diff --git a/test/ConstantinopleContract.sol b/test/contracts/constantinople/ConstantinopleContract.sol similarity index 100% rename from test/ConstantinopleContract.sol rename to test/contracts/constantinople/ConstantinopleContract.sol diff --git a/test/enable_constantinople_hardfork.js b/test/enable_constantinople_hardfork.js index 2671311ce0..15400b8d37 100644 --- a/test/enable_constantinople_hardfork.js +++ b/test/enable_constantinople_hardfork.js @@ -1,87 +1,64 @@ const assert = require("assert"); -const Web3 = require("web3"); -const Ganache = require(process.env.TEST_BUILD - ? "../build/ganache.core." + process.env.TEST_BUILD + ".js" - : "../index.js"); -const fs = require("fs"); -const path = require("path"); -const solc = require("solc"); - -const mnemonic = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"; +const bootstrap = require("./helpers/contract/bootstrap"); describe("Constantinople Hardfork", function() { - let contract; - - before("compile contract", function() { - this.timeout(200000); - let result = solc.compile( - { - sources: { - "ConstantinopleContract.sol": fs.readFileSync(path.join(__dirname, "ConstantinopleContract.sol"), "utf8") - } - }, - 1 - ); - contract = { - bytecode: "0x" + result.contracts["ConstantinopleContract.sol:ConstantinopleContract"].bytecode, - abi: JSON.parse(result.contracts["ConstantinopleContract.sol:ConstantinopleContract"].interface) - }; - }); + const mnemonic = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"; describe("Disallow Constantinople features", function() { - const provider = Ganache.provider({ - mnemonic, - gasLimit: 20000000, - hardfork: "byzantium" - }); - const web3 = new Web3(provider); - let accounts; + let context; - before("get accounts", async function() { - accounts = await web3.eth.getAccounts(); - }); + before("Setting up web3 and contract", async function() { + this.timeout(10000); - it("should fail execution", async function() { - const DummyContract = new web3.eth.Contract(contract.abi); + const contractRef = { + contractFiles: ["ConstantinopleContract"], + contractSubdirectory: "constantinople" + }; - let promiEvent = DummyContract.deploy({ - data: contract.bytecode - }).send({ from: accounts[0], gas: 20000000 }); + const ganacheProviderOptions = { + mnemonic, + gasLimit: 20000000, + hardfork: "byzantium" + }; - let dummyContractInstance = await promiEvent; + context = await bootstrap(contractRef, ganacheProviderOptions); + }); - try { - await dummyContractInstance.methods.test(2).call(); - assert.fail("Call did not fail execution like it was supposed to"); - } catch (err) { - assert.strictEqual(err.message, "VM Exception while processing transaction: invalid opcode"); - } + it("should fail execution", async function() { + const { instance } = context; + + await assert.rejects( + () => instance.methods.test(2).call(), + /VM Exception while processing transaction: invalid opcode/, + "Call did not fail execution like it was supposed to" + ); }); }); describe("Allow Constantinople features", function() { - var provider = Ganache.provider({ - mnemonic, - hardfork: "constantinople", - gasLimit: 20000000 - }); - var web3 = new Web3(provider); - var accounts; + let context; - before("get accounts", async function() { - accounts = await web3.eth.getAccounts(); - }); + before("Setting up web3 and contract", async function() { + this.timeout(10000); - it("should succeed execution", async function() { - const DummyContract = new web3.eth.Contract(contract.abi); + const contractRef = { + contractFiles: ["ConstantinopleContract"], + contractSubdirectory: "constantinople" + }; - let promiEvent = DummyContract.deploy({ - data: contract.bytecode - }).send({ from: accounts[0], gas: 20000000 }); + const ganacheProviderOptions = { + gasLimit: 20000000, + hardfork: "constantinople", + mnemonic + }; - let dummyContractInstance = await promiEvent; + context = await bootstrap(contractRef, ganacheProviderOptions); + }); + + it("should succeed execution", async function() { + const { instance } = context; - let result = await dummyContractInstance.methods.test(2).call(); + const result = await instance.methods.test(2).call(); assert(result, "successful execution"); }); });