0

给定使用 编写的 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
        }
    }
}

委托人示例还代表了多个合约的游乐场。

4

1 回答 1

0

您还不能使用常规测试框架对此进行单元测试。https://redspot.patract.io/en/是一个允许您编写集成测试的框架。

于 2021-06-01T11:31:23.197 回答