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

[ink_e2e] improve call API, remove build_message + callback #1782

Merged
merged 30 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f773699
Cherry picking changes from #1669
ascjones May 12, 2023
4693132
Don't display verbose Debug message for module error.
ascjones May 12, 2023
ad372d1
Initial conversion of erc20 to use new call
ascjones May 12, 2023
d4c9570
Remove constraint from InstantiationResult
ascjones May 12, 2023
ece5722
Merge branch 'master' into aj/e2e-improve-call
ascjones May 17, 2023
e733996
Use 3.0.0 release
ascjones May 17, 2023
ffc218f
Revert "Use 3.0.0 release"
ascjones May 17, 2023
feaa89b
Move instantiate generic parameter
ascjones May 17, 2023
134d976
Merge branch 'master' into aj/e2e-improve-call
ascjones May 17, 2023
d752a4d
Update call-runtime example
ascjones May 17, 2023
1072175
Update contract-terminate tests
ascjones May 17, 2023
580141a
Update contract-transfer tests
ascjones May 17, 2023
1bab0c7
Custom allocator
ascjones May 18, 2023
604053a
Custom environment
ascjones May 18, 2023
5734729
e2e-call-runtime
ascjones May 18, 2023
4d8da7f
flipper
ascjones May 18, 2023
97ac9f8
lang-err-integration-tests, compiles but fails
ascjones May 18, 2023
748103f
Don't debug log the entire dispatch error
ascjones May 18, 2023
21b898b
constructor-return-value
ascjones May 18, 2023
5569857
contract-ref
ascjones May 18, 2023
036dd5f
integration-flipper
ascjones May 18, 2023
f5c1496
mapping-integration-tests
ascjones May 18, 2023
9b181d3
multi-contract-caller
ascjones May 18, 2023
0197363
set-code-hash
ascjones May 18, 2023
46a5c02
wildcard-selector
ascjones May 18, 2023
1d4846e
Merge branch 'master' into aj/e2e-improve-call
ascjones May 18, 2023
867da3b
trait-dyn-cross-contract-calls
ascjones May 18, 2023
4570150
Clippy
ascjones May 18, 2023
0611141
Export CallBuilderFinal type alias
ascjones May 19, 2023
5087d30
CHANGELOG.md
ascjones May 19, 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Schema generation - [#1765](https://github.com/paritytech/ink/pull/1765)

### Changed
- E2E: improve call API, remove `build_message` + callback - [#1782](https://github.com/paritytech/ink/pull/1782)

## Version 4.2.0

### Added
Expand Down
132 changes: 0 additions & 132 deletions crates/e2e/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use ink::codegen::TraitCallBuilder;
use ink_env::{
call::{
utils::{
ReturnType,
Set,
Unset,
},
Call,
CallBuilder,
CreateBuilder,
ExecutionInput,
FromAccountId,
},
Environment,
};
Expand Down Expand Up @@ -59,131 +55,3 @@ where
.exec_input()
.encode()
}

/// Captures the encoded input for an `ink!` message call, together with the account id of
/// the contract being called.
#[derive(Debug, Clone)]
pub struct Message<E: Environment, RetType> {
account_id: E::AccountId,
exec_input: Vec<u8>,
_return_type: std::marker::PhantomData<RetType>,
}

impl<E, RetType> Message<E, RetType>
where
E: Environment,
{
/// Create a new message from the given account id and encoded message data.
pub fn new(account_id: E::AccountId, exec_input: Vec<u8>) -> Self {
Self {
account_id,
exec_input,
_return_type: Default::default(),
}
}

/// The account id of the contract being called to invoke the message.
pub fn account_id(&self) -> &E::AccountId {
&self.account_id
}

/// The encoded message data, comprised of the selector and the message arguments.
pub fn exec_input(&self) -> &[u8] {
&self.exec_input
}
}

/// Convenience method for building messages for the default environment.
///
/// # Note
///
/// This is hardcoded to [`ink_env::DefaultEnvironment`] so the user does not have to
/// specify this generic parameter, which currently is hardcoded in the E2E testing suite.
pub fn build_message<Ref>(
account_id: <ink_env::DefaultEnvironment as Environment>::AccountId,
) -> MessageBuilder<ink_env::DefaultEnvironment, Ref>
where
Ref: TraitCallBuilder + FromAccountId<ink_env::DefaultEnvironment>,
{
MessageBuilder::from_account_id(account_id)
}

/// Build messages using a contract ref.
pub struct MessageBuilder<E: Environment, Ref> {
account_id: E::AccountId,
contract_ref: Ref,
}

impl<E, Ref> MessageBuilder<E, Ref>
where
E: Environment,
Ref: TraitCallBuilder + FromAccountId<E>,
{
/// Create a new [`MessageBuilder`] to invoke a message on the given contract.
pub fn from_account_id(account_id: E::AccountId) -> Self {
let contract_ref = <Ref as FromAccountId<E>>::from_account_id(account_id.clone());
Self {
account_id,
contract_ref,
}
}

/// Build an encoded call for a message from a [`CallBuilder`] instance returned from
/// a contract ref method.
///
/// This utilizes the generated message inherent methods on the contract ref
/// implementation, which returns a [`CallBuilder`] initialized with the selector
/// and message arguments.
///
/// # Example
/// ```
/// # #[ink::contract]
/// # pub mod my_contract {
/// #
/// # #[ink(storage)]
/// # pub struct MyContract { }
/// #
/// # impl MyContract {
/// # #[ink(constructor)]
/// # pub fn new() -> Self {
/// # Self {}
/// # }
/// #
/// # #[ink(message)]
/// # pub fn message(&self) {}
/// # }
/// # }
/// #
/// # fn message_builder_doc_test() {
/// # use my_contract::MyContractRef;
/// # let contract_acc_id = ink_primitives::AccountId::from([0x00; 32]);
/// ink_e2e::MessageBuilder::<ink::env::DefaultEnvironment, MyContractRef>::from_account_id(
/// contract_acc_id,
/// )
/// .call(|contract| contract.message());
/// # }
/// ```

pub fn call<F, Args, RetType>(mut self, mut message: F) -> Message<E, RetType>
where
F: FnMut(
&mut <Ref as TraitCallBuilder>::Builder,
) -> CallBuilder<
E,
Set<Call<E>>,
Set<ExecutionInput<Args>>,
Set<ReturnType<RetType>>,
>,
Args: scale::Encode,
RetType: scale::Decode,
{
let call_builder = <Ref as TraitCallBuilder>::call_mut(&mut self.contract_ref);
let builder = message(call_builder);
let exec_input = builder.params().exec_input().encode();
Message {
account_id: self.account_id.clone(),
exec_input,
_return_type: Default::default(),
}
}
}
Loading