From 0164a4e058aa63f67e108956000362f7f6f9eb9f Mon Sep 17 00:00:00 2001 From: dastan <137785454+dastanfv@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:12:53 +0200 Subject: [PATCH] Apply SBP review comments (#166) * Apply SBP comments * Add tests for constants * Add tx pool test * Remove unused import * Another fix * Rename tests * Order of tests * Shorter test contract bytecode * Review comments --- ownership-chain/e2e-tests/tests/config.ts | 18 ++--- .../e2e-tests/tests/test_txpool.ts | 72 +++++++++++++++++++ ownership-chain/node/Cargo.toml | 5 +- ownership-chain/node/src/rpc/eth.rs | 9 ++- ownership-chain/primitives/src/lib.rs | 4 +- ownership-chain/runtime/src/tests.rs | 18 +++++ 6 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 ownership-chain/e2e-tests/tests/test_txpool.ts diff --git a/ownership-chain/e2e-tests/tests/config.ts b/ownership-chain/e2e-tests/tests/config.ts index 63415ea9f..47490f7db 100644 --- a/ownership-chain/e2e-tests/tests/config.ts +++ b/ownership-chain/e2e-tests/tests/config.ts @@ -1,7 +1,6 @@ -import LaosEvolution from "../build/contracts/LaosEvolution.json"; -import { AbiItem } from "web3-utils"; import BN from "bn.js"; - +import { AbiItem } from "web3-utils"; +import LaosEvolution from "../build/contracts/LaosEvolution.json"; // Node config export const RUNTIME_SPEC_NAME = "frontier-template"; @@ -11,6 +10,8 @@ export const RPC_PORT = 9999; // Chain config export const CHAIN_ID = 667; +export const OWNCHAIN_SUDO = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"; +export const OWNCHAIN_SUDO_PRIVATE_KEY = "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133"; export const GENESIS_ACCOUNT = "0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d"; export const GENESIS_ACCOUNT_PRIVATE_KEY = "0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df"; export const GENESIS_ACCOUNT_BALANCE = "77559934324363988853790420524572160"; @@ -18,11 +19,12 @@ export const GAS_PRICE = "0x3B9ACA00"; export const GAS = "0x10000"; // LAOS Evolution Contract -export const LAOS_EVOLUTION_ABI = LaosEvolution.abi as AbiItem[] +export const LAOS_EVOLUTION_ABI = LaosEvolution.abi as AbiItem[]; export const CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000403"; export const SELECTOR_LOG_NEW_COLLECTION = "0x6eb24fd767a7bcfa417f3fe25a2cb245d2ae52293d3c4a8f8c6450a09795d289"; -export const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI = "0x4b3b5da28a351f8bb73b960d7c80b2cef3e3570cb03448234dee173942c74786"; -export const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI = "0x95c167d04a267f10e6b3f373c7a336dc65cf459caf048854dc32a2d37ab1607c"; - +export const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI = + "0x4b3b5da28a351f8bb73b960d7c80b2cef3e3570cb03448234dee173942c74786"; +export const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI = + "0x95c167d04a267f10e6b3f373c7a336dc65cf459caf048854dc32a2d37ab1607c"; -export const MAX_U96 = new BN('79228162514264337593543950336'); // 2^96 - 1 \ No newline at end of file +export const MAX_U96 = new BN("79228162514264337593543950336"); // 2^96 - 1 diff --git a/ownership-chain/e2e-tests/tests/test_txpool.ts b/ownership-chain/e2e-tests/tests/test_txpool.ts new file mode 100644 index 000000000..548b77a35 --- /dev/null +++ b/ownership-chain/e2e-tests/tests/test_txpool.ts @@ -0,0 +1,72 @@ +import { expect } from "chai"; +import { step } from "mocha-steps"; + +import { OWNCHAIN_SUDO, OWNCHAIN_SUDO_PRIVATE_KEY } from "./config"; +import { customRequest, describeWithExistingNode } from "./util"; + +describeWithExistingNode("Frontier RPC (TxPoolApi)", (context) => { + const TEST_CONTRACT_BYTECODE = "0x608060405234801561"; + + let nonce; + let pendingTx; + let futureTx; + async function sendTransaction(context, nonce) { + const tx = await context.web3.eth.accounts.signTransaction( + { + from: OWNCHAIN_SUDO, + data: TEST_CONTRACT_BYTECODE, + value: "0x00", + gasPrice: "0x3B9ACA00", + gas: "0x100000", + nonce: nonce, + }, + OWNCHAIN_SUDO_PRIVATE_KEY + ); + await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); + return tx; + } + + before(async function () { + nonce = await context.web3.eth.getTransactionCount(OWNCHAIN_SUDO); + }); + + step("txpool_status should return correct result", async function () { + let txpoolStatusBefore = await customRequest(context.web3, "txpool_status", []); + + pendingTx = await sendTransaction(context, nonce); + futureTx = await sendTransaction(context, nonce + 1000); + let txpoolStatusAfter = await customRequest(context.web3, "txpool_status", []); + + expect(parseInt(txpoolStatusAfter.result.pending, 16)).to.be.equal( + parseInt(txpoolStatusBefore.result.pending, 16) + 1 + ); + expect(parseInt(txpoolStatusAfter.result.queued, 16)).to.be.equal( + parseInt(txpoolStatusBefore.result.queued, 16) + 1 + ); + }); + + step("txpool_content should return correct result", async function () { + let txpoolContent = await customRequest(context.web3, "txpool_content", []); + + let genesisAccount = OWNCHAIN_SUDO.toLowerCase(); + let futureNonce = `0x${(nonce + 1000).toString(16)}`; + + expect(txpoolContent.result.queued[genesisAccount][futureNonce].nonce).to.be.equal(futureNonce); + expect(txpoolContent.result.queued[genesisAccount][futureNonce].hash).to.be.equal(futureTx.transactionHash); + }); + + step("txpool_inspect should return correct result", async function () { + let txpoolInspect = await customRequest(context.web3, "txpool_inspect", []); + let genesisAccount = OWNCHAIN_SUDO.toLowerCase(); + + let currentNonce = `0x${nonce.toString(16)}`; + let futureNonce = `0x${(nonce + 1000).toString(16)}`; + + expect(txpoolInspect.result.pending[genesisAccount][currentNonce]).to.be.equal( + "0x0000000000000000000000000000000000000000: 0 wei + 1048576 gas x 1000000000 wei" + ); + expect(txpoolInspect.result.queued[genesisAccount][futureNonce]).to.be.equal( + "0x0000000000000000000000000000000000000000: 0 wei + 1048576 gas x 1000000000 wei" + ); + }); +}); diff --git a/ownership-chain/node/Cargo.toml b/ownership-chain/node/Cargo.toml index 5f5607ec6..383a421c7 100644 --- a/ownership-chain/node/Cargo.toml +++ b/ownership-chain/node/Cargo.toml @@ -86,7 +86,10 @@ fp-account = { workspace = true } substrate-build-script-utils = { workspace = true } [features] -default = [] +default = [ + "txpool" +] +txpool = ["fc-rpc/txpool"] runtime-benchmarks = [ "laos-ownership-runtime/runtime-benchmarks", "polkadot-cli/runtime-benchmarks", diff --git a/ownership-chain/node/src/rpc/eth.rs b/ownership-chain/node/src/rpc/eth.rs index ddfea6066..1da556099 100644 --- a/ownership-chain/node/src/rpc/eth.rs +++ b/ownership-chain/node/src/rpc/eth.rs @@ -17,7 +17,7 @@ use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sp_core::H256; use sp_runtime::traits::Block as BlockT; // Frontier -pub use fc_rpc::{EthBlockDataCacheTask, OverrideHandle, StorageOverride}; +pub use fc_rpc::{EthBlockDataCacheTask, OverrideHandle, StorageOverride, TxPoolApiServer}; pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; use fc_rpc_core::{EthApiServer, EthFilterApiServer, NetApiServer, Web3ApiServer}; pub use fc_storage::overrides_handle; @@ -155,7 +155,7 @@ where EthFilter::new( client.clone(), frontier_backend, - graph, + graph.clone(), filter_pool, 500_usize, // max stored filters max_past_logs, @@ -175,7 +175,10 @@ where .into_rpc(), )?; - io.merge(Web3::new(client).into_rpc())?; + io.merge(Web3::new(client.clone()).into_rpc())?; + + #[cfg(feature = "txpool")] + io.merge(fc_rpc::TxPool::new(client, graph).into_rpc())?; Ok(io) } diff --git a/ownership-chain/primitives/src/lib.rs b/ownership-chain/primitives/src/lib.rs index aece2324c..51a696113 100644 --- a/ownership-chain/primitives/src/lib.rs +++ b/ownership-chain/primitives/src/lib.rs @@ -13,11 +13,11 @@ use sp_runtime::{ /// Maximal weight of single OwnershipParachain block. /// -/// This represents two seconds of compute assuming a target block time of six seconds. +/// This represents 0.5 seconds of compute assuming a target block time of 12 seconds. /// /// Max PoV size is set to `5Mb` as all Cumulus-based parachains do. pub const MAXIMUM_BLOCK_WEIGHT: Weight = - Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), 5 * 1024 * 1024); + Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), 5 * 1024 * 1024); /// Represents the portion of a block that will be used by Normal extrinsics. pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); diff --git a/ownership-chain/runtime/src/tests.rs b/ownership-chain/runtime/src/tests.rs index 48a146d9d..8e0f0cb54 100644 --- a/ownership-chain/runtime/src/tests.rs +++ b/ownership-chain/runtime/src/tests.rs @@ -1,6 +1,7 @@ use core::str::FromStr; use super::*; +use frame_support::assert_ok; use sp_core::U256; #[test] @@ -61,3 +62,20 @@ fn asset_id_to_address_two_assets_same_owner() { AccountId::from_str("c0f0f4ab324c46e55d02d0033343b4be8a55532d").unwrap() ); } + +#[test] +fn test_block_and_gas_limit_constants() { + use crate::Runtime; + + let system_block_weights = ::BlockWeights::get(); + + assert_ok!(system_block_weights.clone().validate()); + // 0.5s of block time + assert_eq!(system_block_weights.max_block.ref_time(), 500_000_000_000); + + // EVM constants + let block_gas_limit = ::BlockGasLimit::get(); + + // 15M gas + assert_eq!(block_gas_limit, U256::from(15_000_000)); +}