mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-12-02 23:37:06 +00:00
BREAKING: Rename Call & Event (#11981)
* rename Event to RuntimeEvent * rename Call * rename in runtimes * small fix * rename Event * small fix & rename RuntimeCall back to Call for now * small fixes * more renaming * a bit more renaming * fmt * small fix * commit * prep for renaming associated types * fix * rename associated Event type * rename to RuntimeEvent * commit * merge conflict fixes & fmt * additional renaming * fix. * fix decl_event * rename in tests * remove warnings * remove accidental rename * . * commit * update .stderr * fix in test * update .stderr * TRYBUILD=overwrite * docs * fmt * small change in docs * rename PalletEvent to Event * rename Call to RuntimeCall * renamed at wrong places :P * rename Call * rename * rename associated type * fix * fix & fmt * commit * frame-support-test * passing tests * update docs * rustdoc fix * update .stderr * wrong code in docs * merge fix * fix in error message * update .stderr * docs & error message * . * merge fix * merge fix * fmt * fmt * merge fix * more fixing * fmt * remove unused * fmt * fix Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
1 parent
472b5746e5
commit
6e8795afe6
228 files changed
+1791
-1672
No files matched your search
@@ -282,7 +282,7 @@ pub trait Ext: sealing::Sealed {
|
||||
fn append_debug_buffer(&mut self, msg: &str) -> bool;
|
||||
|
||||
/// Call some dispatchable and return the result.
|
||||
fn call_runtime(&self, call: <Self::T as Config>::Call) -> DispatchResultWithPostInfo;
|
||||
fn call_runtime(&self, call: <Self::T as Config>::RuntimeCall) -> DispatchResultWithPostInfo;
|
||||
|
||||
/// Recovers ECDSA compressed public key based on signature and message hash.
|
||||
fn ecdsa_recover(&self, signature: &[u8; 65], message_hash: &[u8; 32]) -> Result<[u8; 33], ()>;
|
||||
@@ -1305,7 +1305,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn call_runtime(&self, call: <Self::T as Config>::Call) -> DispatchResultWithPostInfo {
|
||||
fn call_runtime(&self, call: <Self::T as Config>::RuntimeCall) -> DispatchResultWithPostInfo {
|
||||
let mut origin: T::Origin = RawOrigin::Signed(self.address().clone()).into();
|
||||
origin.add_filter(T::CallFilter::contains);
|
||||
call.dispatch(origin)
|
||||
@@ -1370,7 +1370,8 @@ mod tests {
|
||||
storage::Storage,
|
||||
tests::{
|
||||
test_utils::{get_balance, hash, place_contract, set_balance},
|
||||
Call, Event as MetaEvent, ExtBuilder, Test, TestFilter, ALICE, BOB, CHARLIE, GAS_LIMIT,
|
||||
ExtBuilder, RuntimeCall, RuntimeEvent as MetaEvent, Test, TestFilter, ALICE, BOB,
|
||||
CHARLIE, GAS_LIMIT,
|
||||
},
|
||||
Error,
|
||||
};
|
||||
@@ -2575,7 +2576,7 @@ mod tests {
|
||||
#[test]
|
||||
fn call_runtime_works() {
|
||||
let code_hash = MockLoader::insert(Call, |ctx, _| {
|
||||
let call = Call::System(frame_system::Call::remark_with_event {
|
||||
let call = RuntimeCall::System(frame_system::Call::remark_with_event {
|
||||
remark: b"Hello World".to_vec(),
|
||||
});
|
||||
ctx.ext.call_runtime(call).unwrap();
|
||||
@@ -2636,10 +2637,11 @@ mod tests {
|
||||
|
||||
// remark should still be allowed
|
||||
let allowed_call =
|
||||
Call::System(SysCall::remark_with_event { remark: b"Hello".to_vec() });
|
||||
RuntimeCall::System(SysCall::remark_with_event { remark: b"Hello".to_vec() });
|
||||
|
||||
// transfers are disallowed by the `TestFiler` (see below)
|
||||
let forbidden_call = Call::Balances(BalanceCall::transfer { dest: CHARLIE, value: 22 });
|
||||
let forbidden_call =
|
||||
RuntimeCall::Balances(BalanceCall::transfer { dest: CHARLIE, value: 22 });
|
||||
|
||||
// simple cases: direct call
|
||||
assert_err!(
|
||||
@@ -2648,7 +2650,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// as part of a patch: return is OK (but it interrupted the batch)
|
||||
assert_ok!(ctx.ext.call_runtime(Call::Utility(UtilCall::batch {
|
||||
assert_ok!(ctx.ext.call_runtime(RuntimeCall::Utility(UtilCall::batch {
|
||||
calls: vec![allowed_call.clone(), forbidden_call, allowed_call]
|
||||
})),);
|
||||
|
||||
@@ -2659,7 +2661,7 @@ mod tests {
|
||||
});
|
||||
|
||||
TestFilter::set_filter(|call| match call {
|
||||
Call::Balances(pallet_balances::Call::transfer { .. }) => false,
|
||||
RuntimeCall::Balances(pallet_balances::Call::transfer { .. }) => false,
|
||||
_ => true,
|
||||
});
|
||||
|
||||
|
||||
@@ -243,13 +243,13 @@ pub mod pallet {
|
||||
type Currency: ReservableCurrency<Self::AccountId>;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The overarching call type.
|
||||
type Call: Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
type RuntimeCall: Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
+ GetDispatchInfo
|
||||
+ codec::Decode
|
||||
+ IsType<<Self as frame_system::Config>::Call>;
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeCall>;
|
||||
|
||||
/// Filter that is applied to calls dispatched by contracts.
|
||||
///
|
||||
@@ -260,7 +260,7 @@ pub mod pallet {
|
||||
/// # Stability
|
||||
///
|
||||
/// The runtime **must** make sure that all dispatchables that are callable by
|
||||
/// contracts remain stable. In addition [`Self::Call`] itself must remain stable.
|
||||
/// contracts remain stable. In addition [`Self::RuntimeCall`] itself must remain stable.
|
||||
/// This means that no existing variants are allowed to switch their positions.
|
||||
///
|
||||
/// # Note
|
||||
@@ -270,7 +270,7 @@ pub mod pallet {
|
||||
/// Therefore please make sure to be restrictive about which dispatchables are allowed
|
||||
/// in order to not introduce a new DoS vector like memory allocation patterns that can
|
||||
/// be exploited to drive the runtime into a panic.
|
||||
type CallFilter: Contains<<Self as frame_system::Config>::Call>;
|
||||
type CallFilter: Contains<<Self as frame_system::Config>::RuntimeCall>;
|
||||
|
||||
/// Used to answer contracts' queries regarding the current weight price. This is **not**
|
||||
/// used to calculate the actual fee and is only for informational purposes.
|
||||
@@ -1119,7 +1119,7 @@ where
|
||||
fn deposit_event(topics: Vec<T::Hash>, event: Event<T>) {
|
||||
<frame_system::Pallet<T>>::deposit_event_indexed(
|
||||
&topics,
|
||||
<T as Config>::Event::from(event).into(),
|
||||
<T as Config>::RuntimeEvent::from(event).into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -164,27 +164,27 @@ impl ChainExtension<Test> for TestExtension {
|
||||
let func_id = env.func_id();
|
||||
let id = env.ext_id() as u32 | func_id as u32;
|
||||
match func_id {
|
||||
0x8000 => {
|
||||
0 => {
|
||||
let mut env = env.buf_in_buf_out();
|
||||
let input = env.read(8)?;
|
||||
env.write(&input, false, None)?;
|
||||
TestExtensionTestValue::mutate(|e| e.last_seen_buffer = input);
|
||||
Ok(RetVal::Converging(id))
|
||||
},
|
||||
0x8001 => {
|
||||
1 => {
|
||||
let env = env.only_in();
|
||||
TestExtensionTestValue::mutate(|e| {
|
||||
e.last_seen_inputs = (env.val0(), env.val1(), env.val2(), env.val3())
|
||||
});
|
||||
Ok(RetVal::Converging(id))
|
||||
},
|
||||
0x8002 => {
|
||||
2 => {
|
||||
let mut env = env.buf_in_buf_out();
|
||||
let weight = Weight::from_ref_time(env.read(5)?[4].into());
|
||||
env.charge_weight(weight)?;
|
||||
Ok(RetVal::Converging(id))
|
||||
},
|
||||
0x8003 => Ok(RetVal::Diverging { flags: ReturnFlags::REVERT, data: vec![42, 99] }),
|
||||
3 => Ok(RetVal::Diverging { flags: ReturnFlags::REVERT, data: vec![42, 99] }),
|
||||
_ => {
|
||||
panic!("Passed unknown id to test chain extension: {}", func_id);
|
||||
},
|
||||
@@ -281,12 +281,12 @@ impl frame_system::Config for Test {
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Call = Call;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = AccountId32;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<250>;
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
@@ -304,7 +304,7 @@ impl pallet_balances::Config for Test {
|
||||
type MaxReserves = ();
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type Balance = u64;
|
||||
type Event = Event;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
@@ -318,8 +318,8 @@ impl pallet_timestamp::Config for Test {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
impl pallet_utility::Config for Test {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
@@ -346,7 +346,7 @@ pub struct TestFilter;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Filters {
|
||||
filter: fn(&Call) -> bool,
|
||||
filter: fn(&RuntimeCall) -> bool,
|
||||
}
|
||||
|
||||
impl Default for Filters {
|
||||
@@ -360,13 +360,13 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl TestFilter {
|
||||
pub fn set_filter(filter: fn(&Call) -> bool) {
|
||||
pub fn set_filter(filter: fn(&RuntimeCall) -> bool) {
|
||||
CallFilter::mutate(|fltr| fltr.filter = filter);
|
||||
}
|
||||
}
|
||||
|
||||
impl Contains<Call> for TestFilter {
|
||||
fn contains(call: &Call) -> bool {
|
||||
impl Contains<RuntimeCall> for TestFilter {
|
||||
fn contains(call: &RuntimeCall) -> bool {
|
||||
(CallFilter::get().filter)(call)
|
||||
}
|
||||
}
|
||||
@@ -379,8 +379,8 @@ impl Config for Test {
|
||||
type Time = Timestamp;
|
||||
type Randomness = Randomness;
|
||||
type Currency = Balances;
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type CallFilter = TestFilter;
|
||||
type CallStack = [Frame<Self>; 31];
|
||||
type WeightPrice = Self;
|
||||
@@ -536,12 +536,14 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }),
|
||||
event: RuntimeEvent::System(frame_system::Event::NewAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Endowed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Endowed {
|
||||
account: addr.clone(),
|
||||
free_balance: min_balance,
|
||||
}),
|
||||
@@ -549,7 +551,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: min_balance,
|
||||
@@ -558,7 +560,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: addr.clone(),
|
||||
amount: min_balance,
|
||||
}),
|
||||
@@ -566,7 +568,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: value,
|
||||
@@ -575,7 +577,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::ContractEmitted {
|
||||
event: RuntimeEvent::Contracts(crate::Event::ContractEmitted {
|
||||
contract: addr.clone(),
|
||||
data: vec![1, 2, 3, 4]
|
||||
}),
|
||||
@@ -583,7 +585,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Instantiated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
|
||||
deployer: ALICE,
|
||||
contract: addr.clone()
|
||||
}),
|
||||
@@ -828,14 +830,14 @@ fn deploy_and_call_other_contract() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::NewAccount {
|
||||
event: RuntimeEvent::System(frame_system::Event::NewAccount {
|
||||
account: callee_addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Endowed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Endowed {
|
||||
account: callee_addr.clone(),
|
||||
free_balance: min_balance,
|
||||
}),
|
||||
@@ -843,7 +845,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: callee_addr.clone(),
|
||||
amount: min_balance,
|
||||
@@ -852,7 +854,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: callee_addr.clone(),
|
||||
amount: min_balance,
|
||||
}),
|
||||
@@ -860,7 +862,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: caller_addr.clone(),
|
||||
to: callee_addr.clone(),
|
||||
amount: 32768, // hard coded in wasm
|
||||
@@ -869,7 +871,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Instantiated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
|
||||
deployer: caller_addr.clone(),
|
||||
contract: callee_addr.clone(),
|
||||
}),
|
||||
@@ -877,7 +879,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: caller_addr.clone(),
|
||||
to: callee_addr.clone(),
|
||||
amount: 32768,
|
||||
@@ -886,7 +888,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: caller_addr.clone(),
|
||||
contract: callee_addr.clone(),
|
||||
}),
|
||||
@@ -894,7 +896,7 @@ fn deploy_and_call_other_contract() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: caller_addr.clone(),
|
||||
}),
|
||||
@@ -1093,7 +1095,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Slashed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Slashed {
|
||||
who: addr.clone(),
|
||||
amount: 90,
|
||||
}),
|
||||
@@ -1101,7 +1103,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -1109,7 +1111,7 @@ fn cannot_self_destruct_by_refund_after_slash() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
from: addr.clone(),
|
||||
to: ALICE,
|
||||
amount: 10,
|
||||
@@ -1201,7 +1203,7 @@ fn self_destruct_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: addr.clone(),
|
||||
to: DJANGO,
|
||||
amount: 100_000,
|
||||
@@ -1210,7 +1212,7 @@ fn self_destruct_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Terminated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Terminated {
|
||||
contract: addr.clone(),
|
||||
beneficiary: DJANGO
|
||||
}),
|
||||
@@ -1218,7 +1220,7 @@ fn self_destruct_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -1226,14 +1228,14 @@ fn self_destruct_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::KilledAccount {
|
||||
event: RuntimeEvent::System(frame_system::Event::KilledAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
from: addr.clone(),
|
||||
to: ALICE,
|
||||
amount: 1_000,
|
||||
@@ -1698,22 +1700,21 @@ fn chain_extension_works() {
|
||||
),);
|
||||
let addr = Contracts::contract_address(&ALICE, &hash, &[]);
|
||||
|
||||
// 0x8000 = read input buffer and pass it through as output
|
||||
let input: Vec<u8> =
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8000, extra: &[99] }.into();
|
||||
// 0 = read input buffer and pass it through as output
|
||||
let input: Vec<u8> = ExtensionInput { extension_id: 0, func_id: 0, extra: &[99] }.into();
|
||||
let result =
|
||||
Contracts::bare_call(ALICE, addr.clone(), 0, GAS_LIMIT, None, input.clone(), false);
|
||||
assert_eq!(TestExtension::last_seen_buffer(), input);
|
||||
assert_eq!(result.result.unwrap().data, Bytes(input));
|
||||
|
||||
// 0x8001 = treat inputs as integer primitives and store the supplied integers
|
||||
// 1 = treat inputs as integer primitives and store the supplied integers
|
||||
Contracts::bare_call(
|
||||
ALICE,
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8001, extra: &[] }.into(),
|
||||
ExtensionInput { extension_id: 0, func_id: 1, extra: &[] }.into(),
|
||||
false,
|
||||
)
|
||||
.result
|
||||
@@ -1721,14 +1722,14 @@ fn chain_extension_works() {
|
||||
// those values passed in the fixture
|
||||
assert_eq!(TestExtension::last_seen_inputs(), (4, 4, 16, 12));
|
||||
|
||||
// 0x8002 = charge some extra weight (amount supplied in the fifth byte)
|
||||
// 2 = charge some extra weight (amount supplied in the fifth byte)
|
||||
let result = Contracts::bare_call(
|
||||
ALICE,
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8002, extra: &[0] }.into(),
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[0] }.into(),
|
||||
false,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
@@ -1739,7 +1740,7 @@ fn chain_extension_works() {
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8002, extra: &[42] }.into(),
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[42] }.into(),
|
||||
false,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
@@ -1750,20 +1751,20 @@ fn chain_extension_works() {
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8002, extra: &[95] }.into(),
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[95] }.into(),
|
||||
false,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
assert_eq!(result.gas_consumed, gas_consumed + 95);
|
||||
|
||||
// 0x8003 = diverging chain extension call that sets flags to 0x1 and returns a fixed buffer
|
||||
// 3 = diverging chain extension call that sets flags to 0x1 and returns a fixed buffer
|
||||
let result = Contracts::bare_call(
|
||||
ALICE,
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 0x8003, extra: &[] }.into(),
|
||||
ExtensionInput { extension_id: 0, func_id: 3, extra: &[] }.into(),
|
||||
false,
|
||||
)
|
||||
.result
|
||||
@@ -2550,7 +2551,7 @@ fn gas_estimation_call_runtime() {
|
||||
|
||||
// Call something trivial with a huge gas limit so that we can observe the effects
|
||||
// of pre-charging. This should create a difference between consumed and required.
|
||||
let call = Call::Contracts(crate::Call::call {
|
||||
let call = RuntimeCall::Contracts(crate::Call::call {
|
||||
dest: addr_callee,
|
||||
value: 0,
|
||||
gas_limit: GAS_LIMIT / 3,
|
||||
@@ -2660,7 +2661,7 @@ fn upload_code_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -2668,7 +2669,7 @@ fn upload_code_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
]
|
||||
@@ -2739,7 +2740,7 @@ fn remove_code_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -2747,12 +2748,12 @@ fn remove_code_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Unreserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Unreserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -2760,7 +2761,7 @@ fn remove_code_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeRemoved { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeRemoved { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
]
|
||||
@@ -2794,7 +2795,7 @@ fn remove_code_wrong_origin() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -2802,7 +2803,7 @@ fn remove_code_wrong_origin() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
]
|
||||
@@ -2895,12 +2896,14 @@ fn instantiate_with_zero_balance_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }),
|
||||
event: RuntimeEvent::System(frame_system::Event::NewAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Endowed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Endowed {
|
||||
account: addr.clone(),
|
||||
free_balance: min_balance,
|
||||
}),
|
||||
@@ -2908,7 +2911,7 @@ fn instantiate_with_zero_balance_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: min_balance,
|
||||
@@ -2917,7 +2920,7 @@ fn instantiate_with_zero_balance_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: addr.clone(),
|
||||
amount: min_balance,
|
||||
}),
|
||||
@@ -2925,7 +2928,7 @@ fn instantiate_with_zero_balance_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -2933,12 +2936,12 @@ fn instantiate_with_zero_balance_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Instantiated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
|
||||
deployer: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -2986,12 +2989,14 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }),
|
||||
event: RuntimeEvent::System(frame_system::Event::NewAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Endowed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Endowed {
|
||||
account: addr.clone(),
|
||||
free_balance: min_balance,
|
||||
}),
|
||||
@@ -2999,7 +3004,7 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: min_balance,
|
||||
@@ -3008,7 +3013,7 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: addr.clone(),
|
||||
amount: min_balance,
|
||||
}),
|
||||
@@ -3016,7 +3021,7 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: 50,
|
||||
@@ -3025,7 +3030,7 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: ALICE,
|
||||
amount: 240,
|
||||
}),
|
||||
@@ -3033,12 +3038,12 @@ fn instantiate_with_below_existential_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
event: RuntimeEvent::Contracts(crate::Event::CodeStored { code_hash }),
|
||||
topics: vec![code_hash],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Instantiated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Instantiated {
|
||||
deployer: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3115,7 +3120,7 @@ fn storage_deposit_works() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: 42,
|
||||
@@ -3124,7 +3129,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3132,7 +3137,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: charged0,
|
||||
@@ -3141,7 +3146,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: addr.clone(),
|
||||
amount: charged0,
|
||||
}),
|
||||
@@ -3149,7 +3154,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3157,7 +3162,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: charged1,
|
||||
@@ -3166,7 +3171,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Reserved {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Reserved {
|
||||
who: addr.clone(),
|
||||
amount: charged1,
|
||||
}),
|
||||
@@ -3174,7 +3179,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3182,7 +3187,7 @@ fn storage_deposit_works() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::ReserveRepatriated {
|
||||
from: addr.clone(),
|
||||
to: ALICE,
|
||||
amount: refunded0,
|
||||
@@ -3264,7 +3269,7 @@ fn set_code_extrinsic() {
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(pallet_contracts::Event::ContractCodeUpdated {
|
||||
event: RuntimeEvent::Contracts(pallet_contracts::Event::ContractCodeUpdated {
|
||||
contract: addr.clone(),
|
||||
new_code_hash,
|
||||
old_code_hash: code_hash,
|
||||
@@ -3343,14 +3348,14 @@ fn call_after_killed_account_needs_funding() {
|
||||
vec![
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::KilledAccount {
|
||||
event: RuntimeEvent::System(frame_system::Event::KilledAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Slashed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Slashed {
|
||||
who: addr.clone(),
|
||||
amount: min_balance + 700
|
||||
}),
|
||||
@@ -3358,7 +3363,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3366,12 +3371,14 @@ fn call_after_killed_account_needs_funding() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }),
|
||||
event: RuntimeEvent::System(frame_system::Event::NewAccount {
|
||||
account: addr.clone()
|
||||
}),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Endowed {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Endowed {
|
||||
account: addr.clone(),
|
||||
free_balance: min_balance
|
||||
}),
|
||||
@@ -3379,7 +3386,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Balances(pallet_balances::Event::Transfer {
|
||||
event: RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
from: ALICE,
|
||||
to: addr.clone(),
|
||||
amount: min_balance
|
||||
@@ -3388,7 +3395,7 @@ fn call_after_killed_account_needs_funding() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: addr.clone(),
|
||||
}),
|
||||
@@ -3571,7 +3578,7 @@ fn set_code_hash() {
|
||||
&[
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::ContractCodeUpdated {
|
||||
event: RuntimeEvent::Contracts(crate::Event::ContractCodeUpdated {
|
||||
contract: contract_addr.clone(),
|
||||
new_code_hash,
|
||||
old_code_hash: code_hash,
|
||||
@@ -3580,7 +3587,7 @@ fn set_code_hash() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: contract_addr.clone(),
|
||||
}),
|
||||
@@ -3588,7 +3595,7 @@ fn set_code_hash() {
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Contracts(crate::Event::Called {
|
||||
event: RuntimeEvent::Contracts(crate::Event::Called {
|
||||
caller: ALICE,
|
||||
contract: contract_addr.clone(),
|
||||
}),
|
||||
|
||||
@@ -280,7 +280,7 @@ mod tests {
|
||||
},
|
||||
gas::GasMeter,
|
||||
storage::WriteOutcome,
|
||||
tests::{Call, Test, ALICE, BOB},
|
||||
tests::{RuntimeCall, Test, ALICE, BOB},
|
||||
BalanceOf, CodeHash, Error, Pallet as Contracts,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
@@ -339,7 +339,7 @@ mod tests {
|
||||
transfers: Vec<TransferEntry>,
|
||||
// (topics, data)
|
||||
events: Vec<(Vec<H256>, Vec<u8>)>,
|
||||
runtime_calls: RefCell<Vec<Call>>,
|
||||
runtime_calls: RefCell<Vec<RuntimeCall>>,
|
||||
schedule: Schedule<Test>,
|
||||
gas_meter: GasMeter<Test>,
|
||||
debug_buffer: Vec<u8>,
|
||||
@@ -532,7 +532,10 @@ mod tests {
|
||||
self.debug_buffer.extend(msg.as_bytes());
|
||||
true
|
||||
}
|
||||
fn call_runtime(&self, call: <Self::T as Config>::Call) -> DispatchResultWithPostInfo {
|
||||
fn call_runtime(
|
||||
&self,
|
||||
call: <Self::T as Config>::RuntimeCall,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
self.runtime_calls.borrow_mut().push(call);
|
||||
Ok(Default::default())
|
||||
}
|
||||
@@ -2299,7 +2302,8 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn call_runtime_works() {
|
||||
let call = Call::System(frame_system::Call::remark { remark: b"Hello World".to_vec() });
|
||||
let call =
|
||||
RuntimeCall::System(frame_system::Call::remark { remark: b"Hello World".to_vec() });
|
||||
let mut ext = MockExt::default();
|
||||
let result = execute(CODE_CALL_RUNTIME, call.encode(), &mut ext).unwrap();
|
||||
assert_eq!(*ext.runtime_calls.borrow(), vec![call]);
|
||||
|
||||
@@ -2316,7 +2316,7 @@ pub mod env {
|
||||
) -> Result<ReturnCode, TrapReason> {
|
||||
use frame_support::{dispatch::GetDispatchInfo, weights::extract_actual_weight};
|
||||
ctx.charge_gas(RuntimeCosts::CopyFromContract(call_len))?;
|
||||
let call: <E::T as Config>::Call =
|
||||
let call: <E::T as Config>::RuntimeCall =
|
||||
ctx.read_sandbox_memory_as_unbounded(call_ptr, call_len)?;
|
||||
let dispatch_info = call.get_dispatch_info();
|
||||
let charged = ctx.charge_gas(RuntimeCosts::CallRuntime(dispatch_info.weight))?;
|
||||
|
||||
Reference in new issue
Block a user