环境配置sui1.24核心概念sui的scenario创建,并且运行,测试运行脚本suimovetest运行代码moduletest_learning::Sword{publicstructSwordhaskey,store{id:U
环境配置sui 1.24
核心概念 sui的scenario创建,并且运行,测试
运行脚本
sui move test
运行代码
module test_learning::Sword {
public struct Sword has key, store{
id: UID,
magic: u64,
strength: u64,
}
public struct AdminCap has key, store {
id: UID,
}
public fun sword_create(magic: u64, strength: u64, ctx: &mut TxContext): Sword{
let sword = Sword {
id: object::new(ctx),
magic: magic,
strength: strength,
};
sword
}
#[test]
public fun test_create_sowrd() {
use sui::test_scenario;
let addr1 = @0xA;
let addr2 = @0xB;
let mut scenario = test_scenario::begin(addr1);
{
let sword = sword_create(47, 10, scenario.ctx());
transfer::public_transfer(sword, addr1)
};
scenario.next_tx(addr1);
{
let sword = scenario.take_from_sender<Sword>();
transfer::public_transfer(sword, addr2);
};
scenario.next_tx(addr2);
{
let sword = scenario.take_from_sender<Sword>();
assert!(sword.magic == 47, 1);
scenario.return_to_sender(sword)
};
scenario.end();
}
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!