Skip to content

Commit

Permalink
Add test vector for workspace setups where contract types live in a l…
Browse files Browse the repository at this point in the history
…ib (#1070)

### What
Add test vector for workspace setups where contract types live in a lib.

### Why
In #1063 it was
mentioned that folks were having trouble with using types in other libs.
Added this test vector to confirm if that was an issue or not. Appears
to work fine, and this is a use case that is important, so committing
the test vector.
  • Loading branch information
leighmcculloch authored Aug 25, 2023
1 parent 535a9dd commit c844b88
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ members = [
"tests/auth",
"tests/fuzz",
"tests/multiimpl",
"tests/workspace_contract",
"tests/workspace_lib",
]

[workspace.package]
Expand Down
Binary file added test_workspace_contract.wasm
Binary file not shown.
Binary file added test_workspace_contract_b.wasm
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/workspace_contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "test_workspace_contract"
version.workspace = true
authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
edition = "2021"
publish = false
rust-version = "1.71"

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

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

[dev-dependencies]
soroban-sdk = {path = "../../soroban-sdk", features = ["testutils"]}
test_workspace_lib = {path = "../workspace_lib", features = ["testutils"]}
31 changes: 31 additions & 0 deletions tests/workspace_contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![no_std]
use soroban_sdk::{contract, contractimpl};

use test_workspace_lib::Value;

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
pub fn value() -> Value {
return Value { value: 13 };
}
}

#[cfg(test)]
mod test {
use super::*;
use soroban_sdk::Env;

#[test]
fn test_add() {
let e = Env::default();

let contract_id = e.register_contract(None, Contract);
let client = ContractClient::new(&e, &contract_id);

let z = client.value();
assert_eq!(z, Value { value: 13 });
}
}
21 changes: 21 additions & 0 deletions tests/workspace_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "test_workspace_lib"
version.workspace = true
authors = ["Stellar Development Foundation <info@stellar.org>"]
license = "Apache-2.0"
edition = "2021"
publish = false
rust-version = "1.71"

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

[features]
testutils = []

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

[dev-dependencies]
soroban-sdk = {path = "../../soroban-sdk", features = ["testutils"]}
8 changes: 8 additions & 0 deletions tests/workspace_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![no_std]
use soroban_sdk::contracttype;

#[contracttype]
#[derive(Debug, Eq, PartialEq)]
pub struct Value {
pub value: i32,
}

0 comments on commit c844b88

Please sign in to comment.