Skip to content

Commit

Permalink
Merge branch 'main' into feat/xcm-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dastan authored Nov 13, 2023
2 parents 3ae4e34 + 0164a4e commit 65c4a92
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 7 deletions.
1 change: 0 additions & 1 deletion ownership-chain/e2e-tests/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ export const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI =

// Constants
export const MAX_U96 = new BN("79228162514264337593543950336"); // 2^96 - 1
export const BLOCK_TIME = 12000; // 12 seconds
72 changes: 72 additions & 0 deletions ownership-chain/e2e-tests/tests/test_txpool.ts
Original file line number Diff line number Diff line change
@@ -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"
);
});
});
5 changes: 4 additions & 1 deletion ownership-chain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions ownership-chain/node/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +155,7 @@ where
EthFilter::new(
client.clone(),
frontier_backend,
graph,
graph.clone(),
filter_pool,
500_usize, // max stored filters
max_past_logs,
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions ownership-chain/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions ownership-chain/runtime/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::str::FromStr;

use super::*;
use frame_support::assert_ok;
use sp_core::U256;

#[test]
Expand Down Expand Up @@ -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 = <Runtime as frame_system::Config>::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 = <Runtime as pallet_evm::Config>::BlockGasLimit::get();

// 15M gas
assert_eq!(block_gas_limit, U256::from(15_000_000));
}

0 comments on commit 65c4a92

Please sign in to comment.