diff --git a/modules/currencies/src/mock.rs b/modules/currencies/src/mock.rs index e8e2059971..e9a2749946 100644 --- a/modules/currencies/src/mock.rs +++ b/modules/currencies/src/mock.rs @@ -253,6 +253,7 @@ pub fn deploy_contracts() { )); System::assert_last_event(Event::EVM(module_evm::Event::Created( + alice_evm_addr(), erc20_address(), vec![module_evm::Log { address: H160::from_str("0x0000000000000000000000000000000002000000").unwrap(), @@ -261,10 +262,7 @@ pub fn deploy_contracts() { H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), H256::from_str("0x0000000000000000000000001000000000000000000000000000000000000001").unwrap(), ], - data: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 16, - ] - .to_vec(), + data: H256::from_low_u64_be(10000).as_bytes().to_vec(), }], ))); diff --git a/modules/evm-accounts/Cargo.toml b/modules/evm-accounts/Cargo.toml index 77651cc756..4cb9ad5d3d 100644 --- a/modules/evm-accounts/Cargo.toml +++ b/modules/evm-accounts/Cargo.toml @@ -42,4 +42,8 @@ std = [ "orml-traits/std", "module-support/std", ] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] try-runtime = ["frame-support/try-runtime"] diff --git a/modules/evm-accounts/src/lib.rs b/modules/evm-accounts/src/lib.rs index 2ec48a546a..a038a32bd9 100644 --- a/modules/evm-accounts/src/lib.rs +++ b/modules/evm-accounts/src/lib.rs @@ -218,7 +218,9 @@ impl Pallet { secp256k1::PublicKey::from_secret_key(secret) } + #[cfg(any(feature = "runtime-benchmarks", feature = "std"))] // Returns an Etherum address derived from an Ethereum secret key. + // Only for tests pub fn eth_address(secret: &secp256k1::SecretKey) -> EvmAddress { EvmAddress::from_slice(&keccak_256(&Self::eth_public(secret).serialize()[1..65])[12..]) } diff --git a/modules/evm-bridge/src/mock.rs b/modules/evm-bridge/src/mock.rs index 99b213779e..897c3ce03b 100644 --- a/modules/evm-bridge/src/mock.rs +++ b/modules/evm-bridge/src/mock.rs @@ -189,6 +189,7 @@ pub fn deploy_contracts() { assert_ok!(EVM::create(Origin::signed(alice()), code, 0, 2_100_000, 10000)); System::assert_last_event(Event::EVM(module_evm::Event::Created( + alice_evm_addr(), erc20_address(), vec![module_evm::Log { address: erc20_address(), @@ -197,10 +198,7 @@ pub fn deploy_contracts() { H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), H256::from_str("0x0000000000000000000000001000000000000000000000000000000000000001").unwrap(), ], - data: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 16, - ] - .to_vec(), + data: H256::from_low_u64_be(10000).as_bytes().to_vec(), }], ))); diff --git a/modules/evm-manager/src/mock.rs b/modules/evm-manager/src/mock.rs index dfef411da0..ef0950abc2 100644 --- a/modules/evm-manager/src/mock.rs +++ b/modules/evm-manager/src/mock.rs @@ -218,6 +218,7 @@ pub fn deploy_contracts() { )); System::assert_last_event(Event::EVM(module_evm::Event::Created( + alice_evm_addr(), erc20_address(), vec![module_evm::Log { address: H160::from_str("0x0000000000000000000000000000000002000000").unwrap(), @@ -226,10 +227,7 @@ pub fn deploy_contracts() { H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), H256::from_str("0x0000000000000000000000001000000000000000000000000000000000000001").unwrap(), ], - data: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 16, - ] - .to_vec(), + data: H256::from_low_u64_be(10000).as_bytes().to_vec(), }], ))); diff --git a/modules/evm/src/lib.rs b/modules/evm/src/lib.rs index 731b16f097..23c2407caa 100644 --- a/modules/evm/src/lib.rs +++ b/modules/evm/src/lib.rs @@ -390,16 +390,16 @@ pub mod module { #[pallet::generate_deposit(pub(crate) fn deposit_event)] #[pallet::metadata(T::AccountId = "AccountId")] pub enum Event { - /// A contract has been created at given \[address, logs\]. - Created(EvmAddress, Vec), + /// A contract has been created at given \[from, address, logs\]. + Created(EvmAddress, EvmAddress, Vec), /// A contract was attempted to be created, but the execution failed. - /// \[contract, exit_reason, logs\] - CreatedFailed(EvmAddress, ExitReason, Vec), - /// A contract has been executed successfully with states applied. \[contract, logs]\ - Executed(EvmAddress, Vec), + /// \[from, contract, exit_reason, logs\] + CreatedFailed(EvmAddress, EvmAddress, ExitReason, Vec), + /// A contract has been executed successfully with states applied. \[from, contract, logs]\ + Executed(EvmAddress, EvmAddress, Vec), /// A contract has been executed with errors. States are reverted with - /// only gas fees applied. \[contract, exit_reason, output, logs\] - ExecutedFailed(EvmAddress, ExitReason, Vec, Vec), + /// only gas fees applied. \[from, contract, exit_reason, output, logs\] + ExecutedFailed(EvmAddress, EvmAddress, ExitReason, Vec, Vec), /// Transferred maintainer. \[contract, address\] TransferredMaintainer(EvmAddress, EvmAddress), /// Enabled contract development. \[who\] diff --git a/modules/evm/src/runner/stack.rs b/modules/evm/src/runner/stack.rs index 7186f10c4d..e717297628 100644 --- a/modules/evm/src/runner/stack.rs +++ b/modules/evm/src/runner/stack.rs @@ -211,9 +211,10 @@ impl RunnerT for Runner { })?; if info.exit_reason.is_succeed() { - Pallet::::deposit_event(Event::::Executed(target, info.logs.clone())); + Pallet::::deposit_event(Event::::Executed(source, target, info.logs.clone())); } else { Pallet::::deposit_event(Event::::ExecutedFailed( + source, target, info.exit_reason.clone(), info.value.clone(), @@ -241,9 +242,10 @@ impl RunnerT for Runner { })?; if info.exit_reason.is_succeed() { - Pallet::::deposit_event(Event::::Created(info.value, info.logs.clone())); + Pallet::::deposit_event(Event::::Created(source, info.value, info.logs.clone())); } else { Pallet::::deposit_event(Event::::CreatedFailed( + source, info.value, info.exit_reason.clone(), info.logs.clone(), @@ -276,9 +278,10 @@ impl RunnerT for Runner { })?; if info.exit_reason.is_succeed() { - Pallet::::deposit_event(Event::::Created(info.value, info.logs.clone())); + Pallet::::deposit_event(Event::::Created(source, info.value, info.logs.clone())); } else { Pallet::::deposit_event(Event::::CreatedFailed( + source, info.value, info.exit_reason.clone(), info.logs.clone(), @@ -306,9 +309,10 @@ impl RunnerT for Runner { })?; if info.exit_reason.is_succeed() { - Pallet::::deposit_event(Event::::Created(info.value, info.logs.clone())); + Pallet::::deposit_event(Event::::Created(source, info.value, info.logs.clone())); } else { Pallet::::deposit_event(Event::::CreatedFailed( + source, info.value, info.exit_reason.clone(), info.logs.clone(), diff --git a/modules/evm/src/tests.rs b/modules/evm/src/tests.rs index 8213615eb8..66a608dc01 100644 --- a/modules/evm/src/tests.rs +++ b/modules/evm/src/tests.rs @@ -645,6 +645,7 @@ fn create_network_contract_works() { 2.into() ); System::assert_last_event(Event::EVM(crate::Event::Created( + NetworkContractSource::get(), H160::from_low_u64_be(MIRRORED_NFT_ADDRESS_START), vec![], ))); @@ -709,7 +710,11 @@ fn create_predeploy_contract_works() { assert_eq!(Pallet::::is_account_empty(&addr), false); - System::assert_last_event(Event::EVM(crate::Event::Created(addr, vec![]))); + System::assert_last_event(Event::EVM(crate::Event::Created( + NetworkContractSource::get(), + addr, + vec![], + ))); assert_noop!( EVM::create_predeploy_contract( diff --git a/runtime/integration-tests/src/evm_tests.rs b/runtime/integration-tests/src/evm_tests.rs index 147fd44d1d..cfb944dc3a 100644 --- a/runtime/integration-tests/src/evm_tests.rs +++ b/runtime/integration-tests/src/evm_tests.rs @@ -67,6 +67,7 @@ pub fn deploy_erc20_contracts() { )); System::assert_last_event(Event::EVM(module_evm::Event::Created( + Default::default(), erc20_address_0(), vec![module_evm::Log { address: erc20_address_0(), @@ -75,10 +76,7 @@ pub fn deploy_erc20_contracts() { H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), H256::from_str("0x0000000000000000000000001000000000000000000000000000000000000001").unwrap(), ], - data: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 16, - ] - .to_vec(), + data: H256::from_low_u64_be(10000).as_bytes().to_vec(), }], ))); @@ -87,6 +85,7 @@ pub fn deploy_erc20_contracts() { assert_ok!(EVM::create_network_contract(Origin::root(), code, 0, 2100_000, 100000)); System::assert_last_event(Event::EVM(module_evm::Event::Created( + Default::default(), erc20_address_1(), vec![module_evm::Log { address: erc20_address_1(), @@ -95,10 +94,7 @@ pub fn deploy_erc20_contracts() { H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), H256::from_str("0x0000000000000000000000001000000000000000000000000000000000000001").unwrap(), ], - data: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 16, - ] - .to_vec(), + data: H256::from_low_u64_be(10000).as_bytes().to_vec(), }], ))); @@ -122,8 +118,7 @@ fn deploy_contract(account: AccountId) -> Result { EVM::create(Origin::signed(account), contract, 0, 1000000000, 100000).map_or_else(|e| Err(e.error), |_| Ok(()))?; - if let Event::EVM(module_evm::Event::::Created(address, _)) = System::events().iter().last().unwrap().event - { + if let Event::EVM(module_evm::Event::::Created(_, address, _)) = System::events().last().unwrap().event { Ok(address) } else { Err("deploy_contract failed".into()) @@ -314,11 +309,11 @@ fn test_evm_module() { assert_eq!(Balances::free_balance(alice()), 1_000 * dollar(NATIVE_CURRENCY)); assert_eq!(Balances::free_balance(bob()), 1_000 * dollar(NATIVE_CURRENCY)); - let _alice_address = EvmAccounts::eth_address(&alice_key()); + let alice_address = EvmAccounts::eth_address(&alice_key()); let bob_address = EvmAccounts::eth_address(&bob_key()); let contract = deploy_contract(alice()).unwrap(); - System::assert_last_event(Event::EVM(module_evm::Event::Created(contract, vec![]))); + System::assert_last_event(Event::EVM(module_evm::Event::Created(alice_address, contract, vec![]))); assert_ok!(EVM::transfer_maintainer(Origin::signed(alice()), contract, bob_address)); System::assert_last_event(Event::EVM(module_evm::Event::TransferredMaintainer( @@ -504,7 +499,7 @@ fn should_not_kill_contract_on_transfer_all() { assert_ok!(EVM::create(Origin::signed(alice()), code, 2 * dollar(NATIVE_CURRENCY), 1000000000, 100000)); - let contract = if let Event::EVM(module_evm::Event::Created(address, _)) = System::events().iter().last().unwrap().event { + let contract = if let Event::EVM(module_evm::Event::Created(_, address, _)) = System::events().last().unwrap().event { address } else { panic!("deploy contract failed"); @@ -564,7 +559,8 @@ fn should_not_kill_contract_on_transfer_all_tokens() { // } let code = hex_literal::hex!("608060405260848060116000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806341c0e1b514602d575b600080fd5b60336035565b005b600073ffffffffffffffffffffffffffffffffffffffff16fffea265627a7a72315820ed64a7551098c4afc823bee1663309079d9cb8798a6bdd71be2cd3ccee52d98e64736f6c63430005110032").to_vec(); assert_ok!(EVM::create(Origin::signed(alice()), code, 0, 1000000000, 100000)); - let contract = if let Event::EVM(module_evm::Event::Created(address, _)) = System::events().iter().last().unwrap().event { + + let contract = if let Event::EVM(module_evm::Event::Created(_, address, _)) = System::events().last().unwrap().event { address } else { panic!("deploy contract failed"); diff --git a/runtime/karura/Cargo.toml b/runtime/karura/Cargo.toml index fc22f20ba2..c779b7c913 100644 --- a/runtime/karura/Cargo.toml +++ b/runtime/karura/Cargo.toml @@ -256,6 +256,7 @@ runtime-benchmarks = [ "module-nft/runtime-benchmarks", "module-homa-lite/runtime-benchmarks", + "module-evm-accounts/runtime-benchmarks", "sp-api/disable-logging", ] diff --git a/runtime/mandala/Cargo.toml b/runtime/mandala/Cargo.toml index 6b99a31029..5280b9a0a4 100644 --- a/runtime/mandala/Cargo.toml +++ b/runtime/mandala/Cargo.toml @@ -286,6 +286,7 @@ runtime-benchmarks = [ "module-nft/runtime-benchmarks", "module-homa-lite/runtime-benchmarks", + "module-evm-accounts/runtime-benchmarks", "sp-api/disable-logging", ] diff --git a/runtime/mandala/src/benchmarking/evm.rs b/runtime/mandala/src/benchmarking/evm.rs index ce505dbb7f..489076b75c 100644 --- a/runtime/mandala/src/benchmarking/evm.rs +++ b/runtime/mandala/src/benchmarking/evm.rs @@ -21,6 +21,7 @@ use crate::{dollar, AccountId, CurrencyId, Event, EvmAccounts, GetNativeCurrency use super::utils::set_balance; use frame_support::dispatch::DispatchError; use frame_system::RawOrigin; +use module_support::AddressMapping; use orml_benchmarking::{runtime_benchmarks, whitelist_account}; use sp_core::H160; use sp_io::hashing::keccak_256; @@ -56,10 +57,14 @@ fn deploy_contract(caller: AccountId) -> Result { let contract = hex_literal::hex!("608060405234801561001057600080fd5b5061016f806100206000396000f3fe608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063412a5a6d14610046575b600080fd5b61004e610050565b005b600061005a6100e2565b604051809103906000f080158015610076573d6000803e3d6000fd5b50905060008190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6040516052806100f28339019056fe6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a7230582092dc1966a8880ddf11e067f9dd56a632c11a78a4afd4a9f05924d427367958cc0029a165627a7a723058202b2cc7384e11c452cdbf39b68dada2d5e10a632cc0174a354b8b8c83237e28a40029").to_vec(); System::set_block_number(1); - EVM::create(Origin::signed(caller), contract, 0, 1000000000, 1000000000) + EVM::create(Origin::signed(caller.clone()), contract, 0, 1000000000, 1000000000) .map_or_else(|e| Err(e.error), |_| Ok(()))?; - System::assert_last_event(Event::EVM(module_evm::Event::Created(contract_addr(), vec![]))); + System::assert_last_event(Event::EVM(module_evm::Event::Created( + module_evm_accounts::EvmAddressMapping::::get_evm_address(&caller).unwrap(), + contract_addr(), + vec![], + ))); Ok(contract_addr()) } diff --git a/ts-tests/package.json b/ts-tests/package.json index 8065052699..b119fd58d0 100644 --- a/ts-tests/package.json +++ b/ts-tests/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@acala-network/api": "^2.2.2-1", - "@acala-network/bodhi": "1.0.2-14", + "@acala-network/bodhi": "^1.0.4-0", "@openzeppelin/contracts": "4.3.2", "@polkadot/api": "^5.2.1", "@types/chai": "^4.2.11", diff --git a/ts-tests/tests/test-transaction-cost.ts b/ts-tests/tests/test-transaction-cost.ts index 4cafb9f47b..d3fcf96fc3 100644 --- a/ts-tests/tests/test-transaction-cost.ts +++ b/ts-tests/tests/test-transaction-cost.ts @@ -13,11 +13,6 @@ describeWithAcala("Acala RPC (Transaction cost)", (context) => { const contract = await deployContract(alice as any, Erc20DemoContract, [1000000000]); const to = await ethers.Wallet.createRandom().getAddress(); - try { - await contract.transfer(to, 1000, { gasLimit: 0 }); - } - catch(err) { - expect(err).to.equal('{"error":{"outofgas":null}} '); - } + await expect(contract.transfer(to, 1000, { gasLimit: 0 })).to.be.rejectedWith('{"error":{"outofgas":null}} '); }); }); diff --git a/ts-tests/yarn.lock b/ts-tests/yarn.lock index 271e1560f4..ddc5fd3bf7 100644 --- a/ts-tests/yarn.lock +++ b/ts-tests/yarn.lock @@ -24,10 +24,10 @@ "@polkadot/api" "^5.9.1" "@polkadot/rpc-core" "^5.9.1" -"@acala-network/bodhi@1.0.2-14": - version "1.0.2-14" - resolved "https://registry.yarnpkg.com/@acala-network/bodhi/-/bodhi-1.0.2-14.tgz#52fd7774887b886b10b23b63e405e003705ce3ae" - integrity sha512-lW4sK0ahyf+bcjmDkgK2uwZ1kgNNRq/xhuwtBS+TOeC5Tt+48L0/JEORFXjpDHg5Rcz+2nL75Q/3ZkmEGRMG9A== +"@acala-network/bodhi@^1.0.4-0": + version "1.0.4-0" + resolved "https://registry.yarnpkg.com/@acala-network/bodhi/-/bodhi-1.0.4-0.tgz#7b1635343f002c98f96879c2cf9a06126816caae" + integrity sha512-x12AlZC5x2epEvr6SetTybnkKbW4U/KCn4R0QFBBC06bNAIEwTfWHSO0omVXbil3Rs6EXhb1oDxy53IGWcloTA== dependencies: "@open-web3/scanner" "^0.9.4-19" blakejs "^1.1.0"