1
+ use anyhow:: Context ;
1
2
use aptos_sdk:: move_types:: {
2
3
identifier:: Identifier , language_storage:: ModuleId , language_storage:: TypeTag ,
3
4
} ;
@@ -26,7 +27,7 @@ impl MaptosTransferLifecycle {
26
27
}
27
28
28
29
pub fn transfer (
29
- & self ,
30
+ from_account : & LocalAccount ,
30
31
to_account : AccountAddress ,
31
32
amount : u64 ,
32
33
chain_id : ChainId ,
@@ -41,12 +42,12 @@ impl MaptosTransferLifecycle {
41
42
SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_secs ( ) + 10 ,
42
43
chain_id,
43
44
)
44
- . sender ( self . 0 . address ( ) )
45
- . sequence_number ( self . 0 . sequence_number ( ) )
45
+ . sender ( from_account . address ( ) )
46
+ . sequence_number ( from_account . sequence_number ( ) )
46
47
. max_gas_amount ( 5_000 )
47
48
. gas_unit_price ( 100 ) ;
48
49
49
- self . 0 . sign_with_transaction_builder ( transaction_builder)
50
+ from_account . sign_with_transaction_builder ( transaction_builder)
50
51
}
51
52
}
52
53
@@ -61,33 +62,57 @@ impl Criterionish for MaptosTransferLifecycle {
61
62
. await
62
63
. map_err ( |e| CriterionError :: Internal ( e. into ( ) ) ) ?;
63
64
64
- // TODO: fetch the correct chain-id
65
- let chain_id = ChainId :: test ( ) ;
65
+ let movement_aptos_faucet_client = movement_aptos_migrator
66
+ . wait_for_faucet_client_ready ( tokio:: time:: Duration :: from_secs ( 30 ) )
67
+ . await
68
+ . map_err ( |e| CriterionError :: Internal ( e. into ( ) ) ) ?;
69
+
70
+ let alice = LocalAccount :: generate ( & mut rand:: rngs:: OsRng ) ;
71
+ let bob = LocalAccount :: generate ( & mut rand:: rngs:: OsRng ) ;
66
72
67
- let recipient1 = AccountAddress :: random ( ) ;
68
- let recipient2 = AccountAddress :: random ( ) ;
73
+ movement_aptos_faucet_client
74
+ . create_account ( alice. address ( ) )
75
+ . await
76
+ . context ( "Failed to create Alice's account" )
77
+ . map_err ( |e| CriterionError :: Internal ( e. into ( ) ) ) ?;
78
+
79
+ movement_aptos_faucet_client
80
+ . create_account ( bob. address ( ) )
81
+ . await
82
+ . context ( "Failed to create Bob's account" )
83
+ . map_err ( |e| CriterionError :: Internal ( e. into ( ) ) ) ?;
84
+
85
+ let chain_id = movement_aptos_rest_client
86
+ . get_index ( )
87
+ . await
88
+ . context ( "Failed to get chain ID" )
89
+ . map_err ( |e| CriterionError :: Internal ( e. into ( ) ) ) ?
90
+ . inner ( )
91
+ . chain_id ;
92
+ let chain_id = ChainId :: new ( chain_id) ;
69
93
70
- // 1. transfer 1 MOVE to recipient1
71
- let tx1 = self . transfer ( recipient1, 100_000_000 , chain_id) ;
94
+ // 1. transfer 1 MOVE to Alice
95
+ let tx1 =
96
+ MaptosTransferLifecycle :: transfer ( & self . 0 , alice. address ( ) , 100_000_000 , chain_id) ;
72
97
73
98
movement_aptos_rest_client. submit_and_wait ( & tx1) . await . map_err ( |e| {
74
- CriterionError :: Unsatisfied ( format ! ( "Transfer to recipient1 failed: {:?}" , e) . into ( ) )
99
+ CriterionError :: Unsatisfied ( format ! ( "Transfer to Aice failed: {:?}" , e) . into ( ) )
75
100
} ) ?;
76
101
77
- // 2. transfer 0 MOVE to recipient1
78
- let tx2 = self . transfer ( recipient1 , 0 , chain_id) ;
102
+ // 2. transfer 0 MOVE to Alice
103
+ let tx2 = MaptosTransferLifecycle :: transfer ( & alice , alice . address ( ) , 0 , chain_id) ;
79
104
80
105
movement_aptos_rest_client. submit_and_wait ( & tx2) . await . map_err ( |e| {
81
106
CriterionError :: Unsatisfied (
82
- format ! ( "Zero transfer to recipient1 failed: {:?}" , e) . into ( ) ,
107
+ format ! ( "Zero transfer from Alice to Alice failed: {:?}" , e) . into ( ) ,
83
108
)
84
109
} ) ?;
85
110
86
- // 3. transfers 0.1 MOVE to recipient2
87
- let tx3 = self . transfer ( recipient2 , 10_000_000 , chain_id) ;
111
+ // 3. transfers 0.1 MOVE to Bob
112
+ let tx3 = MaptosTransferLifecycle :: transfer ( & alice , bob . address ( ) , 10_000_000 , chain_id) ;
88
113
89
114
movement_aptos_rest_client. submit_and_wait ( & tx3) . await . map_err ( |e| {
90
- CriterionError :: Unsatisfied ( format ! ( "Transfer to recipient2 failed: {:?}" , e) . into ( ) )
115
+ CriterionError :: Unsatisfied ( format ! ( "Transfer to Bob failed: {:?}" , e) . into ( ) )
91
116
} ) ?;
92
117
93
118
Ok ( ( ) )
0 commit comments