Skip to content

Commit

Permalink
Add u64 test vector (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Sep 7, 2022
1 parent df9fd4b commit d7f92c6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"tests/hello",
"tests/add_i32",
"tests/add_i64",
"tests/add_u64",
"tests/add_bigint",
"tests/vec",
"tests/import_contract",
Expand Down
21 changes: 21 additions & 0 deletions tests/add_u64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "example_add_u64"
version = "0.0.4"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
publish = false
rust-version = "1.63"

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[dependencies]
soroban-sdk = {path = "../../soroban-sdk"}

[dev-dependencies]
soroban-sdk = {path = "../../soroban-sdk", features = ["testutils"]}

[features]
testutils = ["soroban-sdk/testutils"]
31 changes: 31 additions & 0 deletions tests/add_u64/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![no_std]
use soroban_sdk::contractimpl;

pub struct Contract;

#[contractimpl]
impl Contract {
pub fn add(a: u64, b: u64) -> u64 {
a + b
}
}

#[cfg(test)]
mod test {
use soroban_sdk::{BytesN, Env};

use crate::{Contract, ContractClient};

#[test]
fn test_add() {
let e = Env::default();
let contract_id = BytesN::from_array(&e, &[0; 32]);
e.register_contract(&contract_id, Contract);
let client = ContractClient::new(&e, &contract_id);

let x = 10u64;
let y = 12u64;
let z = client.add(&x, &y);
assert!(z == 22);
}
}

0 comments on commit d7f92c6

Please sign in to comment.