-
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.
Implement
symbol_index_in_linear_memory
(#46)
* move `loadSlices` to `symbol.md` * implement `symbol_index_in_linear_memory` * add komet test * Set Version: 0.1.39 * Set Version: 0.1.40 --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
5348db8
commit 3b9a1d9
Showing
6 changed files
with
165 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.39 | ||
0.1.40 |
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.39" | ||
version = "0.1.40" | ||
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_custom_types/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_custom_types" | ||
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"] } |
50 changes: 50 additions & 0 deletions
50
src/tests/integration/data/soroban/contracts/test_custom_types/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, contractimpl, contracttype, symbol_short, Address, Bytes, Env, FromVal, Symbol, TryFromVal, TryIntoVal, Val, Vec, EnvBase}; | ||
|
||
#[contract] | ||
pub struct TestCustomTypesContract; | ||
|
||
#[contracttype] | ||
#[derive(PartialEq)] | ||
pub enum MyBool { | ||
True, | ||
False | ||
} | ||
|
||
fn to_bool(p: &MyBool) -> bool { | ||
match p { | ||
MyBool::True => true, | ||
MyBool::False => false | ||
} | ||
} | ||
|
||
fn from_bool(p: bool) -> MyBool { | ||
if p { | ||
MyBool::True | ||
} else { | ||
MyBool::False | ||
} | ||
} | ||
|
||
|
||
#[contractimpl] | ||
impl TestCustomTypesContract { | ||
|
||
pub fn test_my_bool_roundtrip(env: Env, p: bool) -> bool { | ||
|
||
// mp:MyBool lives in the Wasm memory | ||
let mp = from_bool(p); | ||
|
||
// convert MyBool to a host object | ||
let v: Val = mp.try_into_val(&env).unwrap(); | ||
|
||
// convert v:Val to MyBool, load it to the Wasm memory | ||
// (using the 'symbol_index_in_linear_memory' host function under the hood) | ||
let mp2: MyBool = MyBool::try_from_val(&env, &v).unwrap(); | ||
|
||
let p2 = to_bool(&mp2); | ||
|
||
mp == mp2 && p == p2 | ||
} | ||
|
||
} |