Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Put missing test back that was remove in the last PR #383

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 31 additions & 35 deletions test/block-tags.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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"
);
});
});
4 changes: 2 additions & 2 deletions test/helpers/contract/compileAndDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 });
}
Expand Down