Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c04f89a
Parse backend type
pmikolajczyk41 Aug 2, 2023
c13ceca
Config tests
pmikolajczyk41 Aug 2, 2023
816030b
Extract client building
pmikolajczyk41 Aug 2, 2023
96c124f
OCD
pmikolajczyk41 Aug 2, 2023
d2abb06
CHANGELOG.md
pmikolajczyk41 Aug 4, 2023
316bf58
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/e2e-…
pmikolajczyk41 Aug 4, 2023
37f8d09
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/e2e-…
pmikolajczyk41 Aug 7, 2023
f679f73
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/e2e-…
pmikolajczyk41 Aug 16, 2023
f8e295a
Add drink dependency, fix with wasm-instrument
pmikolajczyk41 Aug 17, 2023
7be1f3a
ChainApi
pmikolajczyk41 Aug 18, 2023
42484ff
Instantiate
pmikolajczyk41 Aug 18, 2023
06cbc9b
Calling
pmikolajczyk41 Aug 18, 2023
c454db3
Upload
pmikolajczyk41 Aug 18, 2023
b21fc27
Use all arguments
pmikolajczyk41 Aug 18, 2023
ec3936e
Build client in macro
pmikolajczyk41 Aug 18, 2023
17bf359
fmt, implement e2e backend
pmikolajczyk41 Aug 18, 2023
dcc746d
remove actor types
pmikolajczyk41 Aug 18, 2023
624d20f
convert accounts and hashes
pmikolajczyk41 Aug 22, 2023
2b67dc8
get rid of session
pmikolajczyk41 Aug 23, 2023
7f9b764
add dedicated example
pmikolajczyk41 Aug 23, 2023
158dd64
example working
pmikolajczyk41 Aug 23, 2023
97ac62b
clean a bit
pmikolajczyk41 Aug 23, 2023
20a36ca
Merge remote-tracking branch 'origin/master' into pmikolajczyk41/e2e-…
pmikolajczyk41 Aug 23, 2023
96f647f
merging cleanup
pmikolajczyk41 Aug 23, 2023
15aaa48
use published drink
pmikolajczyk41 Aug 23, 2023
f416edc
Review
pmikolajczyk41 Aug 24, 2023
04bb5e9
Add DRink! as valid word
pmikolajczyk41 Aug 24, 2023
ea738c2
Give it up
pmikolajczyk41 Aug 24, 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
Prev Previous commit
Next Next commit
convert accounts and hashes
  • Loading branch information
