1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| #[test_only] module book::witness_tests ; use sui::test_scenario::{Self, Scenario}; use sui::coin::{Self, Coin}; use sui::sui::SUI; use std::string; use book::witness::{Self, ShareInfo, House, Passport}; use book::witness::get_passport_fee;
#[test] fun test_witness_flow() { let owner = @0xA; let user = @0xB; let mut scenario = test_scenario::begin(owner); test_scenario::next_tx(&mut scenario, owner); { witness::test_init(test_scenario::ctx(&mut scenario)); };
test_scenario::next_tx(&mut scenario, user); { let coin = coin::mint_for_testing<SUI>(100000, test_scenario::ctx(&mut scenario)); let share_info = test_scenario::take_immutable<ShareInfo>(&scenario); let passport = witness::requirePassport( coin, &share_info, test_scenario::ctx(&mut scenario) ); witness::create_house( passport, string::utf8(b"My House"), test_scenario::ctx(&mut scenario) ); test_scenario::return_immutable(share_info); };
test_scenario::next_tx(&mut scenario, user); { let coin = test_scenario::take_from_address<Coin<SUI>>(&scenario, owner); assert!(coin.value() == get_passport_fee()); test_scenario::return_to_address(owner, coin);
let coin = test_scenario::take_from_address<Coin<SUI>>(&scenario, user); assert!(coin.value() == 100000 - get_passport_fee()); test_scenario::return_to_address(user, coin);
assert!(test_scenario::has_most_recent_for_sender<House>(&scenario)); }; test_scenario::end(scenario); }
#[test] #[expected_failure(abort_code = sui::balance::ENotEnough)] fun test_witness_flow_no_enough() {
let owner = @0xA; let user = @0xB; let mut scenario = test_scenario::begin(owner); test_scenario::next_tx(&mut scenario, owner); { witness::test_init(test_scenario::ctx(&mut scenario)); };
test_scenario::next_tx(&mut scenario, user); { let fee = get_passport_fee() - 1; let coin = coin::mint_for_testing<SUI>(fee, test_scenario::ctx(&mut scenario)); let share_info = test_scenario::take_immutable<ShareInfo>(&scenario); let passport = witness::requirePassport( coin, &share_info, test_scenario::ctx(&mut scenario) ); test_scenario::return_shared(share_info); }; test_scenario::end(scenario); }
|