Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add origin to events #1461

Merged
merged 5 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions modules/currencies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}],
)));

Expand Down
6 changes: 2 additions & 4 deletions modules/evm-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}],
)));

Expand Down
6 changes: 2 additions & 4 deletions modules/evm-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}],
)));

Expand Down
16 changes: 8 additions & 8 deletions modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,16 @@ pub mod module {
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
#[pallet::metadata(T::AccountId = "AccountId")]
pub enum Event<T: Config> {
/// A contract has been created at given \[address, logs\].
Created(EvmAddress, Vec<Log>),
/// A contract has been created at given \[from, address, logs\].
Created(EvmAddress, EvmAddress, Vec<Log>),
/// A contract was attempted to be created, but the execution failed.
/// \[contract, exit_reason, logs\]
CreatedFailed(EvmAddress, ExitReason, Vec<Log>),
/// A contract has been executed successfully with states applied. \[contract, logs]\
Executed(EvmAddress, Vec<Log>),
/// \[from, contract, exit_reason, logs\]
CreatedFailed(EvmAddress, EvmAddress, ExitReason, Vec<Log>),
/// A contract has been executed successfully with states applied. \[from, contract, logs]\
Executed(EvmAddress, EvmAddress, Vec<Log>),
/// A contract has been executed with errors. States are reverted with
/// only gas fees applied. \[contract, exit_reason, output, logs\]
ExecutedFailed(EvmAddress, ExitReason, Vec<u8>, Vec<Log>),
/// only gas fees applied. \[from, contract, exit_reason, output, logs\]
ExecutedFailed(EvmAddress, EvmAddress, ExitReason, Vec<u8>, Vec<Log>),
/// Transferred maintainer. \[contract, address\]
TransferredMaintainer(EvmAddress, EvmAddress),
/// Enabled contract development. \[who\]
Expand Down
12 changes: 8 additions & 4 deletions modules/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ impl<T: Config> RunnerT<T> for Runner<T> {
})?;

if info.exit_reason.is_succeed() {
Pallet::<T>::deposit_event(Event::<T>::Executed(target, info.logs.clone()));
Pallet::<T>::deposit_event(Event::<T>::Executed(source, target, info.logs.clone()));
} else {
Pallet::<T>::deposit_event(Event::<T>::ExecutedFailed(
source,
target,
info.exit_reason.clone(),
info.value.clone(),
Expand Down Expand Up @@ -241,9 +242,10 @@ impl<T: Config> RunnerT<T> for Runner<T> {
})?;

if info.exit_reason.is_succeed() {
Pallet::<T>::deposit_event(Event::<T>::Created(info.value, info.logs.clone()));
Pallet::<T>::deposit_event(Event::<T>::Created(source, info.value, info.logs.clone()));
} else {
Pallet::<T>::deposit_event(Event::<T>::CreatedFailed(
source,
info.value,
info.exit_reason.clone(),
info.logs.clone(),
Expand Down Expand Up @@ -276,9 +278,10 @@ impl<T: Config> RunnerT<T> for Runner<T> {
})?;

if info.exit_reason.is_succeed() {
Pallet::<T>::deposit_event(Event::<T>::Created(info.value, info.logs.clone()));
Pallet::<T>::deposit_event(Event::<T>::Created(source, info.value, info.logs.clone()));
} else {
Pallet::<T>::deposit_event(Event::<T>::CreatedFailed(
source,
info.value,
info.exit_reason.clone(),
info.logs.clone(),
Expand Down Expand Up @@ -306,9 +309,10 @@ impl<T: Config> RunnerT<T> for Runner<T> {
})?;

if info.exit_reason.is_succeed() {
Pallet::<T>::deposit_event(Event::<T>::Created(info.value, info.logs.clone()));
Pallet::<T>::deposit_event(Event::<T>::Created(source, info.value, info.logs.clone()));
} else {
Pallet::<T>::deposit_event(Event::<T>::CreatedFailed(
source,
info.value,
info.exit_reason.clone(),
info.logs.clone(),
Expand Down
7 changes: 6 additions & 1 deletion modules/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
)));
Expand Down Expand Up @@ -709,7 +710,11 @@ fn create_predeploy_contract_works() {

assert_eq!(Pallet::<Runtime>::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(
Expand Down
24 changes: 11 additions & 13 deletions runtime/integration-tests/src/evm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
}],
)));

Expand All @@ -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(),
Expand All @@ -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(),
}],
)));

Expand All @@ -122,7 +118,8 @@ fn deploy_contract(account: AccountId) -> Result<H160, DispatchError> {

EVM::create(Origin::signed(account), contract, 0, 1000000000, 100000).map_or_else(|e| Err(e.error), |_| Ok(()))?;

if let Event::EVM(module_evm::Event::<Runtime>::Created(address, _)) = System::events().iter().last().unwrap().event
if let Event::EVM(module_evm::Event::<Runtime>::Created(_, address, _)) =
System::events().iter().last().unwrap().event
xlc marked this conversation as resolved.
Show resolved Hide resolved
{
Ok(address)
} else {
Expand Down Expand Up @@ -314,11 +311,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(
Expand Down Expand Up @@ -504,7 +501,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");
Expand Down Expand Up @@ -564,7 +561,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");
Expand Down
6 changes: 5 additions & 1 deletion runtime/mandala/src/benchmarking/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ fn deploy_contract(caller: AccountId) -> Result<H160, DispatchError> {
EVM::create(Origin::signed(caller), 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(
Default::default(),
contract_addr(),
vec![],
)));
Ok(contract_addr())
}

Expand Down