Skip to content

Commit

Permalink
add komet test for vector operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Oct 29, 2024
1 parent 0fffc08 commit 974a509
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/komet/kdist/soroban-semantics/host/ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module HOST-LEDGER
<instrs> putContractData(#instance) => toSmall(Void) ... </instrs>
<hostStack> KEY : VAL : S => S </hostStack>
<callee> CONTRACT </callee>
<contract>
<contract>
<contractId> CONTRACT </contractId>
<instanceStorage> STORAGE => STORAGE [ KEY <- VAL ] </instanceStorage>
...
Expand Down Expand Up @@ -71,7 +71,7 @@ module HOST-LEDGER
</instrs>
<hostStack> KEY : S => S </hostStack>
<callee> CONTRACT </callee>
<contract>
<contract>
<contractId> CONTRACT </contractId>
<instanceStorage> STORAGE </instanceStorage>
...
Expand Down Expand Up @@ -112,7 +112,7 @@ module HOST-LEDGER
</instrs>
<hostStack> KEY : S => S </hostStack>
<callee> CONTRACT </callee>
<contract>
<contract>
<contractId> CONTRACT </contractId>
<instanceStorage> ... KEY |-> VAL ... </instanceStorage>
...
Expand Down Expand Up @@ -151,7 +151,7 @@ module HOST-LEDGER
<instrs> delContractData(#instance) => toSmall(Void) ... </instrs>
<hostStack> KEY : S => S </hostStack>
<callee> CONTRACT </callee>
<contract>
<contract>
<contractId> CONTRACT </contractId>
<instanceStorage> MAP => MAP [ KEY <- undef ] </instanceStorage>
...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_containers"
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"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, Env, Vec};

#[contract]
pub struct ContainersContract;

#[contractimpl]
impl ContainersContract {

pub fn test_vector(env: Env, n: u32) -> bool {
let n = n % 100;

let mut vec: Vec<u32> = Vec::new(&env);
assert_eq!(vec.len(), 0);

for i in 0..n {
vec.push_back(i);
}

assert_eq!(vec.len(), n);

for i in 0..n {
assert_eq!(vec.get_unchecked(i), i);
}

true
}

}

0 comments on commit 974a509

Please sign in to comment.