-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for building child contracts from source (#50)
* add submodule soroban-examples * fix contract stem * allow contract paths in kasmer.json and build from source * add test_cross_contract * Set Version: 0.1.43 * github action: checkout submodules * Set Version: 0.1.45 --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
5208294
commit 32a7a45
Showing
12 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
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,3 @@ | ||
[submodule "deps/soroban-examples"] | ||
path = deps/soroban-examples | ||
url = https://github.com/stellar/soroban-examples |
Submodule soroban-examples
added at
4ec153
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.1.44 | ||
0.1.45 |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "komet" | ||
version = "0.1.44" | ||
version = "0.1.45" | ||
description = "K tooling for the Soroban platform" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
|
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
15 changes: 15 additions & 0 deletions
15
src/tests/integration/data/soroban/contracts/test_cross_contract/Cargo.toml
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,15 @@ | ||
[package] | ||
name = "test_cross_contract" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
doctest = false | ||
|
||
[dependencies] | ||
soroban-sdk = { workspace = true } | ||
|
||
[dev-dependencies] | ||
soroban-sdk = { workspace = true, features = ["testutils"] } |
4 changes: 4 additions & 0 deletions
4
src/tests/integration/data/soroban/contracts/test_cross_contract/README.md
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,4 @@ | ||
This test demonstrates deploying two contracts (`contract_a and contract_b`) and testing their interaction. | ||
`contract_b` calls a function in `contract_a` during execution. The test setup is defined in `kasmer.json`, | ||
listing the directories of the two contracts. | ||
Komet automatically compiles the contracts and runs the test. |
6 changes: 6 additions & 0 deletions
6
src/tests/integration/data/soroban/contracts/test_cross_contract/kasmer.json
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,6 @@ | ||
{ | ||
"contracts": [ | ||
"../../../../../../../deps/soroban-examples/cross_contract/contract_a", | ||
"../../../../../../../deps/soroban-examples/cross_contract/contract_b" | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
src/tests/integration/data/soroban/contracts/test_cross_contract/src/lib.rs
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,50 @@ | ||
#![no_std] | ||
use soroban_sdk::{contract, contractclient, contractimpl, symbol_short, Address, Bytes, Env, FromVal, Symbol, Val}; | ||
|
||
extern "C" { | ||
fn kasmer_create_contract(addr_val: u64, hash_val: u64) -> u64; | ||
} | ||
|
||
fn create_contract(env: &Env, addr: &Bytes, hash: &Bytes) -> Address { | ||
unsafe { | ||
let res = kasmer_create_contract(addr.as_val().get_payload(), hash.as_val().get_payload()); | ||
Address::from_val(env, &Val::from_payload(res)) | ||
} | ||
} | ||
|
||
#[contract] | ||
pub struct TestCrossContract; | ||
|
||
#[contractclient(name = "ContractBClient")] | ||
trait ContractB { | ||
fn add_with(e: Env, address: Address, x: u32, y: u32) -> u32; | ||
} | ||
|
||
const ADDR_A: &[u8; 32] = b"contract_a______________________"; | ||
const ADDR_A_KEY: Symbol = symbol_short!("ctr_a"); | ||
const ADDR_B: &[u8; 32] = b"contract_b______________________"; | ||
const ADDR_B_KEY: Symbol = symbol_short!("ctr_b"); | ||
|
||
#[contractimpl] | ||
impl TestCrossContract { | ||
pub fn init(env: Env, hash_a: Bytes, hash_b: Bytes) { | ||
let address_a = create_contract(&env, &Bytes::from_array(&env, ADDR_A), &hash_a); | ||
let address_b = create_contract(&env, &Bytes::from_array(&env, ADDR_B), &hash_b); | ||
|
||
env.storage().instance().set(&ADDR_A_KEY, &address_a); | ||
env.storage().instance().set(&ADDR_B_KEY, &address_b); | ||
} | ||
|
||
pub fn test_add_with(env: Env, x: u32, y: u32) -> bool { | ||
if x > 100 || y > 100 { | ||
return true; | ||
} | ||
|
||
let address_a : Address = env.storage().instance().get(&ADDR_A_KEY).unwrap(); | ||
let address_b : Address = env.storage().instance().get(&ADDR_B_KEY).unwrap(); | ||
|
||
let client = ContractBClient::new(&env, &address_b); | ||
x + y == client.add_with(&address_a, &x, &y) | ||
} | ||
|
||
} |
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