如何解决你如何使用 `ink!` 测试与 Substrate 的跨合约调用?
给定一个使用 ink!
编写的 2 个合约 Substrate 区块链,我如何运行一个单元测试来实例化两个合约?
“根”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
}
}
}
delegator example 还代表多个合约的游乐场。
解决方法
您还不能使用常规测试框架对此进行单元测试。 https://redspot.patract.io/en/ 是一个允许您编写集成测试的框架。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。