Skip to content

Commit

Permalink
bug with zero blockconfrimations config fix (ChainSafe#594)
Browse files Browse the repository at this point in the history
- parseChainConfig function fix. When no blockConfirmation opt specified, default value (10) will be used
- Add unit test to test behaviour
  • Loading branch information
P1sar authored Feb 17, 2021
1 parent 8a4c7d2 commit 525be88
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 25 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,4 @@ jobs:
version: v1.36
args: --timeout=5m
- name: License Check
run: make license-check

deploy:
name: Docker Deployment
runs-on: ubuntu-latest
needs: [test, e2e, lint]
if: github.ref == 'refs/heads/main' || contains(github.ref, '/tags/v')
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
run: make license-check
54 changes: 54 additions & 0 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2020 ChainSafe Systems
# SPDX-License-Identifier: LGPL-3.0-only

name: Docker build and push

on:
push:
branches:
- main
tags:
- "v*.*.*"
release:
types:
- created
jobs:
build-and-deploy:
name: Docker Deployment
runs-on: ubuntu-latest
needs: [test, e2e, lint]
if: github.ref == 'refs/heads/main' || contains(github.ref, '/tags/v')
steps:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=chainsafe/chainbridge
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
3 changes: 3 additions & 0 deletions chains/ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func parseChainConfig(chainCfg *core.ChainConfig) (*Config, error) {
} else {
return nil, fmt.Errorf("unable to parse %s", BlockConfirmationsOpt)
}
} else {
config.blockConfirmations = big.NewInt(DefaultBlockConfirmations)
delete(chainCfg.Opts, BlockConfirmationsOpt)
}

if len(chainCfg.Opts) != 0 {
Expand Down
54 changes: 53 additions & 1 deletion chains/ethereum/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,58 @@ func TestParseChainConfig(t *testing.T) {
}
}

//TestParseChainConfig tests parseChainConfig with all handlerContracts provided
func TestParseChainConfigWithNoBlockConfirmations(t *testing.T) {

input := core.ChainConfig{
Name: "chain",
Id: 1,
Endpoint: "endpoint",
From: "0x0",
KeystorePath: "./keys",
Insecure: false,
Opts: map[string]string{
"bridge": "0x1234",
"erc20Handler": "0x1234",
"erc721Handler": "0x1234",
"genericHandler": "0x1234",
"gasLimit": "10",
"gasMultiplier": "1",
"maxGasPrice": "20",
"http": "true",
"startBlock": "10",
},
}

out, err := parseChainConfig(&input)

if err != nil {
t.Fatal(err)
}

expected := Config{
name: "chain",
id: 1,
endpoint: "endpoint",
from: "0x0",
keystorePath: "./keys",
bridgeContract: common.HexToAddress("0x1234"),
erc20HandlerContract: common.HexToAddress("0x1234"),
erc721HandlerContract: common.HexToAddress("0x1234"),
genericHandlerContract: common.HexToAddress("0x1234"),
gasLimit: big.NewInt(10),
maxGasPrice: big.NewInt(20),
gasMultiplier: big.NewFloat(1),
http: true,
startBlock: big.NewInt(10),
blockConfirmations: big.NewInt(DefaultBlockConfirmations),
}

if !reflect.DeepEqual(&expected, out) {
t.Fatalf("Output not expected.\n\tExpected: %#v\n\tGot: %#v\n", &expected, out)
}
}

//TestChainConfigOneContract Tests chain config providing only one contract
func TestChainConfigOneContract(t *testing.T) {

Expand Down Expand Up @@ -105,7 +157,7 @@ func TestChainConfigOneContract(t *testing.T) {
gasMultiplier: big.NewFloat(1),
http: true,
startBlock: big.NewInt(10),
blockConfirmations: big.NewInt(0),
blockConfirmations: big.NewInt(DefaultBlockConfirmations),
}

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

0 comments on commit 525be88

Please sign in to comment.