pmikolajczyk41 committed Aug 22, 2023
commit 624d20f1b5cc83511f06f20d0f77c8058c9554ff
4 changes: 2 additions & 2 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait ChainBackend {
/// Returns the balance of `actor`.
async fn balance(
&mut self,
actor: Self::AccountId,
account: Self::AccountId,
) -> Result<Self::Balance, Self::Error>;

/// Executes a runtime call `call_name` for the `pallet_name`.
Expand All @@ -75,7 +75,7 @@ pub trait ChainBackend {
/// events that are associated with this transaction.
async fn runtime_call<'a>(
&mut self,
actor: &Keypair,
origin: &Keypair,
pallet_name: &'a str,
call_name: &'a str,
call_data: Vec<Value>,
Expand Down
65 changes: 43 additions & 22 deletions crates/e2e/src/drink_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ use drink::{
use ink_env::Environment;
use jsonrpsee::core::async_trait;
use pallet_contracts_primitives::{
CodeUploadReturnValue,
ContractInstantiateResult,
ContractResult,
InstantiateReturnValue,
};
use scale::{
Decode,
Expand All @@ -35,23 +37,24 @@ use sp_core::{
crypto::AccountId32,
sr25519::Pair,
Pair as _,
H256,
};
use std::{
collections::BTreeMap,
marker::PhantomData,
path::PathBuf,
};
use subxt::dynamic::Value;
use subxt_signer::sr25519::Keypair;

pub struct Client {
pub struct Client<AccountId, Hash> {
session: Session<MinimalRuntime>,
contracts: BTreeMap<String, PathBuf>,
_phantom: PhantomData<(AccountId, Hash)>,
}

unsafe impl Send for Client {}
unsafe impl<AccountId, Hash> Send for Client<AccountId, Hash> {}

impl Client {
impl<AccountId, Hash> Client<AccountId, Hash> {
pub fn new<'a>(contracts: impl IntoIterator<Item = &'a str>) -> Self {
// todo: extract to a common place
let contracts = contracts
Expand All @@ -68,6 +71,7 @@ impl Client {
Self {
session: Session::new(None).expect("Failed to create session"),
contracts,
_phantom: Default::default(),
}
}

Expand Down Expand Up @@ -106,8 +110,8 @@ impl Client {
}

#[async_trait]
impl ChainBackend for Client {
type AccountId = AccountId32;
impl<AccountId: AsRef<[u8; 32]> + Send, Hash> ChainBackend for Client<AccountId, Hash> {
type AccountId = AccountId;
type Balance = u128;
type Error = ();
type EventLog = ();
Expand All @@ -117,7 +121,6 @@ impl ChainBackend for Client {
_origin: &Keypair,
amount: Self::Balance,
) -> Keypair {
// todo: extract to a common place
let (pair, seed) = Pair::generate();

self.session
Expand All @@ -129,14 +132,15 @@ impl ChainBackend for Client {

async fn balance(
&mut self,
actor: Self::AccountId,
account: Self::AccountId,
) -> Result<Self::Balance, Self::Error> {
Ok(self.session.chain_api().balance(&actor))
let account = AccountId32::new(*account.as_ref());
Ok(self.session.chain_api().balance(&account))
}

async fn runtime_call<'a>(
&mut self,
_actor: &Keypair,
_origin: &Keypair,
_pallet_name: &'a str,
_call_name: &'a str,
_call_data: Vec<Value>,
Expand All @@ -146,8 +150,11 @@ impl ChainBackend for Client {
}

#[async_trait]
impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'static>
ContractsBackend<E> for Client
impl<
AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>,
Hash: From<[u8; 32]>,
E: Environment<AccountId = AccountId, Balance = u128, Hash = Hash> + 'static,
> ContractsBackend<E> for Client<AccountId, Hash>
{
type Error = ();
type EventLog = ();
Expand All @@ -172,20 +179,27 @@ impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'sta
DEFAULT_GAS_LIMIT,
storage_deposit_limit,
);
let account_id = self
.session
.last_deploy_return()
.expect("We have just deployed a contract, so we should have its address");
let account_id_raw = *<AccountId32 as AsRef<[u8; 32]>>::as_ref(
&self.session.last_deploy_return().expect(
"We have just deployed a contract, so we should have its address",
),
);
let account_id = AccountId::from(account_id_raw);

Ok(InstantiationResult {
account_id,
account_id: account_id.clone(),
// We need type remapping here because of the different `EventRecord` types.
dry_run: ContractInstantiateResult {
gas_consumed: result.gas_consumed,
gas_required: result.gas_required,
storage_deposit: result.storage_deposit,
debug_message: result.debug_message,
result: result.result,
result: result.result.map(|r| {
InstantiateReturnValue {
result: r.result,
account_id,
}
}),
events: None,
},
events: (), // todo: https://github.com/Cardinal-Cryptography/drink/issues/32
Expand Down Expand Up @@ -224,8 +238,11 @@ impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'sta
};

Ok(UploadResult {
code_hash: result.code_hash,
dry_run: Ok(result),
code_hash: result.code_hash.0.into(),
dry_run: Ok(CodeUploadReturnValue {
code_hash: result.code_hash.0.into(),
deposit: result.deposit,
}),
events: (),
})
}
Expand All @@ -242,6 +259,7 @@ impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'sta
{
let account_id = message.clone().params().callee().clone();
let exec_input = Encode::encode(message.clone().params().exec_input());
let account_id = (*account_id.as_ref()).into();

let result = self.session.contracts_api().call_contract(
account_id,
Expand Down Expand Up @@ -283,8 +301,11 @@ impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'sta
}
}

impl<E: Environment<AccountId = AccountId32, Balance = u128, Hash = H256> + 'static>
E2EBackend<E> for Client
impl<
AccountId: Clone + Send + Sync + From<[u8; 32]> + AsRef<[u8; 32]>,
Hash: From<[u8; 32]>,
E: Environment<AccountId = AccountId, Balance = u128, Hash = Hash> + 'static,
> E2EBackend<E> for Client<AccountId, Hash>
{
}

Expand Down
10 changes: 5 additions & 5 deletions crates/e2e/src/subxt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ where

async fn balance(
&mut self,
actor: Self::AccountId,
account: Self::AccountId,
) -> Result<Self::Balance, Self::Error> {
let account_addr = subxt::dynamic::storage(
"System",
"Account",
vec![
// Something that encodes to an AccountId32 is what we need for the map
// key here:
Value::from_bytes(&actor),
Value::from_bytes(&account),
],
);

Expand Down Expand Up @@ -439,20 +439,20 @@ where
Error::<E>::Balance(format!("{balance:?} failed to convert from u128"))
})?;

log_info(&format!("balance of contract {actor:?} is {balance:?}"));
log_info(&format!("balance of contract {account:?} is {balance:?}"));
Ok(balance)
}

async fn runtime_call<'a>(
&mut self,
actor: &Keypair,
origin: &Keypair,
pallet_name: &'a str,
call_name: &'a str,
call_data: Vec<Value>,
) -> Result<Self::EventLog, Self::Error> {
let tx_events = self
.api
.runtime_call(actor, pallet_name, call_name, call_data)
.runtime_call(origin, pallet_name, call_name, call_data)
.await;

for evt in tx_events.iter() {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contract-transfer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub mod give_me {

type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
#[ink_e2e::test(backend = "runtime-only")]
async fn e2e_sending_value_to_give_me_must_fail<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
Expand Down