Skip to content

Commit

Permalink
Add deployment test cases for "contract could not be stored"
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Jan 7, 2020
1 parent 7918661 commit 17f72d7
Showing 1 changed file with 62 additions and 9 deletions.
71 changes: 62 additions & 9 deletions test/e2e.contract.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ describe('contract.deploy [ @E2E ]', function() {
var accounts;
var basic;
var reverts;
var noBytecode;
var options;

// Error message variants
var ganacheRevert = "revert";
var gethRevert = "code couldn't be stored";
var revertMessage = "revert";
var couldNotBeStoredMessage = "code couldn't be stored";
var creationWithoutDataMessage = "contract creation without any data provided";

var basicOptions = {
data: Basic.bytecode,
Expand All @@ -27,13 +29,20 @@ describe('contract.deploy [ @E2E ]', function() {
gas: 4000000
}

var noBytecodeOptions = {
data: '0x',
gasPrice: '1',
gas: 4000000
}

describe('http', function() {
before(async function(){
web3 = new Web3('http://localhost:8545');
accounts = await web3.eth.getAccounts();

basic = new web3.eth.Contract(Basic.abi, basicOptions);
reverts = new web3.eth.Contract(Reverts.abi, revertsOptions);
noBytecode = new web3.eth.Contract(Basic.abi, noBytecodeOptions);
})

it('returns an instance', async function(){
Expand All @@ -44,7 +53,9 @@ describe('contract.deploy [ @E2E ]', function() {
assert(web3.utils.isAddress(instance.options.address));
});

it('errors on OOG', async function(){
// Clients reject this kind of OOG is early because
// the gas is obviously way too low.
it('errors on "intrinic gas too low" OOG', async function(){
try {
await basic
.deploy()
Expand All @@ -53,9 +64,49 @@ describe('contract.deploy [ @E2E ]', function() {
assert.fail();
} catch(err){
assert(err.message.includes('gas'))
assert(err.receipt === undefined);
}
});

// Clients reject this kind of OOG when the EVM runs out of gas
// while running the code. A contractAddress is set on the
// receipt, but the status will be false.
it('errors on OOG reached while running EVM', async function(){
const estimate = await basic
.deploy()
.estimateGas()

const gas = estimate - 1000;

try {
await basic
.deploy()
.send({from: accounts[0], gas: gas});

assert.fail();
} catch(err){
assert(err.message.includes(couldNotBeStoredMessage));
assert(err.receipt.status === false);
}
});

// Geth immediately rejects a zero length bytecode without mining,
// Ganache accepts and mines it, returning a receipt with status === true
it('errors deploying a zero length bytecode', async function(){
try {
await noBytecode
.deploy()
.send({from: accounts[0]});

assert.fail();
} catch(err){
assert(
err.message.includes(creationWithoutDataMessage) ||
err.message.includes(couldNotBeStoredMessage)
);
}
})

it('errors on revert', async function(){
try {
await reverts
Expand All @@ -65,9 +116,11 @@ describe('contract.deploy [ @E2E ]', function() {
assert.fail();
} catch(err){
assert(
err.message.includes(gethRevert) ||
err.message.includes(ganacheRevert)
err.message.includes(couldNotBeStoredMessage) ||
err.message.includes(revertMessage)
);

assert(err.receipt.status === false);
}
});
});
Expand Down Expand Up @@ -115,8 +168,8 @@ describe('contract.deploy [ @E2E ]', function() {
assert.fail();
} catch(err){
assert(
err.message.includes(gethRevert) ||
err.message.includes(ganacheRevert)
err.message.includes(couldNotBeStoredMessage) ||
err.message.includes(revertMessage)
);
}
});
Expand Down Expand Up @@ -177,8 +230,8 @@ describe('contract.deploy [ @E2E ]', function() {
.send({from: accounts[0]})
.on('error', err => {
assert(
err.message.includes(gethRevert) ||
err.message.includes(ganacheRevert)
err.message.includes(couldNotBeStoredMessage) ||
err.message.includes(revertMessage)
);
done();
})
Expand Down

0 comments on commit 17f72d7

Please sign in to comment.