Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ jobs:
run: make check-benchmarks
- name: Check try-runtime
run: make check-try-runtime
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Run ts tests
run: |
npm install -g yarn
make test-ts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
*.state

.vscode/launch.json

ts-tests/cache/
ts-tests/node_modules/
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ test: githooks
.PHONY: test-eth
test-eth: githooks
SKIP_WASM_BUILD= cargo test -p runtime-common --features with-ethereum-compatibility schedule_call_precompile_should_work
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features with-mandala-runtime --features with-ethereum-compatibility test_evm_module
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features with-mandala-runtime --features with-ethereum-compatibility should_not_kill_contract_on_transfer_all
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features with-mandala-runtime --features with-ethereum-compatibility schedule_call_precompile_should_handle_invalid_input

Expand All @@ -75,6 +74,11 @@ test-runtimes:
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features=with-mandala-runtime
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features=with-karura-runtime

.PHONY: test-ts
test-ts:
cargo build --features with-mandala-runtime
cd ts-tests && yarn && yarn run build && yarn run test

.PHONY: test-benchmarking
test-benchmarking:
cargo test --features runtime-benchmarks --features with-all-runtime --features --all benchmarking
Expand Down
10 changes: 2 additions & 8 deletions modules/evm-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Default for ExtBuilder {
}

pub fn erc20_address() -> EvmAddress {
EvmAddress::from_str("0000000000000000000000000000000002000000").unwrap()
EvmAddress::from_str("5dddfce53ee040d9eb21afbc0ae1bb4dbb0ba643").unwrap()
}

pub fn alice() -> AccountId {
Expand All @@ -186,13 +186,7 @@ pub fn bob_evm_addr() -> EvmAddress {

pub fn deploy_contracts() {
let code = from_hex(include!("./erc20_demo_contract")).unwrap();
assert_ok!(EVM::create_network_contract(
Origin::signed(NetworkContractAccount::get()),
code,
0,
2_100_000,
10000
));
assert_ok!(EVM::create(Origin::signed(alice()), code, 0, 2_100_000, 10000));

let event = Event::EVM(module_evm::Event::Created(erc20_address()));
assert_eq!(System::events().iter().last().unwrap().event, event);
Expand Down
2 changes: 0 additions & 2 deletions modules/evm/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ where
};

let calculate_gas_used = |request| -> Result<(U256, i32)> {
let hash = self.client.info().best_hash;

let CallRequest {
from,
to,
Expand Down
5 changes: 3 additions & 2 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub mod module {
type Runner: Runner<Self>;

/// Find author for the current block.
type FindAuthor: FindAuthor<H160>;
type FindAuthor: FindAuthor<Self::AccountId>;

/// Weight information for the extrinsics in this module.
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -1072,7 +1072,8 @@ impl<T: Config> Pallet<T> {
let digest = <frame_system::Pallet<T>>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());

T::FindAuthor::find_author(pre_runtime_digests).unwrap_or_default()
let author = T::FindAuthor::find_author(pre_runtime_digests).unwrap_or_default();
T::AddressMapping::get_default_evm_address(&author)
}

/// Get code hash at given address.
Expand Down
10 changes: 5 additions & 5 deletions modules/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ impl Convert<u64, u64> for GasToWeight {
}
}

pub struct FindAuthorTruncated;
impl FindAuthor<H160> for FindAuthorTruncated {
fn find_author<'a, I>(_digests: I) -> Option<H160>
pub struct AuthorGiven;
impl FindAuthor<AccountId32> for AuthorGiven {
fn find_author<'a, I>(_digests: I) -> Option<AccountId32>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
Some(H160::from_str("1234500000000000000000000000000000000000").unwrap())
Some(AccountId32::from_str("1234500000000000000000000000000000000000").unwrap())
}
}

Expand Down Expand Up @@ -178,7 +178,7 @@ impl Config for Runtime {
type FreeDeploymentOrigin = EnsureSignedBy<CouncilAccount, AccountId32>;

type Runner = crate::runner::stack::Runner<Self>;
type FindAuthor = FindAuthorTruncated;
type FindAuthor = AuthorGiven;
type WeightInfo = ();
}

Expand Down
29 changes: 28 additions & 1 deletion modules/evm/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use crate::runner::state::PrecompileOutput;
use evm::{Context, ExitError, ExitSucceed};
use frame_support::log;
use impl_trait_for_tuples::impl_for_tuples;
use primitive_types::H160;
use ripemd160::Digest;
Expand Down Expand Up @@ -109,7 +110,7 @@ where
context: &Context,
) -> Option<core::result::Result<PrecompileOutput, ExitError>> {
// https://github.com/ethereum/go-ethereum/blob/9357280fce5c5d57111d690a336cca5f89e34da6/core/vm/contracts.go#L83
if address == H160::from_low_u64_be(1) {
let result = if address == H160::from_low_u64_be(1) {
Some(ECRecover::execute(input, target_gas, context))
} else if address == H160::from_low_u64_be(2) {
Some(Sha256::execute(input, target_gas, context))
Expand All @@ -127,7 +128,12 @@ where
Some(Sha3FIPS512::execute(input, target_gas, context))
} else {
None
};

if result.is_some() {
log::debug!(target: "evm", "Precompile end, address: {:?}, input: {:?}, target_gas: {:?}, context: {:?}, result: {:?}", address, input, target_gas, context, result);
}
result
}
}

Expand Down Expand Up @@ -392,4 +398,25 @@ mod tests {
}
}
}

