File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ use crate :: build_solidity;
4+ use soroban_sdk:: testutils:: Logs ;
5+ use soroban_sdk:: { IntoVal , String , Vec } ;
6+
7+ #[ test]
8+ fn hello_world ( ) {
9+ let runtime = build_solidity (
10+ r#"
11+ contract HelloWorld {
12+ function hello(string memory to) public pure returns (string[] memory) {
13+ string[] memory res = new string[](2);
14+ res[0] = "Hello";
15+ res[1] = to;
16+ return res;
17+ }
18+ }"# ,
19+ |_| { } ,
20+ ) ;
21+
22+ let addr = runtime. contracts . last ( ) . unwrap ( ) ;
23+
24+ let to_str = String :: from_str ( & runtime. env , "Dev" ) ;
25+ let res = runtime. invoke_contract ( addr, "hello" , vec ! [ to_str. into_val( & runtime. env) ] ) ;
26+
27+ let vec_res: Vec < String > = res. into_val ( & runtime. env ) ;
28+ println ! ( "Logs: {:?}" , runtime. env. logs( ) . all( ) ) ;
29+ assert_eq ! ( vec_res. len( ) , 2 ) ;
30+
31+ // Check elements
32+ let _str0 = vec_res. get ( 0 ) . unwrap ( ) ;
33+ let _str1 = vec_res. get ( 1 ) . unwrap ( ) ;
34+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ mod auth;
66mod constructor;
77mod cross_contract_calls;
88mod events;
9+ mod hello_world;
910mod i256_u256;
1011mod integer_width_rounding;
1112mod integer_width_warnings;
You can’t perform that action at this time.
0 commit comments