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

Contracts expose pallet-xcm #1248

Merged
merged 126 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
251e8cd
boilerplate type changes
pgherveou Aug 29, 2023
3b1cc37
Add pallet_xcm::execute
pgherveou Aug 29, 2023
22430a3
wip
pgherveou Aug 30, 2023
c6e1f49
add other xcm_methods
pgherveou Aug 30, 2023
bf66839
add benchmarks
pgherveou Aug 31, 2023
a348bd9
build fixes
pgherveou Aug 31, 2023
b2a9f4e
fix
pgherveou Aug 31, 2023
d20d6ca
fix post-rebase missing imports
pgherveou Sep 1, 2023
8388585
Revert "boilerplate type changes"
pgherveou Sep 1, 2023
4bae246
Use trait instead of tight coupling
pgherveou Sep 1, 2023
0675899
add mock_network setup
pgherveou Sep 1, 2023
2049b57
fixes
pgherveou Sep 4, 2023
be04741
fix clippy
pgherveou Sep 4, 2023
b7875ad
quick fixes
pgherveou Sep 4, 2023
c312b98
simplify
pgherveou Sep 4, 2023
5983dbd
move stuff to pallet_xcm_extension
pgherveou Sep 4, 2023
7484d32
fmt
pgherveou Sep 4, 2023
b40f92c
headr
pgherveou Sep 4, 2023
c3f7d40
missing headers
pgherveou Sep 4, 2023
a08e41b
fix missing comment
pgherveou Sep 4, 2023
376a6b3
fixes
pgherveou Sep 4, 2023
5b883d6
Merge branch 'master' into pg/xcm
pgherveou Sep 4, 2023
967616c
Merge branch 'master' into pg/xcm
pgherveou Sep 4, 2023
d2b5ba3
refactoring
pgherveou Sep 4, 2023
d7fe1bc
fix build
pgherveou Sep 4, 2023
c15adab
missing type in node/runtime
pgherveou Sep 5, 2023
e15c7eb
format cargo.toml
pgherveou Sep 5, 2023
971b167
more zepter fixes
pgherveou Sep 5, 2023
3dba8d1
fixes
pgherveou Sep 5, 2023
be1a46d
missing trait implementation
pgherveou Sep 5, 2023
a4d706c
fix tests
pgherveou Sep 5, 2023
b15ea88
fixes
pgherveou Sep 5, 2023
b938df4
fmt fix
pgherveou Sep 5, 2023
fcc37f5
zepter format
pgherveou Sep 5, 2023
9cc990f
fix doc links
pgherveou Sep 5, 2023
7ff220b
rm println!
pgherveou Sep 5, 2023
bdf0ae7
add tests comments
pgherveou Sep 5, 2023
14e1514
worst case
pgherveou Sep 5, 2023
e9d2cdf
simplify XCM
pgherveou Sep 14, 2023
c9f8f35
add docs
pgherveou Sep 14, 2023
151175b
Filter out transact calls
pgherveou Sep 21, 2023
43f38d2
fmt
pgherveou Sep 21, 2023
4583e03
move ensure to it's own function for benchmark
pgherveou Sep 21, 2023
ceb3fc8
fix error handling
pgherveou Sep 21, 2023
db7c479
doc fixes
pgherveou Sep 22, 2023
cd8281e
fix weight
pgherveou Sep 22, 2023
c004909
improve weight
pgherveou Sep 22, 2023
526abbd
XCMAdapter -> XcmAdapter
pgherveou Sep 25, 2023
0a98a89
XCM<T> -> Xcm<T>
pgherveou Sep 25, 2023
1d1f40a
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
e01cb2c
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
2c7735b
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
4e3de86
Update substrate/frame/contracts/src/xcm.rs
pgherveou Sep 25, 2023
e52f85f
s/xcm message/message
pgherveou Sep 25, 2023
d78ec47
typo
pgherveou Sep 25, 2023
435de45
fix build issues
pgherveou Sep 27, 2023
c4d87ff
fix fmt
pgherveou Sep 27, 2023
4363e6d
More doc fix changes
pgherveou Sep 27, 2023
ac39a50
Apply suggestions from code review
pgherveou Sep 29, 2023
0bf6e1a
address PR comments
pgherveou Sep 29, 2023
ddf485a
Add reentrency test
pgherveou Oct 9, 2023
975ef56
Simplify tests
pgherveou Oct 9, 2023
448c9d4
Apply suggestions from code review
pgherveou Oct 24, 2023
132e203
PR review comment
pgherveou Oct 24, 2023
7bf716d
Fix lint
pgherveou Oct 24, 2023
6a7a8bd
return proper error code
pgherveou Oct 24, 2023
8c1c118
Merge branch 'master' into pg/xcm
pgherveou Oct 24, 2023
06a5c9a
fix compilation issues after rebase
pgherveou Oct 24, 2023
b47f660
lint
pgherveou Oct 24, 2023
06cf121
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Oct 24, 2023
0949455
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
Oct 24, 2023
14fed0e
Update substrate/frame/contracts/src/tests/test_xcm.rs
pgherveou Oct 25, 2023
e694941
simplify mock_network
pgherveou Oct 25, 2023
72f15c1
fix return type in comment
pgherveou Oct 26, 2023
c8f39e7
Contracts expose pallet-xcm - tweaks (#2062)
pgherveou Oct 27, 2023
54e2803
Add copyright
pgherveou Oct 27, 2023
ce637dc
reuse QueryHandler
pgherveou Oct 29, 2023
582467d
Contracts: Add XCM traits to interface with contracts
pgherveou Oct 30, 2023
79535cb
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 30, 2023
0a02451
Update doc
pgherveou Oct 30, 2023
262e17c
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Oct 31, 2023
9413874
use Outcome return value for xcm_execute
pgherveou Oct 31, 2023
18c6bb4
Use outcome in controller
pgherveou Oct 31, 2023
b9b2ccc
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Oct 31, 2023
198d692
add docstring
pgherveou Oct 31, 2023
e3ce2e0
Event consistency
pgherveou Oct 31, 2023
6342962
Add more docs
pgherveou Oct 31, 2023
a2fde63
Update polkadot/xcm/xcm-executor/src/traits/controller.rs
pgherveou Oct 31, 2023
0ae8763
fix doc
pgherveou Oct 31, 2023
034150c
fix CI
pgherveou Oct 31, 2023
7848e2f
move to xcm-builder
pgherveou Nov 1, 2023
b7155b6
move to pallet-xcm
pgherveou Nov 1, 2023
34329e5
Update doc links
pgherveou Nov 1, 2023
07439dd
Merge branch 'master' into pg/xcm_contracts_update
pgherveou Nov 1, 2023
b37d169
wip
pgherveou Nov 1, 2023
de8f1a9
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Nov 1, 2023
7cd84a2
update xcm stuff
pgherveou Nov 1, 2023
8ac21da
Bench compile fix
pgherveou Nov 1, 2023
7ee5d08
add missing use
pgherveou Nov 2, 2023
e13b51b
Merge branch 'pg/xcm_contracts_update' into pg/xcm
pgherveou Nov 2, 2023
2359fa0
fix test
pgherveou Nov 2, 2023
41215d3
mock-network crate
pgherveou Nov 10, 2023
e515180
Merge branch 'master' into pg/xcm
pgherveou Nov 10, 2023
8b0f8ac
revert bad merge
pgherveou Nov 10, 2023
3526658
move fixtures files
pgherveou Nov 10, 2023
784f8df
rm pallet-xcm dep
pgherveou Nov 10, 2023
0b5517a
fix xcm deps
pgherveou Nov 10, 2023
7b3ad3d
fix tests
pgherveou Nov 10, 2023
0b4c840
fix lint
pgherveou Nov 10, 2023
80e0c53
fixes
pgherveou Nov 10, 2023
59d67a0
fix
pgherveou Nov 10, 2023
9a9d572
fix
pgherveou Nov 10, 2023
3adde14
fixed deps moved to pallet-contracts-mock-network
pgherveou Nov 14, 2023
c70aca5
Review https://github.com/paritytech/polkadot-sdk/pull/1248#discussio…
pgherveou Nov 14, 2023
5d63636
Review https://github.com/paritytech/polkadot-sdk/pull/1248#discussio…
pgherveou Nov 14, 2023
57b7ca5
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
10f22fb
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
162ad54
PR review https://github.com/paritytech/polkadot-sdk/pull/1248#discus…
pgherveou Nov 14, 2023
3a4a251
rm macro_export
pgherveou Nov 14, 2023
dab8314
Temporary remove xcm_query and xcm_take_response fns
pgherveou Nov 14, 2023
e3161c9
misc removed stuff from query
pgherveou Nov 14, 2023
4128aa6
fix doc
pgherveou Nov 14, 2023
f0df85b
rm more stuff from query & take_response
pgherveou Nov 14, 2023
b48a8f9
fmt
pgherveou Nov 14, 2023
7c72e24
Merge branch 'master' into pg/xcm
pgherveou Nov 14, 2023
b34e245
doc test
pgherveou Nov 14, 2023
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

27 changes: 27 additions & 0 deletions polkadot/xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ benchmarks! {
Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
}

new_query {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
}: {
Pallet::<T>::new_query(responder, timeout, match_querier);
}

take_response {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
let query_id = Pallet::<T>::new_query(responder, timeout, match_querier);
let infos = (0 .. xcm::v3::MaxPalletsInfo::get()).map(|_| PalletInfo::new(
1u32,
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
1u32,
0u32,
0u32,
).unwrap()).collect::<Vec<_>>();
Pallet::<T>::expect_response(query_id, Response::PalletsInfo(infos.try_into().unwrap()));

}: {
Pallet::<T>::take_response(query_id);
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext_with_balances(Vec::new()),
Expand Down
15 changes: 15 additions & 0 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ pub trait WeightInfo {
fn notify_target_migration_fail() -> Weight;
fn migrate_version_notify_targets() -> Weight;
fn migrate_and_notify_old_targets() -> Weight;
// TODO remove after benchmark are regenerated
fn new_query() -> Weight {
Weight::zero()
}
fn take_response() -> Weight {
Weight::zero()
}
}

/// fallback implementation
Expand Down Expand Up @@ -141,6 +148,14 @@ impl WeightInfo for TestWeightInfo {
fn migrate_and_notify_old_targets() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn new_query() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn take_response() -> Weight {
Weight::from_parts(100_000_000, 0)
}
}

#[frame_support::pallet]
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-executor/src/traits/on_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::Xcm;
use core::result;
use frame_support::pallet_prelude::{Get, TypeInfo};
use parity_scale_codec::{FullCodec, MaxEncodedLen};
use parity_scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use sp_arithmetic::traits::Zero;
use sp_std::fmt::Debug;
use xcm::latest::{
Expand Down Expand Up @@ -103,7 +103,7 @@ impl VersionChangeNotifier for () {
}

/// The possible state of an XCM query response.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
pub enum QueryResponseStatus<BlockNumber> {
/// The response has arrived, and includes the inner Response and the block number it arrived
/// at.
Expand Down
7 changes: 7 additions & 0 deletions substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ sp-io = { path = "../../primitives/io", default-features = false}
sp-runtime = { path = "../../primitives/runtime", default-features = false}
sp-std = { path = "../../primitives/std", default-features = false}

xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false}
xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor", default-features = false}
pallet-xcm = { path = "../../../polkadot/xcm/pallet-xcm", default-features = false}

Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these crates are going to move into their own repo (cc @KiChjang ), so that should partially address your concern.

I don't see how we could bring xcm features to SC without bringing in these dependencies though... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, makes sense.

Not my call, but I would strive to have things in the dep graph be correct before landing this PR. Else the slippery slope to a janky cluster of deps crossing boundaries will likely happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree you don't necessarily want to use xcm when using pallet-contracts, you might not even have access to it
Ideally we want contracts, at the pallet level, to allow xcm but not enforce knowing about it

It's good that you can disable the capability, but still relying on this dependencies sounds too much when I don't want to deal with xcm as a solochain developer for example

The only way to take this out of the dependencies would be to have a different crate, something like "xcm-powered-contracts", which is ugly. The other thing we could do is feature gate this, so at least some things are not even compiled if you don't want XCM. However, dependencies can't be defined per feature 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasoning is that even solo chain might eventually want to use xcm, to communicate messages over bridges for example. That's why we want xcm to be part of the config, rather than using other type of indirection like dispatching runtime call or building ad-hoc SC chain extension, which has been how team have interfaced with XCM so far.

We could feature gate everything but I think this is not necessary as the compiler should just strip pallet_xcm code if you use the default () noop trait.

Copy link
Member

@athei athei Oct 26, 2023

Choose a reason for hiding this comment

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

Yes XCM is not specific to being a parachain. It is a language to express intent. It will also be used for contract <-> runtime communication. In an ideal world it would also be used inside a transaction instead of the unstable encoded Call.

Hence there is no reason to jump though all these hoops and add all the complexity just to make it optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I initially I used tight coupling , but I think having an Xcm configuration trait provide a few advantage:

  • I find it a bit more readable to do T::Xcm::some_xcm_foo(..) rather than <T as pallet_xcm::Config>::xcm_foo(..)
  • You will need to replace all T:: by <T as Config> to get the pallet to compile
  • We can document the set of xcm operation we want to bring in through this trait
  • Even if the vision is to use Xcm for all chains, the upgrade path is slightly easier this way as they don't have to implement pallet_xcm::Config straight away.

Happy to update if you feel strongly that we should use tight coupling on the pallet.

[dev-dependencies]
array-bytes = "6.1"
assert_matches = "1"
Expand Down Expand Up @@ -90,6 +94,9 @@ std = [
"sp-std/std",
"wasm-instrument/std",
"wasmi/std",
"pallet-xcm/std",
"xcm/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
72 changes: 36 additions & 36 deletions substrate/frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
data: Vec<u8>,
) -> Result<Contract<T>, &'static str> {
let value = Pallet::<T>::min_balance();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
let salt = vec![0xff];
let addr = Contracts::<T>::contract_address(&caller, &module.hash, &data, &salt);

Expand Down Expand Up @@ -163,7 +163,7 @@ where

/// Set the balance of the contract to the supplied amount.
fn set_balance(&self, balance: BalanceOf<T>) {
T::Currency::set_balance(&self.account_id, balance);
<T as Config>::Currency::set_balance(&self.account_id, balance);
}

/// Returns `true` iff all storage entries related to code storage exist.
Expand Down Expand Up @@ -291,7 +291,7 @@ benchmarks! {
#[pov_mode = Measured]
v14_migration_step {
let account = account::<T::AccountId>("account", 0, 0);
T::Currency::set_balance(&account, caller_funding::<T>());
<T as Config>::Currency::set_balance(&account, caller_funding::<T>());
v14::store_dummy_code::<T, pallet_balances::Pallet<T>>(account);
let mut m = v14::Migration::<T, pallet_balances::Pallet<T>>::default();
}: {
Expand Down Expand Up @@ -406,21 +406,21 @@ benchmarks! {
let salt = vec![42u8; s as usize];
let value = Pallet::<T>::min_balance();
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::sized(c, Location::Call);
let origin = RawOrigin::Signed(caller.clone());
let addr = Contracts::<T>::contract_address(&caller, &hash, &input, &salt);
}: _(origin, value, Weight::MAX, None, code, input, salt)
verify {
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
let deposit = <T as Config>::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
// uploading the code reserves some balance in the callers account
let code_deposit = T::Currency::balance_on_hold(&HoldReason::CodeUploadDepositReserve.into(), &caller);
let code_deposit = <T as Config>::Currency::balance_on_hold(&HoldReason::CodeUploadDepositReserve.into(), &caller);
assert_eq!(
T::Currency::balance(&caller),
<T as Config>::Currency::balance(&caller),
caller_funding::<T>() - value - deposit - code_deposit - Pallet::<T>::min_balance(),
);
// contract has the full value
assert_eq!(T::Currency::balance(&addr), value + Pallet::<T>::min_balance());
assert_eq!(<T as Config>::Currency::balance(&addr), value + Pallet::<T>::min_balance());
}

// Instantiate uses a dummy contract constructor to measure the overhead of the instantiate.
Expand All @@ -434,21 +434,21 @@ benchmarks! {
let salt = vec![42u8; s as usize];
let value = Pallet::<T>::min_balance();
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::dummy();
let origin = RawOrigin::Signed(caller.clone());
let addr = Contracts::<T>::contract_address(&caller, &hash, &input, &salt);
Contracts::<T>::store_code_raw(code, caller.clone())?;
}: _(origin, value, Weight::MAX, None, hash, input, salt)
verify {
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
let deposit = <T as Config>::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &addr);
// value was removed from the caller
assert_eq!(
T::Currency::balance(&caller),
<T as Config>::Currency::balance(&caller),
caller_funding::<T>() - value - deposit - Pallet::<T>::min_balance(),
);
// contract has the full value
assert_eq!(T::Currency::balance(&addr), value + Pallet::<T>::min_balance());
assert_eq!(<T as Config>::Currency::balance(&addr), value + Pallet::<T>::min_balance());
}

// We just call a dummy contract to measure the overhead of the call extrinsic.
Expand All @@ -467,17 +467,17 @@ benchmarks! {
let value = Pallet::<T>::min_balance();
let origin = RawOrigin::Signed(instance.caller.clone());
let callee = instance.addr.clone();
let before = T::Currency::balance(&instance.account_id);
let before = <T as Config>::Currency::balance(&instance.account_id);
}: _(origin, callee, value, Weight::MAX, None, data)
verify {
let deposit = T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id);
let deposit = <T as Config>::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id);
// value and value transferred via call should be removed from the caller
assert_eq!(
T::Currency::balance(&instance.caller),
<T as Config>::Currency::balance(&instance.caller),
caller_funding::<T>() - instance.value - value - deposit - Pallet::<T>::min_balance(),
);
// contract should have received the value
assert_eq!(T::Currency::balance(&instance.account_id), before + value);
assert_eq!(<T as Config>::Currency::balance(&instance.account_id), before + value);
// contract should still exist
instance.info()?;
}
Expand All @@ -489,13 +489,13 @@ benchmarks! {
upload_code {
let c in 0 .. T::MaxCodeLen::get();
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::sized(c, Location::Call);
let origin = RawOrigin::Signed(caller.clone());
}: _(origin, code, None, Determinism::Enforced)
verify {
// uploading the code reserves some balance in the callers account
assert!(T::Currency::total_balance_on_hold(&caller) > 0u32.into());
assert!(<T as Config>::Currency::total_balance_on_hold(&caller) > 0u32.into());
assert!(<Contract<T>>::code_exists(&hash));
}

Expand All @@ -505,17 +505,17 @@ benchmarks! {
#[pov_mode = Measured]
remove_code {
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::dummy();
let origin = RawOrigin::Signed(caller.clone());
let uploaded = <Contracts<T>>::bare_upload_code(caller.clone(), code, None, Determinism::Enforced)?;
assert_eq!(uploaded.code_hash, hash);
assert_eq!(uploaded.deposit, T::Currency::total_balance_on_hold(&caller));
assert_eq!(uploaded.deposit, <T as Config>::Currency::total_balance_on_hold(&caller));
assert!(<Contract<T>>::code_exists(&hash));
}: _(origin, hash)
verify {
// removing the code should have unreserved the deposit
assert_eq!(T::Currency::total_balance_on_hold(&caller), 0u32.into());
assert_eq!(<T as Config>::Currency::total_balance_on_hold(&caller), 0u32.into());
assert!(<Contract<T>>::code_removed(&hash));
}

Expand Down Expand Up @@ -889,7 +889,7 @@ benchmarks! {
let beneficiary_len = beneficiary_bytes.len();
let caller = whitelisted_caller();

T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());

// Maximize the delegate_dependencies to account for the worst-case scenario.
let code_hashes = (0..T::MaxDelegateDependencies::get())
Expand Down Expand Up @@ -941,15 +941,15 @@ benchmarks! {
});
let instance = Contract::<T>::new(code, vec![])?;
let origin = RawOrigin::Signed(instance.caller.clone());
assert_eq!(T::Currency::total_balance(&beneficiary), 0u32.into());
assert_eq!(T::Currency::balance(&instance.account_id), Pallet::<T>::min_balance() * 2u32.into());
assert_ne!(T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
assert_eq!(<T as Config>::Currency::total_balance(&beneficiary), 0u32.into());
assert_eq!(<T as Config>::Currency::balance(&instance.account_id), Pallet::<T>::min_balance() * 2u32.into());
assert_ne!(<T as Config>::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
}: call(origin, instance.addr.clone(), 0u32.into(), Weight::MAX, None, vec![])
verify {
if r > 0 {
assert_eq!(T::Currency::total_balance(&instance.account_id), 0u32.into());
assert_eq!(T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
assert_eq!(T::Currency::total_balance(&beneficiary), Pallet::<T>::min_balance() * 2u32.into());
assert_eq!(<T as Config>::Currency::total_balance(&instance.account_id), 0u32.into());
assert_eq!(<T as Config>::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &instance.account_id), 0u32.into());
assert_eq!(<T as Config>::Currency::total_balance(&beneficiary), Pallet::<T>::min_balance() * 2u32.into());
}
}

Expand Down Expand Up @@ -1718,12 +1718,12 @@ benchmarks! {
instance.set_balance(value * (r + 1).into());
let origin = RawOrigin::Signed(instance.caller.clone());
for account in &accounts {
assert_eq!(T::Currency::total_balance(account), 0u32.into());
assert_eq!(<T as Config>::Currency::total_balance(account), 0u32.into());
}
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
verify {
for account in &accounts {
assert_eq!(T::Currency::total_balance(account), value);
assert_eq!(<T as Config>::Currency::total_balance(account), value);
}
}

Expand Down Expand Up @@ -1812,7 +1812,7 @@ benchmarks! {
.map(|i| {
let code = WasmModule::<T>::dummy_with_bytes(i);
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(code.code, caller)?;
Ok(code.hash)
})
Expand Down Expand Up @@ -1934,7 +1934,7 @@ benchmarks! {
.. Default::default()
});
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(code.code, caller)?;
Ok(code.hash)
})
Expand Down Expand Up @@ -2040,7 +2040,7 @@ benchmarks! {
let hash_bytes = callee_code.hash.encode();
let hash_len = hash_bytes.len();
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(callee_code.code, caller)?;
let value: BalanceOf<T> = t.into();
let value_bytes = value.encode();
Expand Down Expand Up @@ -2384,7 +2384,7 @@ benchmarks! {
.map(|i| {
let new_code = WasmModule::<T>::dummy_with_bytes(i);
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(new_code.code, caller)?;
Ok(new_code.hash)
})
Expand Down Expand Up @@ -2427,7 +2427,7 @@ benchmarks! {
.map(|i| {
let new_code = WasmModule::<T>::dummy_with_bytes(65 + i);
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(new_code.code, caller)?;
Ok(new_code.hash)
})
Expand Down Expand Up @@ -2465,7 +2465,7 @@ benchmarks! {
.map(|i| {
let new_code = WasmModule::<T>::dummy_with_bytes(65 + i);
let caller = whitelisted_caller();
T::Currency::set_balance(&caller, caller_funding::<T>());
<T as Config>::Currency::set_balance(&caller, caller_funding::<T>());
Contracts::<T>::store_code_raw(new_code.code, caller)?;
Ok(new_code.hash)
})
Expand Down
Loading
Loading