Skip to content

Commit

Permalink
[E2E alternative backend]: Make tests generic over client (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 authored Aug 4, 2023
1 parent fdd164d commit 3d6784c
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 93 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
- Stabilize `call_runtime`[#1749](/~https://github.com/paritytech/ink/pull/1749)
- Make E2E testcases generic over `E2EBackend` trait - [#1867](/~https://github.com/paritytech/ink/pull/1867)

### Added
- Schema generation - [#1765](/~https://github.com/paritytech/ink/pull/1765)
Expand Down
10 changes: 8 additions & 2 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ use crate::{
InstantiationResult,
UploadResult,
};
use ink_env::Environment;
use ink_env::{
DefaultEnvironment,
Environment,
};
use jsonrpsee::core::async_trait;
use pallet_contracts_primitives::ContractInstantiateResult;
use subxt::dynamic::Value;

/// Full E2E testing backend: combines general chain API and contract-specific operations.
#[async_trait]
pub trait E2EBackend<E: Environment>: ChainBackend + ContractsBackend<E> {}
pub trait E2EBackend<E: Environment = DefaultEnvironment>:
ChainBackend + ContractsBackend<E>
{
}

/// General chain operations useful in contract testing.
#[async_trait]
Expand Down
25 changes: 17 additions & 8 deletions integration-tests/call-builder-return-value/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ mod call_builder {
use ink_e2e::{
ChainBackend,
ContractsBackend,
E2EBackend,
};

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

#[ink_e2e::test]
async fn e2e_delegate_call_return_value_returns_correct_value(
mut client: ink_e2e::Client<C, E>,
async fn e2e_delegate_call_return_value_returns_correct_value<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000)
Expand Down Expand Up @@ -159,8 +162,10 @@ mod call_builder {
}

#[ink_e2e::test]
async fn e2e_delegate_call_return_value_errors_if_return_data_too_long(
mut client: ink_e2e::Client<C, E>,
async fn e2e_delegate_call_return_value_errors_if_return_data_too_long<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000)
Expand Down Expand Up @@ -201,8 +206,10 @@ mod call_builder {
}

#[ink_e2e::test]
async fn e2e_forward_call_return_value_returns_correct_value(
mut client: ink_e2e::Client<C, E>,
async fn e2e_forward_call_return_value_returns_correct_value<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000)
Expand Down Expand Up @@ -239,8 +246,10 @@ mod call_builder {
}

#[ink_e2e::test]
async fn e2e_forward_call_return_value_errors_if_return_data_too_long(
mut client: ink_e2e::Client<C, E>,
async fn e2e_forward_call_return_value_errors_if_return_data_too_long<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::alice(), 10_000_000_000_000)
Expand Down
16 changes: 10 additions & 6 deletions integration-tests/call-runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ mod runtime_call {
/// - the call is valid
/// - the call execution succeeds
#[ink_e2e::test]
async fn transfer_with_call_runtime_works(
mut client: Client<C, E>,
async fn transfer_with_call_runtime_works<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = RuntimeCallerRef::new();
Expand Down Expand Up @@ -216,8 +216,10 @@ mod runtime_call {
/// - the call is valid
/// - the call execution fails
#[ink_e2e::test]
async fn transfer_with_call_runtime_fails_when_execution_fails(
mut client: Client<C, E>,
async fn transfer_with_call_runtime_fails_when_execution_fails<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = RuntimeCallerRef::new();
Expand Down Expand Up @@ -253,8 +255,10 @@ mod runtime_call {
/// Negative case scenario:
/// - the call is invalid
#[ink_e2e::test]
async fn transfer_with_call_runtime_fails_when_call_is_invalid(
mut client: Client<C, E>,
async fn transfer_with_call_runtime_fails_when_call_is_invalid<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = RuntimeCallerRef::new();
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/contract-terminate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub mod just_terminates {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn e2e_contract_terminates(
mut client: ink_e2e::Client<C, E>,
async fn e2e_contract_terminates<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = JustTerminateRef::new();
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/contract-transfer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ pub mod give_me {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn e2e_sending_value_to_give_me_must_fail(
mut client: ink_e2e::Client<C, E>,
async fn e2e_sending_value_to_give_me_must_fail<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = GiveMeRef::new();
Expand Down Expand Up @@ -226,8 +226,8 @@ pub mod give_me {
}

#[ink_e2e::test]
async fn e2e_contract_must_transfer_value_to_sender(
mut client: ink_e2e::Client<C, E>,
async fn e2e_contract_must_transfer_value_to_sender<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = GiveMeRef::new();
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/custom-allocator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod custom_allocator {
/// We test that we can upload and instantiate the contract using its default
/// constructor.
#[ink_e2e::test]
async fn default_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn default_works<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// Given
let constructor = CustomAllocatorRef::default();

Expand All @@ -136,7 +136,7 @@ mod custom_allocator {
/// We test that we can read and write a value from the on-chain contract
/// contract.
#[ink_e2e::test]
async fn it_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn it_works<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// Given
let constructor = CustomAllocatorRef::new(false);
let contract = client
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/custom-environment/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod runtime_call {

#[cfg(feature = "permissive-node")]
#[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)]
async fn calling_custom_environment_works(
mut client: Client<C, E>,
async fn calling_custom_environment_works<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = TopicsRef::new();
Expand Down Expand Up @@ -123,8 +123,10 @@ mod runtime_call {

#[cfg(not(feature = "permissive-node"))]
#[ink_e2e::test(environment = crate::EnvironmentWithManyTopics)]
async fn calling_custom_environment_fails_if_incompatible_with_node(
mut client: Client<C, E>,
async fn calling_custom_environment_fails_if_incompatible_with_node<
Client: E2EBackend,
>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = TopicsRef::new();
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/e2e-call-runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ pub mod e2e_call_runtime {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn call_runtime_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn call_runtime_works<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let constructor = ContractRef::new();
let contract = client
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/erc20/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ mod erc20 {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn e2e_transfer(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn e2e_transfer<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// given
let total_supply = 1_000_000_000;
let constructor = Erc20Ref::new(total_supply);
Expand Down Expand Up @@ -555,7 +555,7 @@ mod erc20 {
}

#[ink_e2e::test]
async fn e2e_allowances(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn e2e_allowances<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// given
let total_supply = 1_000_000_000;
let constructor = Erc20Ref::new(total_supply);
Expand Down
12 changes: 8 additions & 4 deletions integration-tests/events/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ pub mod events {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn emits_foreign_event(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn emits_foreign_event<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let init_value = false;
let constructor = EventsRef::new(init_value);
Expand Down Expand Up @@ -248,7 +250,9 @@ pub mod events {
}

#[ink_e2e::test]
async fn emits_inline_event(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn emits_inline_event<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let init_value = false;
let constructor = EventsRef::new(init_value);
Expand Down Expand Up @@ -286,8 +290,8 @@ pub mod events {
}

#[ink_e2e::test]
async fn emits_event_with_option_topic_none(
mut client: ink_e2e::Client<C, E>,
async fn emits_event_with_option_topic_none<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
// given
let init_value = false;
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/flipper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub mod flipper {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn it_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn it_works<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// given
let constructor = FlipperRef::new(false);
let contract = client
Expand Down Expand Up @@ -89,7 +89,7 @@ pub mod flipper {
}

#[ink_e2e::test]
async fn default_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
async fn default_works<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
// given
let constructor = FlipperRef::new_default();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ mod call_builder {
type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[ink_e2e::test]
async fn e2e_invalid_message_selector_can_be_handled(
mut client: ink_e2e::Client<C, E>,
async fn e2e_invalid_message_selector_can_be_handled<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::bob(), 10_000_000_000_000)
Expand Down Expand Up @@ -139,8 +139,8 @@ mod call_builder {
}

#[ink_e2e::test]
async fn e2e_invalid_message_selector_panics_on_invoke(
mut client: ink_e2e::Client<C, E>,
async fn e2e_invalid_message_selector_panics_on_invoke<Client: E2EBackend>(
mut client: Client,
) -> E2EResult<()> {
let origin = client
.create_and_fund_account(&ink_e2e::charlie(), 10_000_000_000_000)
Expand Down
Loading

0 comments on commit 3d6784c

Please sign in to comment.