Created
June 28, 2017 15:17
-
-
Save TravisMullen/73315976b9f61d64f131b65e2b649ca1 to your computer and use it in GitHub Desktop.
Advance testrpc block during tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `evm_` ONLY works in the testrpc `development` env | |
// `evm_mine` is not a standard web3/eth call | |
function advanceBlock() { | |
return new Promise(resolve => { | |
web3.currentProvider.sendAsync({ | |
method: "evm_mine", | |
jsonrpc: "2.0", | |
id: new Date().getTime() | |
}, function (error, result) { | |
if (error) { | |
console.log('Could not advance block :: ', error) | |
} else { | |
console.log('Advance to block :: ', web3.eth.blockNumber, result.id); | |
resolve(result); | |
} | |
}); | |
}); | |
} | |
// usage | |
it("should have owner", function(done) { | |
MyContract.deployed().then(function(instance) { | |
return instance.owner.call(); | |
}).then(function(results) { | |
assert.equal(results, accounts[0], "does not match creater etherbase/accounts[0]"); | |
// => block 1 | |
return advanceBlock(); | |
}).then(function(results) { | |
// check id of sendAsync | |
// `results.id` | |
done(); | |
}).catch(done); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment