给定使用 编写的 2-contract Substrate 区块链ink!
,我如何运行一个实例化两个合约的单元测试?
根”MyContract
use ink_storage::Lazy;
use other_contract::OtherContract;
//--snip--
#[ink(storage)]
struct MyContract {
/// The other contract.
other_contract: Lazy<OtherContract>,
}
impl MyContract {
/// Instantiate `MyContract with the given
/// sub-contract codes and some initial value.
#[ink(constructor)]
pub fn new(
other_contract_code_hash: Hash,
) -> Self {
let other_contract = OtherContract::new(1337)
.endowment(total_balance / 4)
.code_hash(other_contract_code_hash)
.instantiate()
.expect("failed at instantiating the `OtherContract` contract");
Self {
other_contract
}
}
/// Calls the other contract.
#[ink(message)]
pub fn call_other_contract(&self) -> i32 {
self.other_contract.get_value()
}
}
//--snip--
这OtherContract
#[ink::contract]
pub mod other_contract {
/// Storage for the other contract.
#[ink(storage)]
pub struct OtherContract {
value: i32,
}
impl OtherContract {
/// Initializes the contract.
#[ink(constructor)]
pub fn new(value: i32) -> Self {
Self { value }
}
/// Returns the current state.
#[ink(message)]
pub fn get_value(&self) -> i32 {
self.value
}
}
}
委托人示例还代表了多个合约的游乐场。