#[test]
Expand description
Defines an End-to-End test.
The system requirements are:
- A Substrate node with
pallet-contracts
installed on the local system. You can e.g. usesubstrate-contracts-node
and install it on your PATH, or provide a path to an executable using theCONTRACTS_NODE
environment variable.
Before the test function is invoked the contract will have been build. Any errors that occur during the contract build will prevent the test function from being invoked.
Header Arguments
The #[ink::e2e_test]
macro can be provided with some additional comma-separated
header arguments:
Example
# // TODO(#xxx) Remove the `no_compile`.
#[cfg(test)]
mod tests {
use ::ink_e2e::*;
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[ink::e2e_test]
async fn e2e_test_2(mut client: ::ink_e2e::Client<C,E>) -> E2EResult<()> {
// given
let constructor = contract_transfer::constructors::new();
let contract_acc_id = client.instantiate(
&mut ::ink_e2e::alice(),
constructor,
1337,
None,
)
.await
.expect("instantiating contract failed")
.account_id;
// when
let transfer = contract_transfer::messages::give_me(120);
let call_res = client.call(
&mut ::ink_e2e::bob(),
contract_acc_id.clone(),
transfer.into(),
10,
None,
)
.await;
// then
assert!(call_res.is_ok());
Ok(())
}
}
You can also use build the Signer
type yourself, without going through
the pre-defined functions:
let mut bob = ::ink_e2e::PairSigner::new(
::ink_e2e::AccountKeyring::Bob.pair()
);