Skip to content

Commit

Permalink
Merge pull request #73 from gnosis/fix-other-tests
Browse files Browse the repository at this point in the history
Fix Geth and OpenEthereum test runners
  • Loading branch information
germartinez authored Jun 19, 2020
2 parents 25080a8 + 046409b commit bd3e916
Show file tree
Hide file tree
Showing 8 changed files with 497 additions and 1,868 deletions.
56 changes: 37 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,46 @@ jobs:
include:
- name: Ganache
before_script:
- ganache-cli -d > /dev/null &
- sleep 5
script: yarn test
- CONTAINER_ID=$(docker run -d -p 8545:8545 trufflesuite/ganache-cli)
- yarn wait-port -t 10000 localhost:8545
script:
- yarn test
after_script:
- docker logs $CONTAINER_ID
- docker stop $CONTAINER_ID
- docker rm $CONTAINER_ID

- name: Ganache with --noVMErrorsOnRPCResponse
script: yarn test-rpc
before_script:
- CONTAINER_ID=$(docker run -d -p 8545:8545 trufflesuite/ganache-cli --noVMErrorsOnRPCResponse)
- yarn wait-port -t 10000 localhost:8545
script:
- yarn test
after_script:
- docker logs $CONTAINER_ID
- docker stop $CONTAINER_ID
- docker rm $CONTAINER_ID

# - name: Geth
# script: yarn test-geth
- name: Geth
before_script:
- yarn geth-dev-assistant --accounts 2 --gasLimit 6721975
script:
- yarn test
after_script:
- docker stop geth-client

# - name: OpenEthereum
# before_script:
# - PASSFILE=$(mktemp)
# - echo '' > $PASSFILE
# - chmod 644 $PASSFILE
# - CONTAINER_ID=$(docker run -d -p 8545:8545 -p 8546:8546 -v $PASSFILE:$PASSFILE openethereum/openethereum --config dev --jsonrpc-interface=all --ws-interface=all --unlock 0x00a329c0648769a73afac7f9381e08fb43dbea72 --password $PASSFILE)
# - yarn wait-port -t 10000 localhost:8545
# script:
# - yarn test
# after_script:
# - docker logs $CONTAINER_ID
# - docker stop $CONTAINER_ID
# - docker rm $CONTAINER_ID
- name: OpenEthereum
before_script:
- PASSFILE=$(mktemp)
- echo '' > $PASSFILE
- chmod 644 $PASSFILE
- CONTAINER_ID=$(docker run -d -p 8545:8545 -p 8546:8546 -v $PASSFILE:$PASSFILE openethereum/openethereum --config dev --jsonrpc-interface=all --ws-interface=all --unlock 0x00a329c0648769a73afac7f9381e08fb43dbea72 --password $PASSFILE)
- yarn wait-port -t 10000 localhost:8545
script:
- yarn test
after_script:
- docker logs $CONTAINER_ID
- docker stop $CONTAINER_ID
- docker rm $CONTAINER_ID

