Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for UDTs with tuple fields. #1144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/udt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, Vec};

mod tuples;

#[contracttype]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum UdtEnum2 {
Expand Down
53 changes: 53 additions & 0 deletions tests/udt/src/tuples.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use soroban_sdk::{contract, contractimpl, contracttype, Address, Vec};

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum UdtEnum {
UdtA((u32, Address)),
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UdtTuple((u32, Address));

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UdtStruct {
f1: (u32, Address),
}

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
pub fn id(v: (UdtEnum, UdtTuple, UdtStruct)) -> (UdtEnum, UdtTuple, UdtStruct) {
(v.0, v.1, v.2)
}
}

#[cfg(test)]
mod test {
use super::*;
use soroban_sdk::testutils::Address as _;
use soroban_sdk::{vec, xdr::ScVal, Bytes, Env, TryFromVal};

#[test]
fn test_tuples() {
let e = Env::default();
let contract_id = e.register_contract(None, Contract);
let client = ContractClient::new(&e, &contract_id);

let v1 = (
UdtEnum::UdtA((1, Address::random(&e))),
UdtTuple((2, Address::random(&e))),
UdtStruct {
f1: (3, Address::random(&e)),
},
);

let v2 = client.id(&v1);

assert_eq!(v1, v2);
}
}
Loading