use super::Session;
use crate::{
mock::ContractMock,
runtime::{AccountIdFor, Runtime},
DEFAULT_GAS_LIMIT,
};
pub trait MockingApi<R: Runtime> {
fn deploy(&mut self, mock: ContractMock) -> AccountIdFor<R::Config>;
fn mock_existing_contract(&mut self, _mock: ContractMock, _address: AccountIdFor<R::Config>);
}
impl<R: Runtime> MockingApi<R> for Session<R>
where
R::Config: pallet_contracts::Config,
{
fn deploy(&mut self, mock: ContractMock) -> AccountIdFor<R::Config> {
let mock_bytes = wat::parse_str(DUMMY_CONTRACT).expect("Dummy contract should be valid");
let salt = self
.mocks
.lock()
.expect("Should be able to acquire lock on registry")
.salt();
let mock_address = self
.sandbox()
.deploy_contract(
mock_bytes,
0u32.into(),
vec![],
salt,
R::default_actor(),
DEFAULT_GAS_LIMIT,
None,
)
.result
.expect("Deployment of a dummy contract should succeed")
.account_id;
self.mocks
.lock()
.expect("Should be able to acquire lock on registry")
.register(mock_address.clone(), mock);
mock_address
}
fn mock_existing_contract(&mut self, _mock: ContractMock, _address: AccountIdFor<R::Config>) {
todo!("soon")
}
}
const DUMMY_CONTRACT: &str = r#"
(module
(import "env" "memory" (memory 1 1))
(func (export "deploy"))
(func (export "call") (unreachable))
)"#;