Skip to content

Commit

Permalink
Support pending param for RPC eth_getBlockTransactionCountByNumber (p…
Browse files Browse the repository at this point in the history
…olkadot-evm#627)

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
  • Loading branch information
koushiro authored Apr 20, 2022
1 parent 1ed577e commit 8bf5e12
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
7 changes: 7 additions & 0 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ where
}

pub fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result<Option<U256>> {
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::<B, C>(
self.client.as_ref(),
self.backend.as_ref(),
Expand Down
20 changes: 13 additions & 7 deletions ts-tests/README.md
Original file line number Diff line number Diff line change
@@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
70 changes: 70 additions & 0 deletions ts-tests/tests/test-pending-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});

0 comments on commit 8bf5e12

Please sign in to comment.