Skip to content

Commit db9f6f8

Browse files
committed
test(soroban): add hello_world example for String and Vec<String> ABI coverage
Signed-off-by: sen <kawkoi@proton.me>
1 parent 0f0e2e4 commit db9f6f8

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
use crate::build_solidity;
4+
use soroban_sdk::{IntoVal, String, Vec};
5+
6+
#[test]
7+
fn hello_world() {
8+
let runtime = build_solidity(
9+
r#"
10+
contract HelloWorld {
11+
function hello(string memory to) public pure returns (string[] memory) {
12+
string[] memory res = new string[](2);
13+
res[0] = "Hello";
14+
res[1] = to;
15+
return res;
16+
}
17+
}"#,
18+
|_| {},
19+
);
20+
21+
let addr = runtime.contracts.last().unwrap();
22+
23+
let to_str = String::from_str(&runtime.env, "Dev");
24+
let res = runtime.invoke_contract(addr, "hello", vec![to_str.into_val(&runtime.env)]);
25+
26+
let vec_res: Vec<String> = res.into_val(&runtime.env);
27+
println!("Logs: {:?}", runtime.env.logs().all());
28+
assert_eq!(vec_res.len(), 2);
29+
30+
// Check elements
31+
let _str0 = vec_res.get(0).unwrap();
32+
let _str1 = vec_res.get(1).unwrap();
33+
}

tests/soroban_testcases/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod auth;
66
mod constructor;
77
mod cross_contract_calls;
88
mod events;
9+
mod hello_world;
910
mod i256_u256;
1011
mod integer_width_rounding;
1112
mod integer_width_warnings;

0 commit comments

Comments
 (0)