Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core-method tests for http confirmations & wallet chain options #3311

Merged
merged 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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