Skip to content

Commit b9bccbf

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 b9bccbf

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

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)