From f5ca0841cbddad821cd82559a5b48022771e0b82 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 16 Dec 2024 13:53:52 -0500 Subject: [PATCH] Icepick Solana: Add End-to-End Tests --- e2e-tests/solana/README.md | 22 +++++++++++ e2e-tests/solana/base.Containerfile | 51 ++++++++++++++++++++++++++ e2e-tests/solana/offline.Containerfile | 10 +++++ e2e-tests/solana/offline.sh | 25 +++++++++++++ e2e-tests/solana/online.Containerfile | 8 ++++ e2e-tests/solana/online.sh | 32 ++++++++++++++++ e2e-tests/solana/run-offline.sh | 11 ++++++ e2e-tests/solana/run-online.sh | 14 +++++++ 8 files changed, 173 insertions(+) create mode 100644 e2e-tests/solana/README.md create mode 100644 e2e-tests/solana/base.Containerfile create mode 100644 e2e-tests/solana/offline.Containerfile create mode 100644 e2e-tests/solana/offline.sh create mode 100644 e2e-tests/solana/online.Containerfile create mode 100644 e2e-tests/solana/online.sh create mode 100644 e2e-tests/solana/run-offline.sh create mode 100644 e2e-tests/solana/run-online.sh diff --git a/e2e-tests/solana/README.md b/e2e-tests/solana/README.md new file mode 100644 index 0000000..36e6f01 --- /dev/null +++ b/e2e-tests/solana/README.md @@ -0,0 +1,22 @@ +# Solana End to End Tests + +This test demonstrates that Keyfork can be loaded, a key can be derived, and a +transaction can be performed using an SPL Token. + +We assume for these purposes that an account already exists with enough of the +token to be usable. The flow should be as follows: + +1. In one terminal, `run-offline.sh` should be started, with the mnemonic + entered, to emulate the procurement and operation of the Offline Machine and + the recovery of the shard. +2. In another terminal, `run-online.sh` should be started, with the + "sender address" being the address from the mnemonic, the "recipient + address" being the address of any other previously created account, the + token name being IPDBG or some other devnet token, and the token amount + being the amount to transfer - ideally a low amount. +3. Upon entering all the fields, the inputs should be transferred to the + offline "machine" for validation. Once validated, the offline machine will + derive the key, sign the transaction, and send it to the online machine for + transmission. +4. The online machine will return a signature that can be used to validate the + transaction on the Solana Devnet Blockchain Explorer. diff --git a/e2e-tests/solana/base.Containerfile b/e2e-tests/solana/base.Containerfile new file mode 100644 index 0000000..fa23b9b --- /dev/null +++ b/e2e-tests/solana/base.Containerfile @@ -0,0 +1,51 @@ +# vim: set ft=dockerfile: +FROM stagex/busybox:sx2024.11.0@sha256:3d128909dbc8e7b6c4b8c3c31f4583f01a307907ea179934bb42c4ef056c7efd AS busybox +FROM stagex/binutils:sx2024.11.0@sha256:eff721a796fdfba8c34e21a487b0e376fb55ca2633524926998f1660fbb810de AS binutils +FROM stagex/musl:sx2024.11.0@sha256:d7f6c365f5724c65cadb2b96d9f594e46132ceb366174c89dbf7554897f2bc53 AS musl +FROM stagex/rust:sx2024.11.0@sha256:f23fa04c29ab0250b39c38ee1cc4394a1ea3ec91b865070716a585d2b96389ed AS rust +FROM stagex/gcc:sx2024.11.0@sha256:49ea63c81c65f8be25c242b7e64f2758b23effdaafb458b5862d0f23ec803075 AS gcc +FROM stagex/llvm:sx2024.11.0@sha256:27da8a38ec621317dbafbf1dbdefb07a5b007d1d28ae86393480209652ed3770 AS llvm +FROM stagex/libunwind:sx2024.11.0@sha256:290b8d183a467edc55e338471632f2e40859aef92a4eecf12415ca29b9c16e9f AS libunwind +FROM stagex/openssl:sx2024.11.0@sha256:8e3eb24b4d21639f7ea204b89211d8bc03a2e1b729fb1123f8d0b3752b4beaa1 AS openssl +FROM stagex/zlib:sx2024.11.0@sha256:09d63654e27decb6147f1b23005d539e30db8e53eb2d284e824bcf4d4e7c3c11 AS zlib +FROM stagex/ca-certificates:sx2024.11.0@sha256:a84695f983a448a82acfe78af11f33c6a66b27124266e1fdc3ecfb8dc5852573 AS ca-certificates +FROM stagex/clang:sx2024.11.0@sha256:c26069d378f36c06b5d91e3aba907521ec79eb0864d65a4c28a2db17947ec25f AS clang +FROM stagex/pkgconf:sx2024.11.0@sha256:05b4ac6b931cd81fe5aff48c5a77bb9ae472e2bfbce3cc7d4698c670712d4409 AS pkgconf +FROM stagex/jq:sx2024.11.0@sha256:f54ab8399ca0b373d34a61e2aadd0bb28fac54841c9495043fd477316ceefd7c AS jq + +FROM scratch AS base + + +COPY --from=busybox . / +COPY --from=binutils . / +COPY --from=musl . / +COPY --from=rust . / +COPY --from=gcc . / +COPY --from=llvm . / +COPY --from=libunwind . / +COPY --from=openssl . / +COPY --from=zlib . / +COPY --from=ca-certificates . / +COPY --from=clang . / +COPY --from=pkgconf . / +COPY --from=jq . / + +COPY Cargo.toml /app/Cargo.toml +COPY Cargo.lock /app/Cargo.lock +COPY .cargo /app/.cargo +COPY crates /app/crates +COPY icepick.toml / +WORKDIR /app + +RUN cargo fetch --locked +RUN cargo build --frozen --release --target x86_64-unknown-linux-musl --bin icepick +RUN cargo build --frozen --release --target x86_64-unknown-linux-musl --bin icepick-sol +RUN < /data/output.json diff --git a/e2e-tests/solana/online.Containerfile b/e2e-tests/solana/online.Containerfile new file mode 100644 index 0000000..f6781ec --- /dev/null +++ b/e2e-tests/solana/online.Containerfile @@ -0,0 +1,8 @@ +# vim: set ft=dockerfile: + +FROM git.distrust.co/public/icepick-sol:base + +COPY e2e-tests/solana/online.sh /online.sh + +ENTRYPOINT ["/bin/sh"] +CMD ["/online.sh"] diff --git a/e2e-tests/solana/online.sh b/e2e-tests/solana/online.sh new file mode 100644 index 0000000..45ec5ed --- /dev/null +++ b/e2e-tests/solana/online.sh @@ -0,0 +1,32 @@ +printf "%s" "Public key of the sender address: " +read from_address + +printf "%s" "Public key of the recipient address: " +read to_address + +printf "%s" "Name of the token to transfer: " +read token_name + +printf "%s" "Amount of token to transfer: " +read token_amount + +echo "Acquiring blockhash..." +blockhash="$(icepick sol get-blockhash --cluster devnet | jq -r .blob)" + +echo "Saving information to file" + +cat < /data/input.json +{ + "from_address": "$from_address", + "to_address": "$to_address", + "token_name": "$token_name", + "token_amount": "$token_amount", + "blockhash": "$blockhash" +} +EOF + +echo "Waiting for signed transaction..." +while test ! -f /data/output.json; do sleep 1; done + +echo "Broadcasting transaction" +icepick sol broadcast --cluster devnet < /data/output.json diff --git a/e2e-tests/solana/run-offline.sh b/e2e-tests/solana/run-offline.sh new file mode 100644 index 0000000..e56b5cc --- /dev/null +++ b/e2e-tests/solana/run-offline.sh @@ -0,0 +1,11 @@ +set -eu +export DOCKER_BUILDKIT=1 + +image="git.distrust.co/public/icepick-sol" + +pushd "$(dirname $0)" +docker build -t "$image:base" -f base.Containerfile ../.. +docker build -t "$image:offline" -f offline.Containerfile ../.. + +mkdir -p data +docker run -it -v "$PWD/data:/data" "$image:offline" diff --git a/e2e-tests/solana/run-online.sh b/e2e-tests/solana/run-online.sh new file mode 100644 index 0000000..0680bc5 --- /dev/null +++ b/e2e-tests/solana/run-online.sh @@ -0,0 +1,14 @@ +set -eu +export DOCKER_BUILDKIT=1 + +image="git.distrust.co/public/icepick-sol" + +pushd "$(dirname $0)" +docker build -t "$image:base" -f base.Containerfile ../.. +docker build -t "$image:online" -f online.Containerfile ../.. + +mkdir -p data +# remove stale data if it exists +rm data/input.json || true +rm data/output.json || true +docker run -it -v "$PWD/data:/data" "$image:online"