@@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
30
30
. transact ( )
31
31
. await ?
32
32
. into_result ( ) ?;
33
-
33
+
34
34
let bob_account = root
35
35
. create_subaccount ( "bob" )
36
36
. initial_balance ( NearToken :: from_near ( 5 ) )
@@ -50,7 +50,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
50
50
}
51
51
52
52
async fn create_token (
53
- contract : & Contract ,
53
+ factory : & Contract ,
54
54
token_owner_account : & Account ,
55
55
alice_account : & Account ,
56
56
bob_account : & Account ,
@@ -76,48 +76,55 @@ async fn create_token(
76
76
} ;
77
77
78
78
// Getting required deposit based on provided arguments
79
- let required_deposit: U128 = contract
79
+ let required_deposit: U128 = factory
80
80
. view ( "get_required" )
81
81
. args_json ( json ! ( { "args" : token_args} ) )
82
82
. await ?
83
83
. json ( ) ?;
84
84
85
85
// Creating token with less than required deposit (should fail)
86
- let res_0 = contract
87
- . call ( "create_token" )
86
+ let not_enough = alice_account
87
+ . call ( factory . id ( ) , "create_token" )
88
88
. args_json ( json ! ( { "args" : token_args} ) )
89
89
. max_gas ( )
90
90
. deposit ( NearToken :: from_yoctonear ( required_deposit. 0 - 1 ) )
91
91
. transact ( )
92
92
. await ?;
93
- assert ! ( res_0 . is_failure( ) ) ;
93
+ assert ! ( not_enough . is_failure( ) ) ;
94
94
95
95
// Creating token with the required deposit
96
- let res_1 = contract
97
- . call ( "create_token" )
96
+ let alice_succeeds = alice_account
97
+ . call ( factory . id ( ) , "create_token" )
98
98
. args_json ( json ! ( { "args" : token_args} ) )
99
99
. max_gas ( )
100
100
. deposit ( NearToken :: from_yoctonear ( required_deposit. 0 ) )
101
101
. transact ( )
102
102
. await ?;
103
+ assert ! ( alice_succeeds. json:: <bool >( ) ? == true ) ;
103
104
104
- println ! ( "{:?}" , required_deposit ) ;
105
- assert ! ( res_1 . is_success ( ) ) ;
105
+ // Creating same token fails
106
+ let bob_balance = bob_account . view_account ( ) . await ? . balance ;
106
107
107
- // Creating token with the required deposit
108
- let res_3 = contract
109
- . call ( "create_token" )
108
+ let bob_fails = bob_account
109
+ . call ( factory. id ( ) , "create_token" )
110
110
. args_json ( json ! ( { "args" : token_args} ) )
111
111
. max_gas ( )
112
112
. deposit ( NearToken :: from_yoctonear ( required_deposit. 0 ) )
113
113
. transact ( )
114
114
. await ?;
115
115
116
- println ! ( "{:?}" , required_deposit) ;
117
- assert ! ( res_3. is_failure( ) ) ;
116
+ let bob_balance_after = bob_account. view_account ( ) . await ?. balance ;
117
+ let rest = bob_balance. saturating_sub ( bob_balance_after) . as_millinear ( ) ;
118
+ println ! ( "{:?}" , rest) ;
119
+
120
+ // bob fails
121
+ assert ! ( bob_fails. json:: <bool >( ) ? == false ) ;
122
+
123
+ // but it gets back the money (i.e. looses less than 0.005 N)
124
+ assert ! ( rest < 5 ) ;
118
125
119
126
// Checking created token account and metadata
120
- let token_account_id: AccountId = format ! ( "{}.{}" , token_id, contract . id( ) ) . parse ( ) . unwrap ( ) ;
127
+ let token_account_id: AccountId = format ! ( "{}.{}" , token_id, factory . id( ) ) . parse ( ) . unwrap ( ) ;
121
128
let token_metadata: FungibleTokenMetadata = token_owner_account
122
129
. view ( & token_account_id, "ft_metadata" )
123
130
. args_json ( json ! ( { } ) )
0 commit comments