diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index d10f0d3621..9b578d614c 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -167,6 +167,13 @@ where } pub fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result> { + if let BlockNumber::Pending = number { + // get the pending transactions count + return Ok(Some(U256::from( + self.graph.validated_pool().ready().count(), + ))); + } + let id = match frontier_backend_client::native_block_id::( self.client.as_ref(), self.backend.as_ref(), diff --git a/ts-tests/README.md b/ts-tests/README.md index e0a0100d50..ce3794bcb9 100644 --- a/ts-tests/README.md +++ b/ts-tests/README.md @@ -1,29 +1,35 @@ # Functional testing for Substrate Frontier Node RPC -This folder contains a set of functional tests desgined to perform functional testing on the Frontier Eth RPC. +This folder contains a set of functional tests designed to perform functional testing on the Frontier Eth RPC. It is written in typescript, using Mocha/Chai as Test framework. ## Test flow -Tests are separated depending of their genesis requirements. -Each group will start a [frontier test node](frontier-test-node) with a given [spec](substrate-specs) before executing the tests. +Tests are separated depending on their genesis requirements. +Each group will start a `frontier test node` with a given `spec` before executing the tests. -## Installation +## Build the manual seal node for tests +```bash +cargo build --release --no-default-features --features manual-seal,rpc_binary_search_estimate ``` + +## Installation + +```bash npm install ``` ## Run the tests -``` -npm run test +```bash +npm run build && npm run test ``` You can also add the Frontier Node logs to the output using the `FRONTIER_LOG` env variable. Ex: -``` +```bash FRONTIER_LOG="warn,rpc=trace" npm run test ``` diff --git a/ts-tests/tests/test-balance.ts b/ts-tests/tests/test-balance.ts index 78d0938841..2244ad6a6c 100644 --- a/ts-tests/tests/test-balance.ts +++ b/ts-tests/tests/test-balance.ts @@ -19,7 +19,7 @@ describeWithFrontier("Frontier RPC (Balance)", (context) => { const tx = await context.web3.eth.accounts.signTransaction({ from: GENESIS_ACCOUNT, to: TEST_ACCOUNT, - value: "0x200", // Must me higher than ExistentialDeposit (500) + value: "0x200", // Must be higher than ExistentialDeposit (500) gasPrice: "0x3B9ACA00", gas: "0x100000", }, GENESIS_ACCOUNT_PRIVATE_KEY); diff --git a/ts-tests/tests/test-nonce.ts b/ts-tests/tests/test-nonce.ts index 439cfc9174..187b8b75ea 100644 --- a/ts-tests/tests/test-nonce.ts +++ b/ts-tests/tests/test-nonce.ts @@ -13,7 +13,7 @@ describeWithFrontier("Frontier RPC (Nonce)", (context) => { const tx = await context.web3.eth.accounts.signTransaction({ from: GENESIS_ACCOUNT, to: TEST_ACCOUNT, - value: "0x200", // Must me higher than ExistentialDeposit (500) + value: "0x200", // Must be higher than ExistentialDeposit (500) gasPrice: "0x3B9ACA00", gas: "0x100000", }, GENESIS_ACCOUNT_PRIVATE_KEY); diff --git a/ts-tests/tests/test-pending-pool.ts b/ts-tests/tests/test-pending-pool.ts index bdeecf1d11..333ccc8bb2 100644 --- a/ts-tests/tests/test-pending-pool.ts +++ b/ts-tests/tests/test-pending-pool.ts @@ -49,3 +49,73 @@ describeWithFrontier("Frontier RPC (Pending Pool)", (context) => { }); }); }); + +describeWithFrontier("Frontier RPC (Pending Transaction Count)", (context) => { + const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b"; + const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342"; + const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111"; + + it("should return pending transaction count", async function () { + this.timeout(15000); + + // nonce should be 0 + expect(await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT, 'latest')).to.eq(0); + + 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 (500) + gasPrice: "0x3B9ACA00", + gas: "0x100000", + nonce: nonce, + }, + GENESIS_ACCOUNT_PRIVATE_KEY + ); + nonce = nonce + 1; + return (await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction])).result + }; + + { + const pending_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", ['pending'])).result; + expect(pending_transaction_count).to.eq('0x0'); + } + + // block 1 should have 1 transaction + await sendTransaction(); + { + const pending_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", ['pending'])).result; + expect(pending_transaction_count).to.eq('0x1'); + } + + await createAndFinalizeBlock(context.web3); + + { + const pending_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", ['pending'])).result; + expect(pending_transaction_count).to.eq('0x0'); + const processed_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", [1])).result; + expect(processed_transaction_count).to.eq('0x1'); + } + + // block 2 should have 5 transactions + for (var _ of Array(5)) { + await sendTransaction(); + } + + { + const pending_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", ['pending'])).result; + expect(pending_transaction_count).to.eq('0x5'); + } + + await createAndFinalizeBlock(context.web3); + + { + const pending_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", ['pending'])).result; + expect(pending_transaction_count).to.eq('0x0'); + const processed_transaction_count = (await customRequest(context.web3, "eth_getBlockTransactionCountByNumber", [2])).result; + expect(processed_transaction_count).to.eq('0x5'); + } + }); +});