use super::Keypair;
use crate::{
builders::CreateBuilderPartial,
CallBuilderFinal,
CallDryRunResult,
CallResult,
InstantiationResult,
UploadResult,
};
use ink_env::{
DefaultEnvironment,
Environment,
};
use jsonrpsee::core::async_trait;
use pallet_contracts_primitives::ContractInstantiateResult;
use subxt::dynamic::Value;
#[async_trait]
pub trait E2EBackend<E: Environment = DefaultEnvironment>:
ChainBackend + ContractsBackend<E>
{
}
#[async_trait]
pub trait ChainBackend {
type AccountId;
type Balance: Send;
type Error;
type EventLog;
async fn create_and_fund_account(
&mut self,
origin: &Keypair,
amount: Self::Balance,
) -> Keypair;
async fn balance(
&mut self,
account: Self::AccountId,
) -> Result<Self::Balance, Self::Error>;
async fn runtime_call<'a>(
&mut self,
origin: &Keypair,
pallet_name: &'a str,
call_name: &'a str,
call_data: Vec<Value>,
) -> Result<Self::EventLog, Self::Error>;
}
#[async_trait]
pub trait ContractsBackend<E: Environment> {
type Error;
type EventLog;
async fn instantiate<Contract, Args: Send + scale::Encode, R>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<E, Self::EventLog>, Self::Error>;
async fn instantiate_dry_run<Contract, Args: Send + scale::Encode, R>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: CreateBuilderPartial<E, Contract, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> ContractInstantiateResult<E::AccountId, E::Balance, ()>;
async fn upload(
&mut self,
contract_name: &str,
caller: &Keypair,
storage_deposit_limit: Option<E::Balance>,
) -> Result<UploadResult<E, Self::EventLog>, Self::Error>;
async fn call<Args: Sync + scale::Encode, RetType: Send + scale::Decode>(
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<CallResult<E, RetType, Self::EventLog>, Self::Error>
where
CallBuilderFinal<E, Args, RetType>: Clone;
async fn call_dry_run<Args: Sync + scale::Encode, RetType: Send + scale::Decode>(
&mut self,
caller: &Keypair,
message: &CallBuilderFinal<E, Args, RetType>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> CallDryRunResult<E, RetType>
where
CallBuilderFinal<E, Args, RetType>: Clone;
}