11#[test_only]
22module Escrow ::escrow_tests {
3+ use 0x1 ::signer;
34 use Escrow ::escrow;
45
56 const BUYER : address = @0 x1;
67 const SELLER : address = @0 x2;
78
9+ // позитив: deposit → fund → release
810 #[test]
911 public entry fun test_happy_flow () {
1012 let bw = escrow::new_wallet ();
@@ -19,32 +21,29 @@ module Escrow::escrow_tests {
1921 assert ! (escrow::balance (&bw) == 50 , 0 );
2022 assert ! (escrow::balance (&sw) == 100 , 1 );
2123
22- // Поглощаем ресурсы
24+ // потребляем ресурсы
2325 escrow::destroy_deal_for_test (d);
2426 escrow::destroy_wallet_for_test (bw);
2527 escrow::destroy_wallet_for_test (sw);
2628 }
2729
28- // Негатив: не тот покупатель на fund -> E_NOT_BUYER = 5
30+ // негатив: refund после fund (деньги возвращаются покупателю)
2931 #[test]
30- #[expected_failure(abort_code = 5 , location = Escrow::escrow)]
31- public entry fun test_fund_wrong_buyer_fails () {
32+ public entry fun test_refund_flow () {
3233 let bw = escrow::new_wallet ();
33- let d = escrow::create (BUYER , SELLER , 10 );
34- escrow::deposit (&mut bw, 10 );
35- escrow::fund (@0 xDEAD, &mut bw, &mut d);
36- escrow::destroy_deal_for_test (d);
37- escrow::destroy_wallet_for_test (bw);
38- }
39-
40- // Негатив: release до fund -> E_NOT_FUNDED = 2
41- #[test]
42- #[expected_failure(abort_code = 2 , location = Escrow::escrow)]
43- public entry fun test_release_not_funded_fails () {
4434 let sw = escrow::new_wallet ();
45- let d = escrow::create (BUYER , SELLER , 10 );
46- escrow::release (SELLER , &mut sw, &mut d);
35+
36+ escrow::deposit (&mut bw, 100 );
37+ let d = escrow::create (BUYER , SELLER , 100 );
38+
39+ escrow::fund (BUYER , &mut bw, &mut d);
40+ escrow::refund (BUYER , &mut bw, &mut d);
41+
42+ assert ! (escrow::balance (&bw) == 100 , 0 );
43+ assert ! (escrow::balance (&sw) == 0 , 1 );
44+
4745 escrow::destroy_deal_for_test (d);
46+ escrow::destroy_wallet_for_test (bw);
4847 escrow::destroy_wallet_for_test (sw);
4948 }
5049}
0 commit comments