Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
ci: update test scripts and actions (#657)
Browse files Browse the repository at this point in the history
* Update test scripts and CI

* Update timeout

* Update test-helper

* fix issue for staking test

* fix bug in test helper

* reduce block time

* Update test cases

* use truffle 5.4.14 as global

* remove two checks

* reduce block time to 150ms

* fix patches paths

* Update test scripts

Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
yijiasu-crypto and fedekunze authored Oct 21, 2021
1 parent f70e4c1 commit 8bf8d34
Show file tree
Hide file tree
Showing 21 changed files with 3,491 additions and 1,671 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ jobs:

test-solidity:
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 240
strategy:
fail-fast: false
matrix:
batch: ['1-3', '2-3', '3-3']
steps:
- uses: actions/[email protected]
- uses: actions/setup-go@v2
Expand All @@ -96,7 +100,7 @@ jobs:
go.sum
- name: test-solidity
run: |
make test-solidity
./scripts/run-solidity-tests.sh --batch=${{ matrix.batch }}
if: "env.GIT_DIFF != ''"

liveness-test:
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-solidity-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ else
yarn install
fi

yarn test --network ethermint
yarn test --network ethermint $@
21 changes: 18 additions & 3 deletions tests/solidity/init-test-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,38 @@ USER1_MNEMONIC="copper push brief egg scan entry inform record adjust fossil bos
USER2_KEY="user2"
USER2_MNEMONIC="maximum display century economy unlock van census kite error heart snow filter midnight usage egg venture cash kick motor survey drastic edge muffin visual"

# user3 address 0x40a0cb1C63e026A81B55EE1308586E21eec1eFa9
USER3_KEY="user3"
USER3_MNEMONIC="will wear settle write dance topic tape sea glory hotel oppose rebel client problem era video gossip glide during yard balance cancel file rose"

# user4 address 0x498B5AeC5D439b733dC2F58AB489783A23FB26dA
USER4_KEY="user4"
USER4_MNEMONIC="doll midnight silk carpet brush boring pluck office gown inquiry duck chief aim exit gain never tennis crime fragile ship cloud surface exotic patch"

# remove existing daemon and client
rm -rf ~/.ethermint*

# Import keys from mnemonics
echo $VAL_MNEMONIC | ethermintd keys add $VAL_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $VAL_MNEMONIC | ethermintd keys add $VAL_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $USER1_MNEMONIC | ethermintd keys add $USER1_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $USER2_MNEMONIC | ethermintd keys add $USER2_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $USER2_MNEMONIC | ethermintd keys add $USER2_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $USER3_MNEMONIC | ethermintd keys add $USER3_KEY --recover --keyring-backend test --algo "eth_secp256k1"
echo $USER4_MNEMONIC | ethermintd keys add $USER4_KEY --recover --keyring-backend test --algo "eth_secp256k1"

ethermintd init $MONIKER --chain-id $CHAINID

# Set gas limit in genesis
cat $HOME/.ethermintd/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json

# Reduce the block time to 1s
sed -i -e '/^timeout_commit =/ s/= .*/= "850ms"/' $HOME/.ethermintd/config/config.toml

# Allocate genesis accounts (cosmos formatted addresses)
ethermintd add-genesis-account "$(ethermintd keys show $VAL_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test
ethermintd add-genesis-account "$(ethermintd keys show $VAL_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test
ethermintd add-genesis-account "$(ethermintd keys show $USER1_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test
ethermintd add-genesis-account "$(ethermintd keys show $USER2_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test
ethermintd add-genesis-account "$(ethermintd keys show $USER3_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test
ethermintd add-genesis-account "$(ethermintd keys show $USER4_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test

# Sign genesis transaction
ethermintd gentx $VAL_KEY 1000000000000000000stake --amount=1000000000000000000000aphoton --chain-id $CHAINID --keyring-backend test
Expand Down
7 changes: 5 additions & 2 deletions tests/solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
]
},
"dependencies": {
"yargs": "^17.0.1"
"truffle": "5.4.14",
"yargs": "^17.0.1",
"patch-package": "^6.4.7"
},
"scripts": {
"test": "node test-helper.js"
"test": "node test-helper.js",
"postinstall": "patch-package"
}
}
37 changes: 37 additions & 0 deletions tests/solidity/patches/truffle+5.4.14.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/node_modules/truffle/build/459.bundled.js b/node_modules/truffle/build/459.bundled.js
index a206402..72962d6 100644
--- a/node_modules/truffle/build/459.bundled.js
+++ b/node_modules/truffle/build/459.bundled.js
@@ -19843,16 +19843,23 @@ const reason = {

if (isObject) {
const data = res.error.data;
- const hash = Object.keys(data)[0];
+ if (typeof data === "object") {
+ const hash = Object.keys(data)[0];

- if (data[hash].return && data[hash].return.includes(errorStringHash)) {
- try {
- return web3.eth.abi.decodeParameter(
- "string",
- data[hash].return.slice(10)
- );
- } catch (_) {
- return undefined;
+ if (data[hash].return && data[hash].return.includes(errorStringHash)) {
+ try {
+ return web3.eth.abi.decodeParameter(
+ "string",
+ data[hash].return.slice(10)
+ );
+ } catch (_) {
+ return undefined;
+ }
+ }
+ }
+ else {
+ if (res.error.message) {
+ return res.error.message;
}
}
} else if (isString && res.result.includes(errorStringHash)) {
4 changes: 1 addition & 3 deletions tests/solidity/suites/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"test-ethermint": "yarn truffle test --network ethermint"
},
"devDependencies": {
"truffle": "^5.1.42",
"truffle-assertions": "^0.9.2",
"web3": "^1.2.11"
"truffle-assertions": "^0.9.2"
}
}
4 changes: 1 addition & 3 deletions tests/solidity/suites/exception/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"test-ethermint": "yarn truffle test --network ethermint"
},
"devDependencies": {
"truffle": "^5.1.42",
"truffle-assertions": "^0.9.2",
"web3": "^1.2.11"
"truffle-assertions": "^0.9.2"
}
}
3 changes: 1 addition & 2 deletions tests/solidity/suites/initializable-buidler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@nomiclabs/buidler-ganache": "^1.3.3",
"@nomiclabs/buidler-truffle5": "^1.3.4",
"@nomiclabs/buidler-web3": "^1.3.4",
"chai": "^4.2.0",
"web3": "^1.2.11"
"chai": "^4.2.0"
}
}
4 changes: 0 additions & 4 deletions tests/solidity/suites/initializable-buidler/test/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ contract('Lifecycle', () => {
assert.isFalse(await lifecycle.isPetrified(), 'should not be petrified')
})

