Skip to content

Commit

Permalink
[ink_e2e] housekeeping (#1524)
Browse files Browse the repository at this point in the history
* Remove unused stuff

* Remove redundant mutable from signer arg

* Fmt examples
  • Loading branch information
ascjones authored Nov 30, 2022
1 parent 40e872a commit fc543da
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 102 deletions.
32 changes: 5 additions & 27 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use super::{
ContractExecResult,
ContractInstantiateResult,
ContractsApi,
InkMessage,
Signer,
};
use contract_metadata::ContractMetadata;
Expand All @@ -62,27 +61,6 @@ use subxt::{
tx::ExtrinsicParams,
};

/// An encoded `#[ink(message)]`.
#[derive(Clone)]
pub struct EncodedMessage(Vec<u8>);

impl EncodedMessage {
fn new<M: InkMessage>(call: &M) -> Self {
let mut call_data = M::SELECTOR.to_vec();
<M as scale::Encode>::encode_to(call, &mut call_data);
Self(call_data)
}
}

impl<M> From<M> for EncodedMessage
where
M: InkMessage,
{
fn from(msg: M) -> Self {
EncodedMessage::new(&msg)
}
}

/// Result of a contract instantiation.
pub struct InstantiationResult<C: subxt::Config, E: Environment> {
/// The account id at which the contract was instantiated.
Expand Down Expand Up @@ -341,7 +319,7 @@ where
pub async fn instantiate<Args, R>(
&mut self,
contract_name: &str,
signer: &mut Signer<C>,
signer: &Signer<C>,
constructor: CreateBuilderPartial<E, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand Down Expand Up @@ -396,7 +374,7 @@ where
/// Executes an `instantiate_with_code` call and captures the resulting events.
async fn exec_instantiate<Args, R>(
&mut self,
signer: &mut Signer<C>,
signer: &Signer<C>,
code: Vec<u8>,
constructor: CreateBuilderPartial<E, Args, R>,
value: E::Balance,
Expand Down Expand Up @@ -513,7 +491,7 @@ where
pub async fn upload(
&mut self,
contract_name: &str,
signer: &mut Signer<C>,
signer: &Signer<C>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<C, E>, Error<C, E>> {
let contract_metadata = self
Expand All @@ -531,7 +509,7 @@ where
/// Executes an `upload` call and captures the resulting events.
pub async fn exec_upload(
&mut self,
signer: &mut Signer<C>,
signer: &Signer<C>,
code: Vec<u8>,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<C, E>, Error<C, E>> {
Expand Down Expand Up @@ -611,7 +589,7 @@ where
/// contains all events that are associated with this transaction.
pub async fn call<RetType>(
&mut self,
signer: &mut Signer<C>,
signer: &Signer<C>,
message: Message<E, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
Expand Down
21 changes: 0 additions & 21 deletions crates/e2e/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,6 @@ pub type PolkadotConfig = subxt::config::WithExtrinsicParams<
/// cryptography.
pub type Signer<C> = PairSigner<C, sr25519::Pair>;

/// Trait for contract constructors.
// TODO(#1421) Merge this with `InkMessage` to be just `InkSelector`. Requires forking `smart-bench-macro`.
pub trait InkConstructor: scale::Encode {
/// Return type of the constructor.
type ReturnType;
/// An ink! selector consists of four bytes.
const SELECTOR: [u8; 4];
/// Path to the contract bundle.
const CONTRACT_PATH: &'static str;
}

/// Trait for contract messages.
pub trait InkMessage: scale::Encode {
/// Return type of the message.
type ReturnType;
/// An ink! selector consists of four bytes.
const SELECTOR: [u8; 4];
/// Path to the contract bundle.
const CONTRACT_PATH: &'static str;
}

/// We use this to only initialize `env_logger` once.
pub static INIT: Once = Once::new();

Expand Down
8 changes: 4 additions & 4 deletions examples/contract-transfer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub mod give_me {
let contract_acc_id = client
.instantiate(
"contract_transfer",
&mut ink_e2e::alice(),
&ink_e2e::alice(),
constructor,
1000,
None,
Expand All @@ -207,7 +207,7 @@ pub mod give_me {
let transfer = ink_e2e::build_message::<GiveMeRef>(contract_acc_id)
.call(|contract| contract.give_me(120));

let call_res = client.call(&mut ink_e2e::bob(), transfer, 10, None).await;
let call_res = client.call(&ink_e2e::bob(), transfer, 10, None).await;

// then
assert!(call_res.is_err());
Expand All @@ -231,7 +231,7 @@ pub mod give_me {
let contract_acc_id = client
.instantiate(
"contract_transfer",
&mut ink_e2e::bob(),
&ink_e2e::bob(),
constructor,
1337,
None,
Expand All @@ -249,7 +249,7 @@ pub mod give_me {
.call(|contract| contract.give_me(120));

let call_res = client
.call(&mut ink_e2e::eve(), transfer, 0, None)
.call(&ink_e2e::eve(), transfer, 0, None)
.await
.expect("call failed");

Expand Down
20 changes: 10 additions & 10 deletions examples/delegator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@ mod delegator {
async fn e2e_delegator(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
// given
let accumulator_hash = client
.upload("accumulator", &mut ink_e2e::alice(), None)
.upload("accumulator", &ink_e2e::alice(), None)
.await
.expect("uploading `accumulator` failed")
.code_hash;

let adder_hash = client
.upload("adder", &mut ink_e2e::alice(), None)
.upload("adder", &ink_e2e::alice(), None)
.await
.expect("uploading `adder` failed")
.code_hash;

let subber_hash = client
.upload("subber", &mut ink_e2e::alice(), None)
.upload("subber", &ink_e2e::alice(), None)
.await
.expect("uploading `subber` failed")
.code_hash;
Expand All @@ -162,7 +162,7 @@ mod delegator {
);

let delegator_acc_id = client
.instantiate("delegator", &mut ink_e2e::alice(), constructor, 0, None)
.instantiate("delegator", &ink_e2e::alice(), constructor, 0, None)
.await
.expect("instantiate failed")
.account_id;
Expand All @@ -171,7 +171,7 @@ mod delegator {
let get = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.get());
let value = client
.call(&mut ink_e2e::bob(), get, 0, None)
.call(&ink_e2e::bob(), get, 0, None)
.await
.expect("calling `get` failed")
.value
Expand All @@ -180,15 +180,15 @@ mod delegator {
let change = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.change(6));
let _ = client
.call(&mut ink_e2e::bob(), change, 0, None)
.call(&ink_e2e::bob(), change, 0, None)
.await
.expect("calling `change` failed");

// then
let get = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.get());
let value = client
.call(&mut ink_e2e::bob(), get, 0, None)
.call(&ink_e2e::bob(), get, 0, None)
.await
.expect("calling `get` failed")
.value
Expand All @@ -199,21 +199,21 @@ mod delegator {
let switch = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.switch());
let _ = client
.call(&mut ink_e2e::bob(), switch, 0, None)
.call(&ink_e2e::bob(), switch, 0, None)
.await
.expect("calling `switch` failed");
let change = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.change(3));
let _ = client
.call(&mut ink_e2e::bob(), change, 0, None)
.call(&ink_e2e::bob(), change, 0, None)
.await
.expect("calling `change` failed");

// then
let get = build_message::<DelegatorRef>(delegator_acc_id.clone())
.call(|contract| contract.get());
let value = client
.call(&mut ink_e2e::bob(), get, 0, None)
.call(&ink_e2e::bob(), get, 0, None)
.await
.expect("calling `get` failed")
.value
Expand Down
28 changes: 11 additions & 17 deletions examples/lang-err-integration-tests/call-builder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,7 @@ mod call_builder {
) -> E2EResult<()> {
let constructor = CallBuilderTestRef::new();
let contract_acc_id = client
.instantiate(
"call_builder",
&mut ink_e2e::charlie(),
constructor,
0,
None,
)
.instantiate("call_builder", &ink_e2e::charlie(), constructor, 0, None)
.await
.expect("instantiate failed")
.account_id;
Expand All @@ -114,7 +108,7 @@ mod call_builder {
let flipper_acc_id = client
.instantiate(
"integration_flipper",
&mut ink_e2e::charlie(),
&ink_e2e::charlie(),
flipper_constructor,
0,
None,
Expand All @@ -126,7 +120,7 @@ mod call_builder {
let flipper_get = build_message::<FlipperRef>(flipper_acc_id)
.call(|contract| contract.get());
let get_call_result = client
.call(&mut ink_e2e::charlie(), flipper_get, 0, None)
.call(&ink_e2e::charlie(), flipper_get, 0, None)
.await
.expect("Calling `flipper::get` failed");
let initial_value = get_call_result
Expand All @@ -137,7 +131,7 @@ mod call_builder {
let call = build_message::<CallBuilderTestRef>(contract_acc_id)
.call(|contract| contract.call(flipper_acc_id, invalid_selector));
let call_result = client
.call(&mut ink_e2e::charlie(), call, 0, None)
.call(&ink_e2e::charlie(), call, 0, None)
.await
.expect("Calling `call_builder::call` failed");

Expand All @@ -153,7 +147,7 @@ mod call_builder {
let flipper_get = build_message::<FlipperRef>(flipper_acc_id)
.call(|contract| contract.get());
let get_call_result = client
.call(&mut ink_e2e::charlie(), flipper_get, 0, None)
.call(&ink_e2e::charlie(), flipper_get, 0, None)
.await
.expect("Calling `flipper::get` failed");
let flipped_value = get_call_result
Expand All @@ -170,13 +164,13 @@ mod call_builder {
) -> E2EResult<()> {
let constructor = CallBuilderTestRef::new();
let contract_acc_id = client
.instantiate("call_builder", &mut ink_e2e::dave(), constructor, 0, None)
.instantiate("call_builder", &ink_e2e::dave(), constructor, 0, None)
.await
.expect("instantiate failed")
.account_id;

let code_hash = client
.upload("constructors_return_value", &mut ink_e2e::dave(), None)
.upload("constructors_return_value", &ink_e2e::dave(), None)
.await
.expect("upload `constructors_return_value` failed")
.code_hash;
Expand All @@ -187,7 +181,7 @@ mod call_builder {
contract.call_instantiate(code_hash, new_selector, true)
});
let call_result = client
.call(&mut ink_e2e::dave(), call, 0, None)
.call(&ink_e2e::dave(), call, 0, None)
.await
.expect("Client failed to call `call_builder::call_instantiate`.")
.value
Expand All @@ -207,13 +201,13 @@ mod call_builder {
) -> E2EResult<()> {
let constructor = CallBuilderTestRef::new();
let contract_acc_id = client
.instantiate("call_builder", &mut ink_e2e::eve(), constructor, 0, None)
.instantiate("call_builder", &ink_e2e::eve(), constructor, 0, None)
.await
.expect("instantiate failed")
.account_id;

let code_hash = client
.upload("constructors_return_value", &mut ink_e2e::eve(), None)
.upload("constructors_return_value", &ink_e2e::eve(), None)
.await
.expect("upload `constructors_return_value` failed")
.code_hash;
Expand All @@ -224,7 +218,7 @@ mod call_builder {
contract.call_instantiate(code_hash, invalid_selector, true)
});
let call_result = client
.call(&mut ink_e2e::eve(), call, 0, None)
.call(&ink_e2e::eve(), call, 0, None)
.await
.expect("Client failed to call `call_builder::call_instantiate`.")
.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub mod constructors_return_value {
let success = client
.instantiate(
"constructors_return_value",
&mut ink_e2e::alice(),
&ink_e2e::alice(),
constructor,
0,
None,
Expand Down Expand Up @@ -175,7 +175,7 @@ pub mod constructors_return_value {
let contract_acc_id = client
.instantiate(
"constructors_return_value",
&mut ink_e2e::bob(),
&ink_e2e::bob(),
constructor,
0,
None,
Expand All @@ -188,7 +188,7 @@ pub mod constructors_return_value {
ink_e2e::build_message::<ConstructorsReturnValueRef>(contract_acc_id)
.call(|contract| contract.get_value());
let value = client
.call(&mut ink_e2e::bob(), get, 0, None)
.call(&ink_e2e::bob(), get, 0, None)
.await
.expect("Calling `get_value` failed")
.value
Expand Down Expand Up @@ -240,7 +240,7 @@ pub mod constructors_return_value {
let result = client
.instantiate(
"constructors_return_value",
&mut ink_e2e::charlie(),
&ink_e2e::charlie(),
constructor,
0,
None,
Expand Down
Loading

0 comments on commit fc543da

Please sign in to comment.