1- use near_workspaces:: types:: { AccountId , KeyType , NearToken , SecretKey } ;
1+ use near_workspaces:: types:: { AccountId , NearToken } ;
22use serde_json:: json;
33
4+ const TEN_NEAR : NearToken = NearToken :: from_near ( 10 ) ;
5+
46#[ tokio:: test]
57async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
68 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 ( ) ?;
910
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 ?;
1714
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 ?;
1917
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" )
2221 . args_json ( json ! ( { "name" : "donation_for_alice" , "beneficiary" : alice. id( ) } ) )
2322 . max_gas ( )
24- . deposit ( NearToken :: from_near ( 5 ) )
23+ . deposit ( NearToken :: from_millinear ( 1700 ) )
2524 . transact ( )
2625 . await ?;
2726
@@ -48,5 +47,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4847
4948 assert ! ( res. is_success( ) ) ;
5049
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+
5161 Ok ( ( ) )
5262}
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