11// SPDX-License-Identifier: Apache-2.0
22
3- use crate :: { build_solidity, SorobanEnv } ;
3+ use crate :: build_solidity;
44use soroban_sdk:: { IntoVal , Val } ;
55
66#[ test]
77fn math ( ) {
8- let wasm = build_solidity (
8+ let runtime = build_solidity (
99 r#"contract math {
1010 function max(uint64 a, uint64 b) public returns (uint64) {
1111 if (a > b) {
@@ -15,25 +15,22 @@ fn math() {
1515 }
1616 }
1717 }"# ,
18+ |_| { } ,
1819 ) ;
1920
20- let mut runtime = SorobanEnv :: new ( ) ;
21- // No constructor arguments
22- let constructor_args: soroban_sdk:: Vec < Val > = soroban_sdk:: Vec :: new ( & runtime. env ) ;
23- let addr = runtime. register_contract ( wasm, constructor_args) ;
24-
2521 let arg: Val = 5_u64 . into_val ( & runtime. env ) ;
2622 let arg2: Val = 4_u64 . into_val ( & runtime. env ) ;
2723
28- let res = runtime. invoke_contract ( & addr, "max" , vec ! [ arg, arg2] ) ;
24+ let addr = runtime. contracts . last ( ) . unwrap ( ) ;
25+ let res = runtime. invoke_contract ( addr, "max" , vec ! [ arg, arg2] ) ;
2926
3027 let expected: Val = 5_u64 . into_val ( & runtime. env ) ;
3128 assert ! ( expected. shallow_eq( & res) ) ;
3229}
3330
3431#[ test]
3532fn math_same_name ( ) {
36- let wasm = build_solidity (
33+ let src = build_solidity (
3734 r#"contract math {
3835 function max(uint64 a, uint64 b) public returns (uint64) {
3936 if (a > b) {
@@ -60,23 +57,21 @@ fn math_same_name() {
6057 }
6158 }
6259 "# ,
60+ |_| { } ,
6361 ) ;
6462
65- let mut runtime = SorobanEnv :: new ( ) ;
66- // No constructor arguments
67- let constructor_args: soroban_sdk:: Vec < Val > = soroban_sdk:: Vec :: new ( & runtime. env ) ;
68- let addr = runtime. register_contract ( wasm, constructor_args) ;
63+ let addr = src. contracts . last ( ) . unwrap ( ) ;
6964
70- let arg1: Val = 5_u64 . into_val ( & runtime . env ) ;
71- let arg2: Val = 4_u64 . into_val ( & runtime . env ) ;
72- let res = runtime . invoke_contract ( & addr, "max_uint64_uint64" , vec ! [ arg1, arg2] ) ;
73- let expected: Val = 5_u64 . into_val ( & runtime . env ) ;
65+ let arg1: Val = 5_u64 . into_val ( & src . env ) ;
66+ let arg2: Val = 4_u64 . into_val ( & src . env ) ;
67+ let res = src . invoke_contract ( addr, "max_uint64_uint64" , vec ! [ arg1, arg2] ) ;
68+ let expected: Val = 5_u64 . into_val ( & src . env ) ;
7469 assert ! ( expected. shallow_eq( & res) ) ;
7570
76- let arg1: Val = 5_u64 . into_val ( & runtime . env ) ;
77- let arg2: Val = 4_u64 . into_val ( & runtime . env ) ;
78- let arg3: Val = 6_u64 . into_val ( & runtime . env ) ;
79- let res = runtime . invoke_contract ( & addr, "max_uint64_uint64_uint64" , vec ! [ arg1, arg2, arg3] ) ;
80- let expected: Val = 6_u64 . into_val ( & runtime . env ) ;
71+ let arg1: Val = 5_u64 . into_val ( & src . env ) ;
72+ let arg2: Val = 4_u64 . into_val ( & src . env ) ;
73+ let arg3: Val = 6_u64 . into_val ( & src . env ) ;
74+ let res = src . invoke_contract ( addr, "max_uint64_uint64_uint64" , vec ! [ arg1, arg2, arg3] ) ;
75+ let expected: Val = 6_u64 . into_val ( & src . env ) ;
8176 assert ! ( expected. shallow_eq( & res) ) ;
8277}
0 commit comments