Skip to content

Commit

Permalink
Add EVM tests (#234)
Browse files Browse the repository at this point in the history
* Support Ethereum for dev node

* Add first test

* Add rpc constants test

* Add balance test

* Add contract test

* Finish balance and contract basic tests

* Add bloom filter test

* Test `eth_getCode`

* Test nonce update

* Test opcodes

* Add event test

* Finally, basic tests are covered.
  • Loading branch information
boundless-forest committed Feb 2, 2023
1 parent 3399b66 commit 1537527
Show file tree
Hide file tree
Showing 19 changed files with 10,008 additions and 6 deletions.
23 changes: 17 additions & 6 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ where
let client = client.clone();
let pool = transaction_pool.clone();
let network = network.clone();
let filter_pool = filter_pool;
let frontier_backend = frontier_backend;
let overrides = overrides;
let fee_history_cache = fee_history_cache;
let filter_pool = filter_pool.clone();
let frontier_backend = frontier_backend.clone();
let overrides = overrides.clone();
let fee_history_cache = fee_history_cache.clone();
let max_past_logs = eth_rpc_config.max_past_logs;
let collator = config.role.is_authority();

Expand All @@ -838,18 +838,29 @@ where

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_builder: Box::new(rpc_extensions_builder),
client,
client: client.clone(),
transaction_pool,
task_manager: &mut task_manager,
config,
keystore: keystore_container.sync_keystore(),
backend,
backend: backend.clone(),
network,
system_rpc_tx,
tx_handler_controller,
telemetry: None,
})?;

frontier_service::spawn_frontier_tasks(
&task_manager,
client,
backend,
frontier_backend,
filter_pool,
overrides,
fee_history_cache,
fee_history_cache_limit,
);

start_network.start_network();

Ok(task_manager)
Expand Down
38 changes: 38 additions & 0 deletions tests/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Web3 from "web3";
import { JsonRpcResponse } from "web3-core-helpers";

export const CHAIN_ID = 43;
export const HOST_HTTP_URL = "http://127.0.0.1:9933";
export const HOST_WS_URL = "ws://127.0.0.1:9944";
// TODO: https://github.com/darwinia-network/darwinia-2.0/issues/248
export const BLOCK_GAS_LIMIT = 9375000;
export const DEFAULT_GAS = 4000000;
// EXTRINSIC_GAS_LIMIT = [BLOCK_GAS_LIMIT - BLOCK_GAS_LIMIT * (NORMAL_DISPATCH_RATIO - AVERAGE_ON_INITIALIZE_RATIO) - EXTRINSIC_BASE_Weight] / WEIGHT_PER_GAS = (1_000_000_000_000 * 2 * (0.75-0.025) - 125_000_000) / 40_000
export const EXTRINSIC_GAS_LIMIT = 9059375;

// Accounts builtin
export const FAITH = "0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d";
export const FAITH_P = "0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df";

export async function customRequest(web3: Web3, method: string, params: any[]) {
return new Promise<JsonRpcResponse>((resolve, reject) => {
(web3.currentProvider as any).send(
{
jsonrpc: "2.0",
id: 1,
method,
params,
},
(error: Error | null, result?: JsonRpcResponse) => {
if (error) {
reject(
`Failed to send custom request (${method} (${params.join(",")})): ${
error.message || error.toString()
}`
);
}
resolve(result);
}
);
});
}
367 changes: 367 additions & 0 deletions tests/ethereum/contracts/contracts_info.ts

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions tests/ethereum/contracts/event.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.6.0;

contract JSON_Test {
event Log0(uint256 value);
event Log0Anonym(uint256 value) anonymous;

event Log1(bool indexed aBool, uint256 value);
event Log1Anonym(bool indexed aBool, uint256 value) anonymous;

event Log2(bool indexed aBool, address indexed aAddress, uint256 value);
event Log2Anonym(
bool indexed aBool,
address indexed aAddress,
uint256 value
) anonymous;

event Log3(
bool indexed aBool,
address indexed aAddress,
bytes32 indexed aBytes32,
uint256 value
);
event Log3Anonym(
bool indexed aBool,
address indexed aAddress,
bytes32 indexed aBytes32,
uint256 value
) anonymous;

constructor() public {}

function fireEventLog0() public {
emit Log0(42);
}

function fireEventLog0Anonym() public {
emit Log0Anonym(42);
}

function fireEventLog1() public {
emit Log1(true, 42);
}

function fireEventLog1Anonym() public {
emit Log1Anonym(true, 42);
}

function fireEventLog2() public {
emit Log2(true, msg.sender, 42);
}

function fireEventLog2Anonym() public {
emit Log2Anonym(true, msg.sender, 42);
}

function fireEventLog3() public {
emit Log3(
true,
msg.sender,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff,
42
);
}

function fireEventLog3Anonym() public {
emit Log3Anonym(
true,
msg.sender,
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff,
42
);
}
}
19 changes: 19 additions & 0 deletions tests/ethereum/contracts/incrementer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.6.0;

contract Incrementer {
uint256 public number;

constructor(uint256 _initialNumber) public {
number = _initialNumber;
}

function increment(uint256 _value) public {
number = number + _value;
}

function reset() public {
number = 0;
}
}
Loading

0 comments on commit 1537527

Please sign in to comment.