after_success: yarn coverage
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"migrate": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && truffle migrate --network local",
"test-ts": "nyc mocha -t 5000 -r ts-node/register ./test/contract-proxy-kit.ts --exit",
"test": "yarn migrate && yarn test-ts",
"test-geth": "ethnode --execute='yarn migrate && yarn test-ts'",
"test-rpc": "run-with-testrpc --noVMErrorsOnRPCResponse 'yarn migrate && yarn test-ts'",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint:check": "eslint . --ext .js,.jsx,.ts,.tsx",
Expand Down Expand Up @@ -55,8 +54,8 @@
"dotenv": "^8.2.0",
"eslint": "^7.2.0",
"ethers-4": "npm:ethers@^4.0.45",
"ethnode": "^0.0.19",
"ganache-cli": "^6.9.1",
"geth-dev-assistant": "^0.1.4",
"nyc": "^15.1.0",
"run-with-testrpc": "^0.3.1",
"should": "^13.2.3",
Expand Down
13 changes: 9 additions & 4 deletions src/eth-lib-adapters/EthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,17 @@ class EthersAdapter extends EthLibAdapter {

async getCallRevertData(tx: EthCallTx, block: string | number): Promise<string> {
try {
// Handle Geth/Ganache --noVMErrorsOnRPCResponse revert data
// Handle old Geth/Ganache --noVMErrorsOnRPCResponse revert data
return await this.ethCall(tx, block);
} catch (e) {
if (typeof e.data === 'string' && e.data.startsWith('Reverted 0x')) {
// handle OpenEthereum revert data format
return e.data.slice(9);
if (typeof e.data === 'string') {
if (e.data.startsWith('Reverted 0x'))
// handle OpenEthereum revert data format
return e.data.slice(9);

if (e.data.startsWith('0x'))
// handle new Geth format
return e.data;
}

// handle Ganache revert data format
Expand Down
13 changes: 9 additions & 4 deletions src/eth-lib-adapters/Web3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Web3Adapter extends EthLibAdapter {

async getCallRevertData(tx: EthCallTx, block: string | number): Promise<string> {
try {
// this block handles Geth/Ganache --noVMErrorsOnRPCResponse
// this block handles old Geth/Ganache --noVMErrorsOnRPCResponse
// use a low level eth_call instead of web3.eth.call so
// full error data from eth node is available if provider is Web3 1.x
return await this.providerSend(
Expand All @@ -156,9 +156,14 @@ class Web3Adapter extends EthLibAdapter {
errData = JSON.parse(e.message.slice(12)).data;
}

if (typeof errData === 'string' && errData.startsWith('Reverted 0x')) {
// handle OpenEthereum revert data format
return errData.slice(9);
if (typeof errData === 'string') {
if (errData.startsWith('Reverted 0x'))
// handle OpenEthereum revert data format
return errData.slice(9);

if (errData.startsWith('0x'))
// handle new Geth format
return errData;
}

// handle Ganache revert data format
Expand Down
23 changes: 12 additions & 11 deletions test/contract-proxy-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const web3Versions = [Web3Maj1Min2, Web3Maj2Alpha];
describe('CPK', () => {
let web3: any;
const defaultAccountBox: Address[] = [];
// let coinbase: Address;
const safeOwnerBox: Address[] = [];
let contracts: TestContractInstances;
const gnosisSafeProviderBox: any[] = [];
Expand All @@ -32,9 +31,8 @@ describe('CPK', () => {
web3 = new Web3Maj1Min2('http://localhost:8545');
const accounts = await web3.eth.getAccounts();

// coinbase = accounts[0];
defaultAccountBox[0] = accounts[1];
safeOwnerBox[0] = accounts[2];
defaultAccountBox[0] = accounts[1] || accounts[0];
safeOwnerBox[0] = accounts[2] || defaultAccountBox[0];
});

before('initialize contracts', async () => {
Expand Down Expand Up @@ -220,15 +218,18 @@ describe('CPK', () => {
await CPK.create({} as any).should.be.rejectedWith('ethLibAdapter property missing from options');
});

describe('start', () => {
web3Versions.forEach((Web3) => {
shouldWorkWithWeb3({ Web3, defaultAccountBox, safeOwnerBox, gnosisSafeProviderBox });
});
shouldWorkWithEthers({
ethers: ethersMaj4,
web3Versions.forEach((Web3) => {
shouldWorkWithWeb3({
Web3,
defaultAccountBox,
safeOwnerBox,
gnosisSafeProviderBox
gnosisSafeProviderBox,
});
});
shouldWorkWithEthers({
ethers: ethersMaj4,
defaultAccountBox,
safeOwnerBox,
gnosisSafeProviderBox,
});
});
4 changes: 2 additions & 2 deletions test/ethers/shouldWorkWithEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function shouldWorkWithEthers({

if (signer.constructor.name === 'JsonRpcSigner') {
// mock WalletConnected Gnosis Safe provider
return signer.sendTransaction({ gasLimit: gas, ...txObj });
return (await signer.sendTransaction({ gasLimit: gas, ...txObj })).hash;
}

// See: https://github.com/ethers-io/ethers.js/issues/299
Expand All @@ -55,7 +55,7 @@ export function shouldWorkWithEthers({
gasLimit: gas,
...txObj,
});
return signer.provider.sendTransaction(signedTx);
return (await signer.provider.sendTransaction(signedTx)).hash;
},
randomHexWord: (): string => ethers.utils.hexlify(ethers.utils.randomBytes(32)),
fromWei: (amount: number): number => (
Expand Down
3 changes: 2 additions & 1 deletion test/transactions/shouldSupportDifferentTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ export function shouldSupportDifferentTransactions({
});

beforeEach('give proxy ERC20 allowance', async () => {
await sendTransaction({
const hash = await sendTransaction({
from: proxyOwner,
to: erc20.address,
value: 0,
gas: '0x5b8d80',
data: erc20.contract.methods.approve(cpk.address, `${1e20}`).encodeABI(),
});
await waitTxReceipt({ hash });
});

it('can execute a single transaction', async () => {
Expand Down
Loading

0 comments on commit bd3e916

Please sign in to comment.