Skip to content

Instantly share code, notes, and snippets.

@nicovalencia
Last active June 5, 2018 16:23
Show Gist options
  • Save nicovalencia/51f00ef0c051af61c5f73fe5bcd55a84 to your computer and use it in GitHub Desktop.
Save nicovalencia/51f00ef0c051af61c5f73fe5bcd55a84 to your computer and use it in GitHub Desktop.
it('should require Auction to be ended', async () => {
let playerId = getNextCommonPlayerId();
await instance.createCommonAuction.sendTransaction(playerId, fakeTokenURI);
let auctionsCount = (await instance.totalAuctionsCount()).toNumber();
let lastAuctionIndex = auctionsCount - 1;
// Start auction:
await instance.incrementBid.sendTransaction(lastAuctionIndex, { value: web3.toWei(0.01, 'ether'), from: accounts[1] });
try {
// Finalize not finished auction -- should fail:
await instance.finalizeAuction.sendTransaction(lastAuctionIndex);
} catch (e) {
var firstError = e;
}
assert.equal(firstError.message, 'VM Exception while processing transaction: revert');
// Fast forward to one block before end of auction:
for (let i = 0; i < 255; i++) {
await testHelperInstance.advanceBlock.sendTransaction();
}
try {
// Finalize (almost) not finished auction -- should fail:
await instance.finalizeAuction.call(lastAuctionIndex); // at 256 blocks after
} catch (e) {
var secondError = e;
}
assert.equal(secondError.message, 'VM Exception while processing transaction: revert');
// Fast forward to one block after end of auction:
await testHelperInstance.advanceBlock.sendTransaction();
// Finalize finished auction -- should work:
await instance.finalizeAuction.sendTransaction(lastAuctionIndex); // at 257 (AUCTION_BLOCK_LENGTH) blocks after
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment