-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPROD-381 integration tests for stable structures
- Loading branch information
Showing
29 changed files
with
1,060 additions
and
60 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
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,41 +1,47 @@ | ||
{ | ||
"canisters": { | ||
"canister-a": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister_a/canister_a.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister_a.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-b": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister_b/canister_b.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister_b.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-c": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister-c/canister-c.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister-c.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-d": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister-d/canister-d.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister-d.wasm", | ||
"type": "custom" | ||
}, | ||
"log_canister": { | ||
"candid": "ic-log/examples/log_canister.did", | ||
"build": "bash scripts/build_log_canister.sh", | ||
"wasm": "target/wasm32-unknown-unknown/release/examples/log_canister.wasm", | ||
"type": "custom" | ||
} | ||
}, | ||
"networks": { | ||
"local": { | ||
"bind": "127.0.0.1:8000", | ||
"type": "ephemeral" | ||
} | ||
}, | ||
"version": 1 | ||
} | ||
"canisters": { | ||
"canister-a": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister_a/canister_a.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister_a.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-b": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister_b/canister_b.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister_b.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-c": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister-c/canister-c.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister-c.wasm", | ||
"type": "custom" | ||
}, | ||
"canister-d": { | ||
"build": "bash scripts/build.sh", | ||
"candid": "ic-canister/tests/canister-d/canister-d.did", | ||
"wasm": "target/wasm32-unknown-unknown/release/canister-d.wasm", | ||
"type": "custom" | ||
}, | ||
"dummy_canister": { | ||
"candid": "ic-stable-structures/tests/dummy_canister/dummy_canister.did", | ||
"build": "bash scripts/build_dummy_canister.sh", | ||
"wasm": "target/wasm32-unknown-unknown/release/dummy_canister.wasm", | ||
"type": "custom" | ||
}, | ||
"log_canister": { | ||
"candid": "ic-log/examples/log_canister.did", | ||
"build": "bash scripts/build_log_canister.sh", | ||
"wasm": "target/wasm32-unknown-unknown/release/examples/log_canister.wasm", | ||
"type": "custom" | ||
} | ||
}, | ||
"networks": { | ||
"local": { | ||
"bind": "127.0.0.1:8000", | ||
"type": "ephemeral" | ||
} | ||
}, | ||
"version": 1 | ||
} |
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,17 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
export PROTOC_INCLUDE=${PWD}/../ | ||
|
||
# Get example icrc1 canister | ||
if [ ! -f ic-payments/tests/common/ic-icrc1-ledger.wasm ]; then | ||
export IC_VERSION=b43543ce7365acd1720294e701e8e8361fa30c8f | ||
curl -o ic-icrc1-ledger.wasm.gz https://download.dfinity.systems/ic/${IC_VERSION}/canisters/ic-icrc1-ledger.wasm.gz | ||
gunzip ic-icrc1-ledger.wasm.gz | ||
mv ic-icrc1-ledger.wasm ic-payments/tests/common/ | ||
fi | ||
|
||
# Build test payment canister | ||
cargo build --target wasm32-unknown-unknown --features export-api -p test-payment-canister --release | ||
ic-wasm target/wasm32-unknown-unknown/release/test_payment_canister.wasm -o ic-payments/tests/common/payment_canister.wasm shrink |
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,22 +1,10 @@ | ||
#!/bin/sh | ||
|
||
# Example script to run the state_machine tests. To make it work, replace | ||
# the location of google protobuf repo in your system. You can find the | ||
# needed repo at https://github.com/protocolbuffers/protobuf/tree/main/src/google/protobuf | ||
|
||
set -e | ||
|
||
export PROTOC_INCLUDE=${PWD}/../ | ||
|
||
# Get example icrc1 canister | ||
if [ ! -f ic-payments/tests/common/ic-icrc1-ledger.wasm ]; then | ||
export IC_VERSION=b43543ce7365acd1720294e701e8e8361fa30c8f | ||
curl -o ic-icrc1-ledger.wasm.gz https://download.dfinity.systems/ic/${IC_VERSION}/canisters/ic-icrc1-ledger.wasm.gz | ||
gunzip ic-icrc1-ledger.wasm.gz | ||
mv ic-icrc1-ledger.wasm ic-payments/tests/common/ | ||
fi | ||
|
||
# Build test payment canister | ||
cargo build --target wasm32-unknown-unknown --features export-api -p test-payment-canister --release | ||
ic-wasm target/wasm32-unknown-unknown/release/test_payment_canister.wasm -o ic-payments/tests/common/payment_canister.wasm shrink | ||
./build_payments_canister.sh | ||
|
||
# Run the test | ||
cargo +nightly test -p ic-payments --features state-machine |
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
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
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,12 @@ | ||
[package] | ||
name = "did" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
||
[dependencies] | ||
candid = { workspace = true } | ||
ic-stable-structures = { path = "../../../ic-stable-structures" } | ||
serde = { workspace = true } |
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,36 @@ | ||
use candid::{CandidType, Decode, Deserialize, Encode}; | ||
use ic_stable_structures::{BoundedStorable, ChunkSize, SlicedStorable, Storable}; | ||
|
||
pub fn encode(item: &impl CandidType) -> Vec<u8> { | ||
Encode!(item).expect("failed to encode item to candid") | ||
} | ||
|
||
pub fn decode<'a, T: CandidType + Deserialize<'a>>(bytes: &'a [u8]) -> T { | ||
Decode!(bytes, T).expect("failed to decode item from candid") | ||
} | ||
|
||
#[derive(Debug, Default, Clone, Copy, CandidType, Deserialize)] | ||
pub struct Transaction { | ||
pub from: u8, | ||
pub to: u8, | ||
pub value: u8, | ||
} | ||
|
||
impl Storable for Transaction { | ||
fn to_bytes(&self) -> std::borrow::Cow<[u8]> { | ||
encode(self).into() | ||
} | ||
|
||
fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self { | ||
decode(&bytes) | ||
} | ||
} | ||
|
||
impl SlicedStorable for Transaction { | ||
const CHUNK_SIZE: ChunkSize = 8; | ||
} | ||
|
||
impl BoundedStorable for Transaction { | ||
const MAX_SIZE: u32 = 32; | ||
const IS_FIXED_SIZE: bool = false; | ||
} |
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 @@ | ||
!dummy_canister.did |
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,20 @@ | ||
[package] | ||
name = "dummy_canister" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[features] | ||
default = [] | ||
export-api = [] | ||
|
||
[dependencies] | ||
candid = { workspace = true } | ||
did = { path = "../did" } | ||
ic-canister = { path = "../../../ic-canister/ic-canister" } | ||
ic-cdk = { workspace = true } | ||
ic-exports = { path = "../../../ic-exports" } | ||
ic-stable-structures = { path = "../../../ic-stable-structures" } | ||
serde = { workspace = true } | ||
|
||
[dev-dependencies] | ||
tokio = { workspace = true, features = ["rt", "macros"] } |
15 changes: 15 additions & 0 deletions
15
ic-stable-structures/tests/dummy_canister/dummy_canister.did
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 @@ | ||
type Transaction = record { to : nat8; value : nat8; from : nat8 }; | ||
service : () -> { | ||
get_tx_from_btreemap : (nat64) -> (opt Transaction) query; | ||
get_tx_from_cell : () -> (Transaction) query; | ||
get_tx_from_log : (nat64) -> (opt Transaction) query; | ||
get_tx_from_map : (nat64) -> (opt Transaction) query; | ||
get_tx_from_multimap : (nat64) -> (opt Transaction) query; | ||
get_tx_from_vec : (nat64) -> (opt Transaction) query; | ||
insert_tx_to_btreemap : (Transaction) -> (nat64); | ||
insert_tx_to_cell : (Transaction) -> (); | ||
insert_tx_to_map : (Transaction) -> (nat64); | ||
insert_tx_to_multimap : (Transaction) -> (nat64); | ||
push_tx_to_log : (Transaction) -> (nat64); | ||
push_tx_to_vec : (Transaction) -> (nat64); | ||
} |
Oops, something went wrong.