Skip to content

Commit

Permalink
Merge pull request #3311 from ethereum/test/conf-http
Browse files Browse the repository at this point in the history
Add core-method tests for http confirmations & wallet chain options
  • Loading branch information
nivida authored Jan 15, 2020
2 parents 3f839c9 + 0bf0bc9 commit 513116f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/e2e.geth.automine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo " "
geth-dev-assistant --period 2 --accounts 1 --tag 'stable'

# Test
nyc --no-clean --silent _mocha -- \
GETH_AUTOMINE=true nyc --no-clean --silent _mocha -- \
--reporter spec \
--grep 'E2E' \
--timeout 15000 \
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e.npm.publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
# To model publication correctly, this script needs to run
# without web3's dev deps being installed. It installs
# what it needs here.
npm install -g verdaccio@4.3.4
npm install -g verdaccio@4.4.2
npm install -g [email protected]
npm install -g [email protected]

Expand Down
23 changes: 23 additions & 0 deletions test/e2e.contract.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ describe('contract.deploy [ @E2E ]', function() {
assert(err.receipt.status === false);
}
});

it('fires the confirmation handler', function(){
// Http confirmations poll at 1s interval.
// Automine has a 2s interval.
if (!process.env.GETH_AUTOMINE) return;

return new Promise(async (resolve, reject) => {
var startBlock = await web3.eth.getBlockNumber();

await basic
.deploy()
.send({from: accounts[0]})
.on('confirmation', async (number, receipt) => {
assert(receipt.contractAddress);

if (number === 1) { // Confirmation numbers are zero indexed
var endBlock = await web3.eth.getBlockNumber();
assert(endBlock >= (startBlock + 2));
resolve();
}
})
});
});
});

describe('ws', function() {
Expand Down
52 changes: 52 additions & 0 deletions test/e2e.method.signing.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,58 @@ describe('transaction and message signing [ @E2E ]', function() {
}
});

it('wallet executes method call using chain & hardfork options', async function(){
// Geth --dev errors with 'invalid sender' when using these options.
// Requires a custom common configuration (see next test). Ganache doesn't care
if(!process.env.GANACHE) return;

basic = new web3.eth.Contract(Basic.abi, basicOptions);
basic.defaultChain = 'mainnet';
basic.defaultHardfork = 'istanbul';

instance = await basic
.deploy()
.send({from: wallet[0].address});

const receipt = await instance
.methods
.setValue('1')
.send({from: wallet[0].address});

assert(receipt.status === true);
assert(web3.utils.isHexStrict(receipt.transactionHash));
});

it('wallet executes method call using customCommon option', async function(){
const networkId = await web3.eth.net.getId();
const chainId = await web3.eth.getChainId();

const customCommon = {
baseChain: 'mainnet',
customChain: {
name: 'custom-network',
networkId: networkId,
chainId: chainId,
},
harfork: 'istanbul',
};

basic = new web3.eth.Contract(Basic.abi, basicOptions);
basic.defaultCommon = customCommon;

instance = await basic
.deploy()
.send({from: wallet[0].address});

const receipt = await instance
.methods
.setValue('1')
.send({from: wallet[0].address});

assert(receipt.status === true);
assert(web3.utils.isHexStrict(receipt.transactionHash));
});

it('transactions sent with wallet throws error correctly (with receipt)', async function(){
const data = instance
.methods
Expand Down

0 comments on commit 513116f

Please sign in to comment.