-
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.
- Loading branch information
1 parent
4190b1c
commit 42d2ad6
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/tests/integration/data/soroban/contracts/test_storage/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_storage" | ||
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"] } |
18 changes: 18 additions & 0 deletions
18
src/tests/integration/data/soroban/contracts/test_storage/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,18 @@ | ||
A quick example of a contract that can be ran with `ksoroban test` | ||
|
||
You will need to have the stellar cli utils installed: | ||
https://developers.stellar.org/docs/build/smart-contracts/getting-started/setup | ||
|
||
And the soroban semantics kompiled: | ||
``` | ||
kdist build soroban-semantics.llvm | ||
``` | ||
|
||
And then (from this directory): | ||
|
||
```sh | ||
soroban contract build --out-dir output | ||
ksoroban test output/test_storage.wasm | ||
``` | ||
|
||
`ksoroban test` should exit successfully |
33 changes: 33 additions & 0 deletions
33
src/tests/integration/data/soroban/contracts/test_storage/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,33 @@ | ||
#![no_std] | ||
use soroban_sdk::{contract, contractimpl, Env, Symbol, symbol_short}; | ||
|
||
#[contract] | ||
pub struct StorageContract; | ||
|
||
const INST_KEY: Symbol = symbol_short!("INST"); | ||
const TEMP_KEY: Symbol = symbol_short!("TEMP"); | ||
const PRST_KEY: Symbol = symbol_short!("PRST"); | ||
|
||
#[contractimpl] | ||
impl StorageContract { | ||
pub fn test_u32(env: Env, num1: u32, num2: u32, num3: u32) -> bool { | ||
env.storage().instance().set(&INST_KEY, &num1); | ||
env.storage().temporary().set(&TEMP_KEY, &num2); | ||
env.storage().persistent().set(&PRST_KEY, &num3); | ||
|
||
let snum1: u32 = env.storage().instance().get(&INST_KEY).unwrap(); | ||
let snum2: u32 = env.storage().temporary().get(&TEMP_KEY).unwrap(); | ||
let snum3: u32 = env.storage().persistent().get(&PRST_KEY).unwrap(); | ||
|
||
num1 == snum1 && num2 == snum2 && num3 == snum3 | ||
} | ||
|
||
pub fn test_u32_overwrite(env: Env, num1: u32, num2: u32) -> bool { | ||
env.storage().instance().set(&INST_KEY, &num1); | ||
env.storage().instance().set(&INST_KEY, &num2); | ||
|
||
let num: u32 = env.storage().instance().get(&INST_KEY).unwrap(); | ||
|
||
num == num2 | ||
} | ||
} |