diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e8c8a2fd0b..b955f35e9b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fail when decoding from storage and not all bytes consumed - [#1897](https://github.com/paritytech/ink/pull/1897) - [E2E] resolve DispatchError error details for dry-runs - [#1944](https://github.com/paritytech/ink/pull/1994) +- [E2E] update to new `drink` API - [#2005](https://github.com/paritytech/ink/pull/2005) ### Added - Linter: `storage_never_freed` lint - [#1932](https://github.com/paritytech/ink/pull/1932) diff --git a/Cargo.toml b/Cargo.toml index 79d425a3a2c..aca40e0afa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ cfg-if = { version = "1.0" } contract-build = { version = "3.2.0" } darling = { version = "0.20.3" } derive_more = { version = "0.99.17", default-features = false } -drink = { version = "=0.6.0" } +drink = { version = "=0.8.2" } either = { version = "1.5", default-features = false } funty = { version = "2.0.0" } heck = { version = "0.4.0" } diff --git a/crates/e2e/src/backend.rs b/crates/e2e/src/backend.rs index febb88ac6a1..79d3a419b63 100644 --- a/crates/e2e/src/backend.rs +++ b/crates/e2e/src/backend.rs @@ -67,8 +67,8 @@ pub trait ChainBackend { amount: Self::Balance, ) -> Keypair; - /// Returns the balance of `actor`. - async fn balance( + /// Returns the free balance of `account`. + async fn free_balance( &mut self, account: Self::AccountId, ) -> Result; diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index 06b4552285e..0f2ed54a166 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -34,12 +34,15 @@ use crate::{ UploadResult, }; use drink::{ - chain_api::{ - ChainApi, - RuntimeCall, + frame_support::traits::fungible::Inspect, + pallet_balances, + pallet_contracts, + runtime::{ + AccountIdFor, + Runtime as RuntimeT, }, - contract_api::ContractApi, - runtime::Runtime as RuntimeT, + BalanceOf, + RuntimeCall, Sandbox, Weight, DEFAULT_GAS_LIMIT, @@ -70,6 +73,9 @@ use subxt::{ tx::TxPayload, }; use subxt_signer::sr25519::Keypair; + +type ContractsBalanceOf = + <::Currency as Inspect>>::Balance; pub struct Client { sandbox: Sandbox, contracts: ContractsRegistry, @@ -83,12 +89,11 @@ unsafe impl Send for Client { } - -type RuntimeAccountId = ::AccountId; - -impl Client +impl Client where - RuntimeAccountId: From<[u8; 32]>, + Runtime: RuntimeT + pallet_balances::Config + pallet_contracts::Config, + AccountIdFor: From<[u8; 32]>, + BalanceOf: From, { pub fn new>(contracts: impl IntoIterator) -> Self { let mut sandbox = Sandbox::new().expect("Failed to initialize Drink! sandbox"); @@ -117,19 +122,22 @@ where .map(|kp| kp.public_key().0) .map(From::from); for account in accounts.into_iter() { - sandbox.add_tokens(account, TOKENS); + sandbox + .mint_into(account, TOKENS.into()) + .unwrap_or_else(|_| panic!("Failed to mint {} tokens", TOKENS)); } } } #[async_trait] -impl + Send, Hash, Runtime: RuntimeT> ChainBackend +impl + Send, Hash, Runtime> ChainBackend for Client where - RuntimeAccountId: From<[u8; 32]>, + Runtime: RuntimeT + pallet_balances::Config, + AccountIdFor: From<[u8; 32]>, { type AccountId = AccountId; - type Balance = u128; + type Balance = BalanceOf; type Error = DrinkErr; type EventLog = (); @@ -140,17 +148,19 @@ where ) -> Keypair { let (pair, seed) = Pair::generate(); - self.sandbox.add_tokens(pair.public().0.into(), amount); + self.sandbox + .mint_into(pair.public().0.into(), amount) + .expect("Failed to mint tokens"); Keypair::from_seed(seed).expect("Failed to create keypair") } - async fn balance( + async fn free_balance( &mut self, account: Self::AccountId, ) -> Result { - let account = RuntimeAccountId::::from(*account.as_ref()); - Ok(self.sandbox.balance(&account)) + let account = AccountIdFor::::from(*account.as_ref()); + Ok(self.sandbox.free_balance(&account)) } async fn runtime_call<'a>( @@ -199,11 +209,16 @@ where impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, Hash: Copy + From<[u8; 32]>, - Runtime: RuntimeT, - E: Environment + 'static, + Runtime: RuntimeT + pallet_balances::Config + pallet_contracts::Config, + E: Environment< + AccountId = AccountId, + Balance = ContractsBalanceOf, + Hash = Hash, + > + 'static, > BuilderClient for Client where - RuntimeAccountId: From<[u8; 32]> + AsRef<[u8; 32]>, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, + ContractsBalanceOf: Send + Sync, { async fn bare_instantiate( &mut self, @@ -300,6 +315,7 @@ where code, keypair_to_account(caller), storage_deposit_limit, + pallet_contracts::Determinism::Enforced, ) { Ok(result) => result, Err(err) => { @@ -351,6 +367,7 @@ where keypair_to_account(caller), DEFAULT_GAS_LIMIT, storage_deposit_limit, + pallet_contracts::Determinism::Enforced, ) .result .is_err() @@ -383,6 +400,7 @@ where keypair_to_account(caller), DEFAULT_GAS_LIMIT, storage_deposit_limit, + pallet_contracts::Determinism::Enforced, ) }); Ok(CallDryRunResult { @@ -402,11 +420,16 @@ where impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, Hash: Copy + From<[u8; 32]>, - Runtime: RuntimeT, - E: Environment + 'static, + Runtime: RuntimeT + pallet_balances::Config + pallet_contracts::Config, + E: Environment< + AccountId = AccountId, + Balance = ContractsBalanceOf, + Hash = Hash, + > + 'static, > E2EBackend for Client where - RuntimeAccountId: From<[u8; 32]> + AsRef<[u8; 32]>, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, + ContractsBalanceOf: Send + Sync, { } @@ -418,11 +441,15 @@ fn keypair_to_account>(keypair: &Keypair) -> AccountId impl< AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>, Hash: Copy + From<[u8; 32]>, - Runtime: RuntimeT, - E: Environment + 'static, + Runtime: RuntimeT + pallet_balances::Config + pallet_contracts::Config, + E: Environment< + AccountId = AccountId, + Balance = ContractsBalanceOf, + Hash = Hash, + > + 'static, > ContractsBackend for Client where - RuntimeAccountId: From<[u8; 32]> + AsRef<[u8; 32]>, + AccountIdFor: From<[u8; 32]> + AsRef<[u8; 32]>, { type Error = DrinkErr; type EventLog = (); diff --git a/crates/e2e/src/subxt_client.rs b/crates/e2e/src/subxt_client.rs index cb787f085bc..f887ae0bfc3 100644 --- a/crates/e2e/src/subxt_client.rs +++ b/crates/e2e/src/subxt_client.rs @@ -371,7 +371,7 @@ where keypair } - async fn balance( + async fn free_balance( &mut self, account: Self::AccountId, ) -> Result { diff --git a/integration-tests/call-runtime/lib.rs b/integration-tests/call-runtime/lib.rs index ce2679575a9..b655f13adf4 100644 --- a/integration-tests/call-runtime/lib.rs +++ b/integration-tests/call-runtime/lib.rs @@ -167,11 +167,11 @@ mod runtime_call { let receiver: AccountId = default_accounts::().bob; let contract_balance_before = client - .balance(contract.account_id) + .free_balance(contract.account_id) .await .expect("Failed to get account balance"); let receiver_balance_before = client - .balance(receiver) + .free_balance(receiver) .await .expect("Failed to get account balance"); @@ -189,11 +189,11 @@ mod runtime_call { // then let contract_balance_after = client - .balance(contract.account_id) + .free_balance(contract.account_id) .await .expect("Failed to get account balance"); let receiver_balance_after = client - .balance(receiver) + .free_balance(receiver) .await .expect("Failed to get account balance"); diff --git a/integration-tests/contract-transfer/lib.rs b/integration-tests/contract-transfer/lib.rs index aabecee2f50..7fab52d44bc 100644 --- a/integration-tests/contract-transfer/lib.rs +++ b/integration-tests/contract-transfer/lib.rs @@ -236,7 +236,7 @@ pub mod give_me { let mut call = contract.call::(); let balance_before: Balance = client - .balance(contract.account_id.clone()) + .free_balance(contract.account_id.clone()) .await .expect("getting balance failed"); @@ -253,7 +253,7 @@ pub mod give_me { assert!(call_res.debug_message().contains("requested value: 120\n")); let balance_after: Balance = client - .balance(contract.account_id.clone()) + .free_balance(contract.account_id.clone()) .await .expect("getting balance failed"); assert_eq!(balance_before - balance_after, 120);