Skip to content

Commit 525be88

Browse files
authored
bug with zero blockconfrimations config fix (ChainSafe#594)
- parseChainConfig function fix. When no blockConfirmation opt specified, default value (10) will be used - Add unit test to test behaviour
1 parent 8a4c7d2 commit 525be88

File tree

4 files changed

+111
-25
lines changed

4 files changed

+111
-25
lines changed

.github/workflows/ci.yml

+1-24
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,4 @@ jobs:
8989
version: v1.36
9090
args: --timeout=5m
9191
- name: License Check
92-
run: make license-check
93-
94-
deploy:
95-
name: Docker Deployment
96-
runs-on: ubuntu-latest
97-
needs: [test, e2e, lint]
98-
if: github.ref == 'refs/heads/main' || contains(github.ref, '/tags/v')
99-
steps:
100-
- name: Set up QEMU
101-
uses: docker/setup-qemu-action@v1
102-
- name: Set up Docker Buildx
103-
uses: docker/setup-buildx-action@v1
104-
- name: Login to DockerHub
105-
uses: docker/login-action@v1
106-
with:
107-
username: ${{ secrets.DOCKERHUB_USERNAME }}
108-
password: ${{ secrets.DOCKERHUB_TOKEN }}
109-
- name: Build and push
110-
id: docker_build
111-
uses: docker/build-push-action@v2
112-
with:
113-
push: true
114-
- name: Image digest
115-
run: echo ${{ steps.docker_build.outputs.digest }}
92+
run: make license-check
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2020 ChainSafe Systems
2+
# SPDX-License-Identifier: LGPL-3.0-only
3+
4+
name: Docker build and push
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
tags:
11+
- "v*.*.*"
12+
release:
13+
types:
14+
- created
15+
jobs:
16+
build-and-deploy:
17+
name: Docker Deployment
18+
runs-on: ubuntu-latest
19+
needs: [test, e2e, lint]
20+
if: github.ref == 'refs/heads/main' || contains(github.ref, '/tags/v')
21+
steps:
22+
- name: Prepare
23+
id: prep
24+
run: |
25+
DOCKER_IMAGE=chainsafe/chainbridge
26+
VERSION=edge
27+
if [[ $GITHUB_REF == refs/tags/* ]]; then
28+
VERSION=${GITHUB_REF#refs/tags/v}
29+
fi
30+
if [ "${{ github.event_name }}" = "schedule" ]; then
31+
VERSION=nightly
32+
fi
33+
TAGS="${DOCKER_IMAGE}:${VERSION}"
34+
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
35+
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
36+
fi
37+
echo ::set-output name=tags::${TAGS}
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@v1
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v1
42+
- name: Login to DockerHub
43+
uses: docker/login-action@v1
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
- name: Build and push
48+
id: docker_build
49+
uses: docker/build-push-action@v2
50+
with:
51+
push: ${{ github.event_name != 'pull_request' }}
52+
tags: ${{ steps.prep.outputs.tags }}
53+
- name: Image digest
54+
run: echo ${{ steps.docker_build.outputs.digest }}

chains/ethereum/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func parseChainConfig(chainCfg *core.ChainConfig) (*Config, error) {
154154
} else {
155155
return nil, fmt.Errorf("unable to parse %s", BlockConfirmationsOpt)
156156
}
157+
} else {
158+
config.blockConfirmations = big.NewInt(DefaultBlockConfirmations)
159+
delete(chainCfg.Opts, BlockConfirmationsOpt)
157160
}
158161

159162
if len(chainCfg.Opts) != 0 {

chains/ethereum/config_test.go

+53-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,58 @@ func TestParseChainConfig(t *testing.T) {
6565
}
6666
}
6767

68+
//TestParseChainConfig tests parseChainConfig with all handlerContracts provided
69+
func TestParseChainConfigWithNoBlockConfirmations(t *testing.T) {
70+
71+
input := core.ChainConfig{
72+
Name: "chain",
73+
Id: 1,
74+
Endpoint: "endpoint",
75+
From: "0x0",
76+
KeystorePath: "./keys",
77+
Insecure: false,
78+
Opts: map[string]string{
79+
"bridge": "0x1234",
80+
"erc20Handler": "0x1234",
81+
"erc721Handler": "0x1234",
82+
"genericHandler": "0x1234",
83+
"gasLimit": "10",
84+
"gasMultiplier": "1",
85+
"maxGasPrice": "20",
86+
"http": "true",
87+
"startBlock": "10",
88+
},
89+
}
90+
91+
out, err := parseChainConfig(&input)
92+
93+
if err != nil {
94+
t.Fatal(err)
95+
}
96+
97+
expected := Config{
98+
name: "chain",
99+
id: 1,
100+
endpoint: "endpoint",
101+
from: "0x0",
102+
keystorePath: "./keys",
103+
bridgeContract: common.HexToAddress("0x1234"),
104+
erc20HandlerContract: common.HexToAddress("0x1234"),
105+
erc721HandlerContract: common.HexToAddress("0x1234"),
106+
genericHandlerContract: common.HexToAddress("0x1234"),
107+
gasLimit: big.NewInt(10),
108+
maxGasPrice: big.NewInt(20),
109+
gasMultiplier: big.NewFloat(1),
110+
http: true,
111+
startBlock: big.NewInt(10),
112+
blockConfirmations: big.NewInt(DefaultBlockConfirmations),
113+
}
114+
115+
if !reflect.DeepEqual(&expected, out) {
116+
t.Fatalf("Output not expected.\n\tExpected: %#v\n\tGot: %#v\n", &expected, out)
117+
}
118+
}
119+
68120
//TestChainConfigOneContract Tests chain config providing only one contract
69121
func TestChainConfigOneContract(t *testing.T) {
70122

@@ -105,7 +157,7 @@ func TestChainConfigOneContract(t *testing.T) {
105157
gasMultiplier: big.NewFloat(1),
106158
http: true,
107159
startBlock: big.NewInt(10),
108-
blockConfirmations: big.NewInt(0),
160+
blockConfirmations: big.NewInt(DefaultBlockConfirmations),
109161
}
110162

111163
if !reflect.DeepEqual(&expected, out) {

0 commit comments

Comments
 (0)