From 0a7e344016aa04d958a481cf87e91dc383361df6 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Fri, 15 Mar 2019 18:50:57 -0400 Subject: [PATCH] put it back --- test/block-tags.js | 66 +++++++++++------------ test/helpers/contract/compileAndDeploy.js | 4 +- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/test/block-tags.js b/test/block-tags.js index a9c110b1e3..55b6cfa2ae 100644 --- a/test/block-tags.js +++ b/test/block-tags.js @@ -1,46 +1,21 @@ const assert = require("assert"); -const bootstrap = require("./helpers/contract/bootstrap"); +const initializeTestProvider = require("./helpers/web3/initializeTestProvider"); +const { readFileSync } = require("fs"); +const { compile } = require("solc"); describe("Block Tags", function() { let context; - const contract = {}; const initialState = {}; - before("Setting up web3 and contract", async function() { + before("Setting up web3", async function() { this.timeout(10000); - const contractRef = { - contractFiles: ["Example"], - contractSubdirectory: "examples" + const options = { + mnemonic: "candy maple velvet cake sugar cream honey rich smooth crumble sweet treat", + time: new Date(0) // Testing features that rely on determinate conditions }; - context = await bootstrap(contractRef); - }); - - before("Customize contract data", function() { - const { abi, bytecode } = context; - - // Note: Certain properties of the following contract data are hardcoded to - // maintain repeatable tests. If you significantly change the solidity code, - // make sure to update the resulting contract data with the correct values. - Object.assign(contract, { - abi, - binary: bytecode, - position_of_value: "0x0000000000000000000000000000000000000000000000000000000000000000", - expected_default_value: 5, - call_data: { - gas: "0x2fefd8", - gasPrice: "0x1", // This is important, as passing it has exposed errors in the past. - to: null, // set by test - data: "0x3fa4f245" - }, - transaction_data: { - from: null, // set by test - gas: "0x2fefd8", - to: null, // set by test - data: "0x552410770000000000000000000000000000000000000000000000000000000000000019" // sets value to 25 (base 10) - } - }); + context = await initializeTestProvider(options); }); before("Get initial balance, nonce and block number", async function() { @@ -63,13 +38,15 @@ describe("Block Tags", function() { before("Make a transaction that changes the balance, code and nonce", async function() { const { accounts, web3 } = context; + const source = readFileSync("./test/contracts/examples/Example.sol", { encoding: "utf8" }); + const result = compile(source, 1); const { contractAddress } = await web3.eth.sendTransaction({ from: accounts[0], - data: contract.binary, + data: "0x" + result.contracts[":Example"].bytecode, gas: 3141592 }); - Object.assign(initialState, { contractAddress }); + initialState.contractAddress = contractAddress; }); it("should return the initial nonce at the previous block number", async function() { @@ -108,4 +85,23 @@ describe("Block Tags", function() { assert.notStrictEqual(code, "0x"); assert(code.length > 20); // Just because we don't know the actual code we're supposed to get back }); + + it("should produce correct tx and receipt root when the block contains 1 (or more) tx's", async function() { + const { web3 } = context; + const { blockNumber } = initialState; + + const block = await web3.eth.getBlock(blockNumber + 1, false); + assert.strictEqual(block.transactions.length, 1, "should have one tx in the block."); + assert.notStrictEqual(block.transactionsRoot, block.receiptsRoot, "Trie roots should not be equal."); + assert.strictEqual( + block.transactionsRoot, + "0xce8a25092b27c67e802dff9e3ec66aacf6232da66e2796243aaccdc0deaaa1db", + "Should produce correct transactionsRoot" + ); + assert.strictEqual( + block.receiptsRoot, + "0xa63df9d6e2147dbffa164b173ead7c10d14d95c6e83dbb879ddc45ad7e8dfc89", + "Should produce correct receiptsRoot" + ); + }); }); diff --git a/test/helpers/contract/compileAndDeploy.js b/test/helpers/contract/compileAndDeploy.js index d2baabb493..1e60899fc7 100644 --- a/test/helpers/contract/compileAndDeploy.js +++ b/test/helpers/contract/compileAndDeploy.js @@ -9,7 +9,7 @@ const { readFileSync } = require("fs"); * @param {String} contractPath Path to contracts directory * @returns {Object} context: abi, bytecode, sources */ -async function compile(mainContractName, contractFileNames = [], contractSubdirectory) { +function compile(mainContractName, contractFileNames = [], contractSubdirectory) { const contractPath = join(__dirname, "..", "..", "contracts", `${contractSubdirectory}/`); const selectedContracts = [mainContractName].concat(contractFileNames); @@ -91,7 +91,7 @@ async function compileAndDeploy( options = {}, accounts = [] ) { - const { abi, bytecode, sources } = await compile(mainContractName, contractFileNames, contractPath); + const { abi, bytecode, sources } = compile(mainContractName, contractFileNames, contractPath); const context = await deploy(abi, bytecode, web3, options, accounts); return Object.assign(context, { sources }); }