#[test]
fn ecrecover() -> std::result::Result<(), ExitError> {
let input = sp_core::bytes::from_hex("0xe63325d74baa84af003dfb6a974f41672be881b56aa2c12c093f8259321bd460000000000000000000000000000000000000000000000000000000000000001c6273e55c6b942c7a701ae05195fa24395cd1db99e81c705b8c2eb4d7156ff85a3ecf6b591a30105fef03717fa608c887bd02ba548876e93ce818f90dc46ac374").unwrap();
let expected = b"\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x6b\xe0\x2d\x1d\x36\x65\x66\x0d\x22\xff\x96\x24\xb7\xbe\x05\x51\xee\x1a\xc9\x1b\
";

let cost: u64 = 1;

match <ECRecover as LinearCostPrecompile>::execute(&input, cost) {
Ok((_, out)) => {
assert_eq!(out, expected);
Ok(())
}
Err(e) => {
panic!("Test not expected to fail: {:?}", e);
}
}
}
}
2 changes: 1 addition & 1 deletion runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ impl module_evm::Config for Runtime {
type TreasuryAccount = TreasuryAccount;
type FreeDeploymentOrigin = EnsureRootOrHalfGeneralCouncil;
type Runner = module_evm::runner::stack::Runner<Self>;
type FindAuthor = ();
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type WeightInfo = weights::module_evm::WeightInfo<Runtime>;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static_assertions = "1.1.0"
num_enum = { version = "0.5.1", default-features = false }
serde = { version = "1.0.124", optional = true, default-features = false }
codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["max-encoded-len"] }
ethabi = { git = "https://github.com/rust-ethereum/ethabi", rev = "8bd90d13956edf18bb47c6e39dcf7ab99bf264c7", default-features = false }
ethabi = { version = "15.0.0", default-features = false }

frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
Expand Down
51 changes: 0 additions & 51 deletions runtime/integration-tests/src/evm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pub fn deploy_erc20_contracts() {
assert_ok!(EVM::deploy_free(Origin::root(), erc20_address_1()));
}

#[cfg(not(feature = "with-ethereum-compatibility"))]
fn deploy_contract(account: AccountId) -> Result<H160, DispatchError> {
// pragma solidity ^0.5.0;
//
Expand Down Expand Up @@ -276,7 +275,6 @@ fn dex_module_works_with_evm_contract() {
});
}

#[cfg(not(feature = "with-ethereum-compatibility"))]
#[test]
fn test_evm_module() {
ExtBuilder::default()
Expand Down Expand Up @@ -325,55 +323,6 @@ fn test_evm_module() {
});
}

