Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds tests for Balance #94

Closed
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
4 changes: 2 additions & 2 deletions ts-tests/frontier-test-specs/simple-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"evm": {
"accounts": {
"0x57d213d0927ccc7596044c6ba013dd05522aacba": {
"0x6be02d1d3665660d22ff9624b7be0551ee1ac91b": {
"nonce": "0x0",
"balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"balance": "0xffffffffffffffffffffffffffffffff",
"storage": {},
"code": []
}
Expand Down
31 changes: 31 additions & 0 deletions ts-tests/tests/test-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from "chai";
import { step } from "mocha-steps";

import { createAndFinalizeBlock, describeWithFrontier, customRequest } from "./util";

describeWithFrontier("Frontier RPC (Balance)", `simple-specs.json`, (context) => {
const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b";
const GENESIS_ACCOUNT_BALANCE = "340282366920938463463374607431768211455";
const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342";
const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111";

step("genesis balance is setup correctly", async function () {
expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal(GENESIS_ACCOUNT_BALANCE);
});

step("balance to be updated after transfer", async function () {
this.timeout(15000);

const tx = await context.web3.eth.accounts.signTransaction({
from: GENESIS_ACCOUNT,
to: TEST_ACCOUNT,
value: "0x200", // Must me higher than ExistentialDeposit (500)
gasPrice: "0x00",
gas: "0x100000",
}, GENESIS_ACCOUNT_PRIVATE_KEY);
await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]);
await createAndFinalizeBlock(context.web3);
expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal("340282366920938463463374607431768189943");
expect(await context.web3.eth.getBalance(TEST_ACCOUNT)).to.equal("512");
});
});
6 changes: 4 additions & 2 deletions ts-tests/tests/test-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x0000000000000000000000000000001234567890",
number: 1,
parentHash: "0x2cc74f91423ba20e9bb0b2c7d8924eacd14bc98aa1daad078f8844e529221cde",
//parentHash: "0x2cc74f91423ba20e9bb0b2c7d8924eacd14bc98aa1daad078f8844e529221cde",
receiptsRoot: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
sha3Uncles: "0x0000000000000000000000000000000000000000000000000000000000000000",
size: 539,
Expand All @@ -47,6 +47,7 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
"0x0000000000000000",
]);
expect(block.hash).to.be.a("string").lengthOf(66);
expect(block.parentHash).to.be.a("string").lengthOf(66);
expect(block.timestamp).to.be.a("number");
});

Expand All @@ -73,7 +74,7 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x0000000000000000000000000000000000000000",
number: 1,
parentHash: "0x04540257811b46d103d9896e7807040e7de5080e285841c5430d1a81588a0ce4",
//parentHash: "0x04540257811b46d103d9896e7807040e7de5080e285841c5430d1a81588a0ce4",
receiptsRoot: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
sha3Uncles: "0x0000000000000000000000000000000000000000000000000000000000000000",
size: 539,
Expand All @@ -93,6 +94,7 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
"0x0000000000000000",
]);
expect(block.hash).to.be.a("string").lengthOf(66);
expect(block.parentHash).to.be.a("string").lengthOf(66);
expect(block.timestamp).to.be.a("number");
});

Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-contract-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createAndFinalizeBlock, customRequest, describeWithFrontier } from "./u
import { AbiItem } from "web3-utils";

describeWithFrontier("Frontier RPC (Contract Methods)", `simple-specs.json`, (context) => {
const GENESIS_ACCOUNT = "0x57d213d0927ccc7596044c6ba013dd05522aacba";
const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b";
const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342";

// Solidity: contract test { function multiply(uint a) public pure returns(uint d) {return a * 7;}}
Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from "chai";
import { createAndFinalizeBlock, customRequest, describeWithFrontier } from "./util";

describeWithFrontier("Frontier RPC (Contract)", `simple-specs.json`, (context) => {
const GENESIS_ACCOUNT = "0x57d213d0927ccc7596044c6ba013dd05522aacba";
const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b";
const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342";

// Solidity: contract test { function multiply(uint a) public pure returns(uint d) {return a * 7;}}
Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describeWithFrontier, customRequest, createAndFinalizeBlock } from "./u
import { AbiItem } from "web3-utils";

describeWithFrontier("Frontier RPC (Gas)", `simple-specs.json`, (context) => {
const GENESIS_ACCOUNT = "0x57d213d0927ccc7596044c6ba013dd05522aacba";
const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b";
const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342";

// Solidity: contract test { function multiply(uint a) public pure returns(uint d) {return a * 7;}}
Expand Down
4 changes: 2 additions & 2 deletions ts-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function startFrontierNode(specFilename: string): Promise<{ web3: W
binary.on("error", (err) => {
if ((err as any).errno == "ENOENT") {
console.error(
`\x1b[31mMissing Frontier binary (${BINARY_PATH}).\nPlease compile the Frontier project:\ncargo build --bin frontier-test-node\x1b[0m`
`\x1b[31mMissing Frontier binary (${BINARY_PATH}).\nPlease compile the Frontier project:\ncargo build\x1b[0m`
);
} else {
console.error(err);
Expand All @@ -76,7 +76,7 @@ export async function startFrontierNode(specFilename: string): Promise<{ web3: W
const binaryLogs = [];
await new Promise((resolve) => {
const timer = setTimeout(() => {
console.error(`\x1b[31m Failed to start Frontier Test Node.\x1b[0m`);
console.error(`\x1b[31m Failed to start Frontier Template Node.\x1b[0m`);
console.error(`Command: ${cmd} ${args.join(" ")}`);
console.error(`Logs:`);
console.error(binaryLogs.map((chunk) => chunk.toString()).join("\n"));
Expand Down