1
- use near_workspaces:: types:: { AccountId , KeyType , NearToken , SecretKey } ;
1
+ use near_workspaces:: types:: { AccountId , NearToken } ;
2
2
use serde_json:: json;
3
3
4
+ const TEN_NEAR : NearToken = NearToken :: from_near ( 10 ) ;
5
+
4
6
#[ tokio:: test]
5
7
async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
6
8
let sandbox = near_workspaces:: sandbox ( ) . await ?;
7
- let contract_wasm = near_workspaces:: compile_project ( "./" ) . await ?;
8
- let contract = sandbox. dev_deploy ( & contract_wasm) . await ?;
9
+ let root = sandbox. root_account ( ) ?;
9
10
10
- let alice = sandbox
11
- . create_tla (
12
- "alice.test.near" . parse ( ) . unwrap ( ) ,
13
- SecretKey :: from_random ( KeyType :: ED25519 ) ,
14
- )
15
- . await ?
16
- . unwrap ( ) ;
11
+ // Create accounts
12
+ let alice = create_subaccount ( & root, "alice" ) . await ?;
13
+ let bob = create_subaccount ( & root, "bob" ) . await ?;
17
14
18
- let bob = sandbox. dev_create_account ( ) . await ?;
15
+ let contract_wasm = near_workspaces:: compile_project ( "./" ) . await ?;
16
+ let contract = sandbox. dev_deploy ( & contract_wasm) . await ?;
19
17
20
- let res = contract
21
- . call ( "create_factory_subaccount_and_deploy" )
18
+ // Launch new donation contract through factory
19
+ let res = alice
20
+ . call ( contract. id ( ) , "create_factory_subaccount_and_deploy" )
22
21
. args_json ( json ! ( { "name" : "donation_for_alice" , "beneficiary" : alice. id( ) } ) )
23
22
. max_gas ( )
24
- . deposit ( NearToken :: from_near ( 5 ) )
23
+ . deposit ( NearToken :: from_millinear ( 1700 ) )
25
24
. transact ( )
26
25
. await ?;
27
26
@@ -48,5 +47,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
48
47
49
48
assert ! ( res. is_success( ) ) ;
50
49
50
+ // Try to create new donation contract with insufficient deposit
51
+ let res = alice
52
+ . call ( contract. id ( ) , "create_factory_subaccount_and_deploy" )
53
+ . args_json ( json ! ( { "name" : "donation_for_alice_2" , "beneficiary" : alice. id( ) } ) )
54
+ . max_gas ( )
55
+ . deposit ( NearToken :: from_millinear ( 1500 ) )
56
+ . transact ( )
57
+ . await ?;
58
+
59
+ assert ! ( res. is_failure( ) ) ;
60
+
51
61
Ok ( ( ) )
52
62
}
63
+
64
+ async fn create_subaccount (
65
+ root : & near_workspaces:: Account ,
66
+ name : & str ,
67
+ ) -> Result < near_workspaces:: Account , Box < dyn std:: error:: Error > > {
68
+ let subaccount = root
69
+ . create_subaccount ( name)
70
+ . initial_balance ( TEN_NEAR )
71
+ . transact ( )
72
+ . await ?
73
+ . unwrap ( ) ;
74
+
75
+ Ok ( subaccount)
76
+ }
0 commit comments