#[cfg(feature = "with-ethereum-compatibility")]
#[test]
fn test_evm_module() {
ExtBuilder::default()
.balances(vec![
(alice(), NATIVE_CURRENCY, 1_000 * dollar(NATIVE_CURRENCY)),
(bob(), NATIVE_CURRENCY, 1_000 * dollar(NATIVE_CURRENCY)),
])
.build()
.execute_with(|| {
assert_eq!(Balances::free_balance(alice()), 1_000 * dollar(NATIVE_CURRENCY));
assert_eq!(Balances::free_balance(bob()), 1_000 * dollar(NATIVE_CURRENCY));

use std::fs::{self, File};
use std::io::Read;

let paths = fs::read_dir("../../runtime/mandala/tests/solidity_test").unwrap();
let file_names = paths
.filter_map(|entry| entry.ok().and_then(|e| e.path().to_str().map(|s| String::from(s))))
.collect::<Vec<String>>();

for file in file_names {
let mut f = File::open(&file).expect("File not found");
let mut contents = String::new();
f.read_to_string(&mut contents)
.expect("Something went wrong reading the file.");
let json: serde_json::Value = serde_json::from_str(&contents).unwrap();

let bytecode_str = serde_json::to_string(&json["bytecode"]).unwrap();
let bytecode_str = bytecode_str.replace("\"", "");

let bytecode = hex::decode(bytecode_str).unwrap();
assert_ok!(EVM::create(Origin::signed(alice()), bytecode, 0, u64::MAX, u32::MAX));

match System::events().iter().last().unwrap().event {
Event::EVM(module_evm::Event::Created(_)) => {}
_ => {
println!(
"contract {:?} create failed, event: {:?}",
file,
System::events().iter().last().unwrap().event
);
assert!(false);
}
};
}
});
}

#[test]
fn test_multicurrency_precompile_module() {
ExtBuilder::default()
Expand Down
3 changes: 3 additions & 0 deletions runtime/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ mod homa_lite_tests;
#[cfg(any(feature = "with-mandala-runtime", feature = "with-karura-runtime"))]
mod evm_tests;

#[cfg(any(feature = "with-mandala-runtime", feature = "with-karura-runtime"))]
mod weights_test;

#[cfg(feature = "with-karura-runtime")]
mod kusama_cross_chain_transfer;
#[cfg(feature = "with-karura-runtime")]
Expand Down
2 changes: 1 addition & 1 deletion runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ impl module_evm::Config for Runtime {
type TreasuryAccount = KaruraTreasuryAccount;
type FreeDeploymentOrigin = EnsureRootOrHalfGeneralCouncil;
type Runner = module_evm::runner::stack::Runner<Self>;
type FindAuthor = ();
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type WeightInfo = weights::module_evm::WeightInfo<Runtime>;
}

Expand Down
19 changes: 14 additions & 5 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn get_all_module_accounts() -> Vec<AccountId> {
}

parameter_types! {
pub const BlockHashCount: BlockNumber = 900; // mortal tx can be valid up to 1 hour after signing
pub const BlockHashCount: BlockNumber = HOURS; // mortal tx can be valid up to 1 hour after signing
pub const Version: RuntimeVersion = VERSION;
pub const SS58Prefix: u8 = 42; // Ss58AddressFormat::SubstrateAccount
}
Expand Down Expand Up @@ -631,9 +631,9 @@ impl pallet_recovery::Config for Runtime {
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 20 * MINUTES;
pub const VotingPeriod: BlockNumber = 10 * MINUTES;
pub const FastTrackVotingPeriod: BlockNumber = 10 * MINUTES;
pub const LaunchPeriod: BlockNumber = 2 * HOURS;
pub const VotingPeriod: BlockNumber = HOURS;
pub const FastTrackVotingPeriod: BlockNumber = HOURS;
pub MinimumDeposit: Balance = 100 * cent(ACA);
pub const EnactmentPeriod: BlockNumber = MINUTES;
pub const CooloffPeriod: BlockNumber = MINUTES;
Expand Down Expand Up @@ -1555,7 +1555,7 @@ impl module_evm::Config for Runtime {
type TreasuryAccount = TreasuryAccount;
type FreeDeploymentOrigin = EnsureRootOrHalfGeneralCouncil;
type Runner = module_evm::runner::stack::Runner<Self>;
type FindAuthor = ();
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type WeightInfo = weights::module_evm::WeightInfo<Runtime>;

#[cfg(feature = "with-ethereum-compatibility")]
Expand Down Expand Up @@ -2489,4 +2489,13 @@ mod tests {
) > 0
);
}

//TODO: remove after paritytech/substrate#9890
#[test]
fn ensure_block_hash_count_less_than_democracy_launch_period() {
// Ensure LaunchPeriod > BlockHashCount
// Democracy will take full block weight.
// `ts-tests` need to reach BlockHashCount.
assert!(BlockHashCount::get() < LaunchPeriod::get());
}
}
18 changes: 0 additions & 18 deletions runtime/mandala/tests/solidity_test/Address.json

This file was deleted.

18 changes: 0 additions & 18 deletions runtime/mandala/tests/solidity_test/Counters.json

This file was deleted.

Loading