Skip to content

Commit

Permalink
Merge pull request #2 from omnia-network/chore/migrate-tests-to-pocke…
Browse files Browse the repository at this point in the history
…t-ic

Migrate integration tests to pocket-ic
  • Loading branch information
ilbertt authored Nov 2, 2023
2 parents 312e59c + 8b72aae commit f16f8b5
Show file tree
Hide file tree
Showing 48 changed files with 2,316 additions and 27,184 deletions.
22 changes: 5 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
cache-dependency-path: "tests/package-lock.json"
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.69.0
- uses: aviate-labs/[email protected]
with:
dfx-version: 0.14.1
toolchain: "stable"
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Run unit tests
run: cargo test
- name: Install dependencies for integration tests
run: cd tests && npm install
run: cargo test -p ic-websocket-cdk
- name: Prepare environment for integration tests
run: |
cd tests
rustup target add wasm32-unknown-unknown
dfx start --clean --background
npm run deploy:tests
npm run generate
./scripts/download-pocket-ic.sh
./scripts/build-test-canister.sh
- name: Run integration tests
run: cd tests && npm run test:integration
run: POCKET_IC_BIN="$(pwd)/bin/pocket-ic" cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
!.vscode/settings.json

target
node_modules
.dfx
dist
declarations
.env

# the binary file needed for tests
pocket-ic
110 changes: 105 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
members = [
"src/ic-websocket-cdk",
"tests",
"src/test_canister",
]
resolver = "2"

Expand Down
1 change: 1 addition & 0 deletions bin/test_canister.wasm
3 changes: 3 additions & 0 deletions scripts/build-test-canister.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

cargo build --locked --target wasm32-unknown-unknown --release --package test_canister
18 changes: 18 additions & 0 deletions scripts/download-pocket-ic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

cd bin/

POCKET_IC_BIN=pocket-ic
if [ -f "$POCKET_IC_BIN" ]; then
echo -e "$POCKET_IC_BIN exists. Path: $(pwd)/$POCKET_IC_BIN\n"
else
echo "$POCKET_IC_BIN does not exist."
echo "Downloading Pocket IC binary..."
curl -sLO https://download.dfinity.systems/ic/307d5847c1d2fe1f5e19181c7d0fcec23f4658b3/openssl-static-binaries/x86_64-linux/pocket-ic.gz

echo "Extracting Pocket IC binary..."
gzip -d $POCKET_IC_BIN.gz
chmod +x $POCKET_IC_BIN

echo -e "Pocket IC binary downloaded and extracted successfully! Path: $(pwd)/$POCKET_IC_BIN\n"
fi
16 changes: 4 additions & 12 deletions scripts/test_canister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
set -e

# unit tests
cargo test -p ic-websocket-cdk

cd tests

npm install
cargo test --package ic-websocket-cdk --lib -- tests::unit_tests

# integration tests
dfx start --clean --background

npm run deploy:tests

npm run generate
./scripts/download-pocket-ic.sh

npm run test:integration
./scripts/build-test-canister.sh

dfx stop
POCKET_IC_BIN=$(pwd)/bin/pocket-ic RUST_BACKTRACE=1 cargo test --package ic-websocket-cdk --lib -- tests::integration_tests --test-threads 1
6 changes: 5 additions & 1 deletion src/ic-websocket-cdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ serde = { workspace = true }
serde_cbor = { workspace = true }
ic-certified-map = "0.4.0"
base64 = "0.21.2"
sha2 = "0.10.7"
sha2 = "0.10.8"
serde_bytes = "0.11.12"

[dev-dependencies]
ic-agent = "0.25.0"
proptest = "1.2.0"
rand = "0.8.5"
ring = "0.16.20"
lazy_static = "1.4.0"
pocket-ic = "1.0.0"
ic-certificate-verification = "1.2.0"
ic-certification = "1.2.0"

[package.metadata.docs.rs]
default-target = "wasm32-unknown-unknown"
23 changes: 23 additions & 0 deletions src/ic-websocket-cdk/service_messages.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type ClientPrincipal = principal;
type ClientKey = record {
client_principal : ClientPrincipal;
client_nonce : nat64;
};

type CanisterOpenMessageContent = record {
client_key : ClientKey;
};

type CanisterAckMessageContent = record {
last_incoming_sequence_num : nat64;
};

type ClientKeepAliveMessageContent = record {
last_incoming_sequence_num : nat64;
};

type WebsocketServiceMessageContent = variant {
OpenMessage : CanisterOpenMessageContent;
AckMessage : CanisterAckMessageContent;
KeepAliveMessage : ClientKeepAliveMessageContent;
};
Loading

0 comments on commit f16f8b5

Please sign in to comment.