Skip to content

Commit

Permalink
Add tests for UDTs with tuple fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Nov 10, 2023
1 parent 469844e commit 42ded4a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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);
}
}

0 comments on commit 42ded4a

Please sign in to comment.