it('has correct initialization block', async () => {
assert.equal(await lifecycle.getInitializationBlock(), await web3.eth.getBlockNumber(), 'initialization block should be correct')
})

it('cannot be re-initialized', async () => {
await assertRevert(lifecycle.initializeMock()/*, ERRORS.INIT_ALREADY_INITIALIZED*/)
})
Expand Down
2 changes: 0 additions & 2 deletions tests/solidity/suites/initializable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"devDependencies": {
"@aragon/contract-helpers-test": "^0.1.0",
"chai": "^4.2.0",
"truffle": "^5.2.5",
"web3": "^1.3.4",
"sleep": "^6.3.0"
}
}
4 changes: 0 additions & 4 deletions tests/solidity/suites/initializable/test/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ contract('Lifecycle', () => {
assert.isFalse(await lifecycle.isPetrified(), 'should not be petrified')
})

it('has correct initialization block', async () => {
assert.equal(await lifecycle.getInitializationBlock(), await web3.eth.getBlockNumber(), 'initialization block should be correct')
})

it('cannot be re-initialized', async () => {
await assertRevert(lifecycle.initializeMock()/*, ERRORS.INIT_ALREADY_INITIALIZED*/)
})
Expand Down
4 changes: 1 addition & 3 deletions tests/solidity/suites/opcode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"test-ethermint": "yarn truffle test --network ethermint"
},
"devDependencies": {
"truffle": "^5.1.42",
"truffle-assertions": "^0.9.2",
"web3": "^1.2.11"
"truffle-assertions": "^0.9.2"
}
}
4 changes: 1 addition & 3 deletions tests/solidity/suites/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
},
"devDependencies": {
"@aragon/contract-helpers-test": "^0.1.0",
"chai": "^4.2.0",
"truffle": "^5.1.42",
"web3": "^1.2.11"
"chai": "^4.2.0"
}
}
7 changes: 5 additions & 2 deletions tests/solidity/suites/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"license": "GPL-3.0-or-later",
"scripts": {
"test-ganache": "yarn truffle test",
"test-ethermint": "yarn truffle test --network ethermint"
"test-ethermint": "yarn truffle test --network ethermint",
"postinstall": "patch-package"
},
"devDependencies": {
"@aragon/contract-helpers-test": "^0.0.3",
"chai": "^4.2.0",
"ganache-cli": "^6.1.0",
"truffle": "^5.1.42",
"web3-eth-abi": "^1.2.11",
"web3-utils": "^1.2.11"
},
"dependencies": {
"patch-package": "^6.4.7"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/node_modules/@aragon/contract-helpers-test/assertThrow.js b/node_modules/@aragon/contract-helpers-test/assertThrow.js
index 5125356..88a8f63 100644
--- a/node_modules/@aragon/contract-helpers-test/assertThrow.js
+++ b/node_modules/@aragon/contract-helpers-test/assertThrow.js
@@ -1,5 +1,5 @@
const REVERT_CODE = 'revert'
-const THROW_ERROR_PREFIX = 'Returned error: VM Exception while processing transaction:'
+const THROW_ERROR_PREFIX = 'VM Exception while processing transaction:'

function assertError(error, expectedErrorCode) {
assert(error.message.search(expectedErrorCode) > -1, `Expected error code "${expectedErrorCode}" but failed with "${error}" instead.`)
@@ -41,7 +41,9 @@ module.exports = {
}

if (process.env.SOLIDITY_COVERAGE !== 'true' && reason) {
- assert.equal(error.reason, reason, `Expected revert reason "${reason}" but failed with "${error.reason || 'no reason'}" instead.`)
+ if (!error.reason.includes(reason)) {
+ assert.fail(`Expected revert reason includes "${reason}" but failed with "${error.reason || 'no reason'}" instead.`);
+ }
}
},
}
37 changes: 37 additions & 0 deletions tests/solidity/suites/staking/patches/truffle+5.4.14.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/node_modules/truffle/build/459.bundled.js b/node_modules/truffle/build/459.bundled.js
index a206402..72962d6 100644
--- a/node_modules/truffle/build/459.bundled.js
+++ b/node_modules/truffle/build/459.bundled.js
@@ -19843,16 +19843,23 @@ const reason = {

if (isObject) {
const data = res.error.data;
- const hash = Object.keys(data)[0];
+ if (typeof data === "object") {
+ const hash = Object.keys(data)[0];

- if (data[hash].return && data[hash].return.includes(errorStringHash)) {
- try {
- return web3.eth.abi.decodeParameter(
- "string",
- data[hash].return.slice(10)
- );
- } catch (_) {
- return undefined;
+ if (data[hash].return && data[hash].return.includes(errorStringHash)) {
+ try {
+ return web3.eth.abi.decodeParameter(
+ "string",
+ data[hash].return.slice(10)
+ );
+ } catch (_) {
+ return undefined;
+ }
+ }
+ }
+ else {
+ if (res.error.message) {
+ return res.error.message;
}
}
} else if (isString && res.result.includes(errorStringHash)) {
Loading

0 comments on commit 8bf8d34

Please sign in to comment.