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
12 changes: 12 additions & 0 deletions prdoc/pr_8789.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: '[pallet-revive] Add contract instantiated event'

doc:
- audience: Runtime Dev
description: ' `instantiate` and `instantiate_with_code` emit a `Instantiated` event.'

crates:
- name: pallet-revive
bump: major
13 changes: 10 additions & 3 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ where
skip_transfer: bool,
bump_nonce: BumpNonce,
) -> Result<(H160, ExecReturnValue), ExecError> {
let deployer = T::AddressMapper::to_address(&origin);
let (mut stack, executable) = Stack::<'_, T, E>::new(
FrameArgs::Instantiate {
sender: origin.clone(),
Expand All @@ -830,9 +831,15 @@ where
)?
.expect(FRAME_ALWAYS_EXISTS_ON_INSTANTIATE);
let address = T::AddressMapper::to_address(&stack.top_frame().account_id);
stack
let result = stack
.run(executable, input_data, bump_nonce)
.map(|_| (address, stack.first_frame.last_frame_output))
.map(|_| (address, stack.first_frame.last_frame_output));
if let Ok((contract, ref output)) = result {
if !output.did_revert() {
Contracts::<T>::deposit_event(Event::Instantiated { deployer, contract });
}
}
result
}

#[cfg(any(feature = "runtime-benchmarks", test))]
Expand Down Expand Up @@ -930,7 +937,7 @@ where
if let Some(info) = <ContractInfoOf<T>>::get(&address) {
CachedContract::Cached(info)
} else {
return Ok(None)
return Ok(None);
},
(None, Some(precompile)) if precompile.has_contract_info() => {
if let Some(info) = <ContractInfoOf<T>>::get(&address) {
Expand Down
7 changes: 7 additions & 0 deletions substrate/frame/revive/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,13 @@ fn instantiation_work_with_success_output() {
ContractInfo::<Test>::load_code_hash(&instantiated_contract_id).unwrap(),
dummy_ch
);
assert_eq!(
&events(),
&[Event::Instantiated {
deployer: ALICE_ADDR,
contract: instantiated_contract_address
}]
);
Comment on lines +1148 to +1154
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only test that was effected.

I've checked there's also a test that already checks the case when the instantiation call succeeds but the contract is reverted - In that case there's already an assertion that checks that no events should be emitted. See instantiation_fails_with_failing_output.

All these tests were done previously, but updated the event assertions when #7164 removed the events. The only one that needed to be updated is this one.

});
}

Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ pub mod pallet {
/// Number of topics is capped by [`limits::NUM_EVENT_TOPICS`].
topics: Vec<H256>,
},

/// Contract deployed by deployer at the specified address.
Instantiated { deployer: H160, contract: H160 },
}

#[pallet::error]
Expand Down
24 changes: 24 additions & 0 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ fn instantiate_and_call_and_deposit_event() {
}),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
deployer: ALICE_ADDR,
contract: addr
}),
topics: vec![],
},
]
);
});
Expand Down Expand Up @@ -2220,6 +2228,14 @@ fn instantiate_with_zero_balance_works() {
}),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
deployer: ALICE_ADDR,
contract: addr,
}),
topics: vec![],
},
]
);
});
Expand Down Expand Up @@ -2286,6 +2302,14 @@ fn instantiate_with_below_existential_deposit_works() {
}),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
deployer: ALICE_ADDR,
contract: addr,
}),
topics: vec![],
},
]
);
});
Expand Down