Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Aug 16, 2023
1 parent bf8bee7 commit 331dc12
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ts-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"fmt": "prettier ./tests --write",
"build": "truffle compile",
"test": "mocha -r ts-node/register 'tests/**/*.ts'",
"s": "mocha -r ts-node/register 'tests/**/test-block.ts'",
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'"
},
"author": "",
Expand Down
62 changes: 61 additions & 1 deletion ts-tests/tests/test-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describeWithFrontier("Frontier RPC (Pending Block)", (context) => {
nonce = nonce + 100;
await sendTransaction();

// do not seal, get pendign block
// do not seal, get pending block
let pending_transactions = [];
{
const pending = (await customRequest(context.web3, "eth_getBlockByNumber", ["pending", false])).result;
Expand All @@ -195,3 +195,63 @@ describeWithFrontier("Frontier RPC (Pending Block)", (context) => {
expect(pending_transactions).to.be.deep.eq(latest_block.transactions);
});
});

describeWithFrontier("Frontier RPC (BlockReceipts)", (context) => {
const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111";
const N = 5;

it("should return empty if block without transaction", async function () {
await createAndFinalizeBlock(context.web3);
expect(await context.web3.eth.getBlockNumber()).to.equal(1);

let result = await customRequest(context.web3, "eth_getBlockReceipts", [
await context.web3.eth.getBlockNumber(),
]);
expect(result.result.length).to.be.eq(0);
});

it("should return multiple receipts", async function () {
var nonce = 0;
let sendTransaction = async () => {
const tx = await context.web3.eth.accounts.signTransaction(
{
from: GENESIS_ACCOUNT,
to: TEST_ACCOUNT,
value: "0x200", // Must be higher than ExistentialDeposit
gasPrice: "0x3B9ACA00",
gas: "0x100000",
nonce: nonce,
},
GENESIS_ACCOUNT_PRIVATE_KEY
);
nonce = nonce + 1;
return (await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction])).result;
};

// block 1 send 5 transactions
for (var _ of Array(N)) {
await sendTransaction();
}
await createAndFinalizeBlock(context.web3);
expect(await context.web3.eth.getBlockNumber()).to.equal(2);

let result = await customRequest(context.web3, "eth_getBlockReceipts", [2]);
expect(result.result.length).to.be.eq(N);
});

it("should support block number, tag and hash", async function () {
expect(await context.web3.eth.getBlockNumber()).to.equal(2);

// block number
expect((await customRequest(context.web3, "eth_getBlockReceipts", [2])).result.length).to.be.eq(N);
// block hash
let block = await context.web3.eth.getBlock(2);
let result = await customRequest(context.web3, "eth_getBlockReceipts", [block.hash, true]);
console.log("result", result);
// expect((await customRequest(context.web3, "eth_getBlockReceipts", [block.hash])).result.length).to.be.eq(N);
// block tags
expect((await customRequest(context.web3, "eth_getBlockReceipts", ["earliest"])).result.length).to.be.eq(0);
expect((await customRequest(context.web3, "eth_getBlockReceipts", ["pending"])).result.length).to.be.eq(0);
expect((await customRequest(context.web3, "eth_getBlockReceipts", ["finalized"])).result.length).to.be.eq(N);
});
});
2 changes: 1 addition & 1 deletion ts-tests/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = {
compilers: {
solc: {
version: "0.8.2", // Fetch exact version from solc-bin (default: truffle's version)
docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
docker: false, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
Expand Down

0 comments on commit 331dc12

Please sign in to comment.