-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Option<T> work with contracttype (#1145)
### What Try to make Option<T> work with contracttype ### Why Close stellar/rs-soroban-env#444 Close #877 Dependent on: - stellar/rs-stellar-xdr#320 - stellar/rs-soroban-env#1198
- Loading branch information
1 parent
77a760b
commit 759deb6
Showing
6 changed files
with
284 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate as soroban_sdk; | ||
use soroban_sdk::{contract, contractimpl, contracttype, Env}; | ||
|
||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
#[contracttype] | ||
pub struct Udt { | ||
pub a: i32, | ||
pub b: Option<i32>, | ||
} | ||
|
||
#[contract] | ||
pub struct Contract; | ||
|
||
#[contractimpl] | ||
impl Contract { | ||
pub fn add(a: Udt, b: Udt) -> (Udt, Udt) { | ||
(a, b) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_functional() { | ||
let env = Env::default(); | ||
let contract_id = env.register_contract(None, Contract); | ||
|
||
let a = Udt { a: 5, b: None }; | ||
let b = Udt { a: 10, b: Some(1) }; | ||
let c = ContractClient::new(&env, &contract_id).add(&a, &b); | ||
assert_eq!(c, (a, b)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.