-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'maciej-upgradetest' into 'master'
feat(icp_ledger): update upgrade testing scripts to work with the new testnet infrastructure and add tests for icrc2 endpoints I also updated the guide: https://www.notion.so/dfinityorg/Test-ICP-Ledger-Archive-Upgrade-1176e13ae416424a80ed19e186af4a74 See merge request dfinity-lab/public/ic!15429
- Loading branch information
Showing
5 changed files
with
164 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Submit an upgrade proposal to the NNS. | ||
|
||
set -euo pipefail | ||
#set -x | ||
|
||
if (($# != 0)); then | ||
echo >&2 "Usage: $0" | ||
exit 1 | ||
fi | ||
|
||
LEDGER_CANISTER_ID="ryjl3-tyaaa-aaaaa-aaaba-cai" | ||
ARCHIVE_CANISTER_ID="qjdve-lqaaa-aaaaa-aaaeq-cai" | ||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
LEDGER_DID="$SCRIPT_DIR/../icp_ledger/ledger.did" | ||
TMP_DIR="$SCRIPT_DIR/tmp" # need a persistent directory from within dev container | ||
NUM_OF_BATCHES=50 | ||
NUM_OF_APPROVALS_PER_BATCH=21 # 100 fails for some reason related to the testnet setup | ||
HOME="${DFX_HOME:-$HOME}" | ||
|
||
NNS_TEST_ID="nns_test_user_dfx_identity" | ||
dfx identity use "$NNS_TEST_ID" | ||
|
||
SPENDER_1_PRINCIPAL="pcwbg-y26mf-k62dw-7xo2m-jfv2n-un56b-pjkp7-oirek-obdjm-bklck-2ae" | ||
SPENDER_2_PRINCIPAL="tcpbp-bppbk-ac6zu-smi7p-opmky-qjuez-ugxzv-v33ci-vod7y-kpktd-kae" | ||
SPENDER_3_PRINCIPAL="xnrq6-gadm3-6ious-kx6kn-utuqf-iphoq-vrag4-rlfvt-5z7n7-52n4q-vae" | ||
|
||
query_blocks_res=$(dfx canister --network $NNS_URL call --candid "$LEDGER_DID" --query "$LEDGER_CANISTER_ID" query_blocks '(record {start=0:nat64;length=1:nat64})') | ||
BEFORE_CHAIN_LENGTH=$(echo $query_blocks_res | sed -n 's/.*chain_length *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
BEFORE_FIRST_BLOCK_INDEX=$(echo $query_blocks_res | sed -n 's/.*first_block_index *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
|
||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_approve "(record {spender=record {owner=principal \"$SPENDER_2_PRINCIPAL\"}; amount=200:nat},)" | ||
|
||
EXPIRATION=2993656999000000000 # expiration far in the future | ||
|
||
for ((batch = 0; batch < $NUM_OF_BATCHES; batch++)); do | ||
echo "start sending batch $((batch + 1))/$NUM_OF_BATCHES of $NUM_OF_APPROVALS_PER_BATCH txs" | ||
for ((t = 0; t < $NUM_OF_APPROVALS_PER_BATCH; t++)); do | ||
case $(($t % 3)) in | ||
|
||
0) | ||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_approve "(record {spender=record {owner=principal \"$SPENDER_1_PRINCIPAL\"}; amount=100:nat},)" & | ||
;; | ||
|
||
1) | ||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_approve "(record {spender=record {owner=principal \"$SPENDER_2_PRINCIPAL\"}; amount=200:nat; expected_allowance=opt 200},)" & | ||
;; | ||
|
||
2) | ||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_approve "(record {spender=record {owner=principal \"$SPENDER_3_PRINCIPAL\"}; amount=300:nat; expires_at=opt $EXPIRATION},)" & | ||
let "EXPIRATION += 1" | ||
;; | ||
|
||
esac | ||
done | ||
wait | ||
echo "done sending batch $((batch + 1))/$NUM_OF_BATCHES of $NUM_OF_APPROVALS_PER_BATCH txs" | ||
done | ||
|
||
query_blocks_res=$(dfx canister --network $NNS_URL call --candid "$LEDGER_DID" --query "$LEDGER_CANISTER_ID" query_blocks '(record {start=0:nat64;length=1:nat64})') | ||
AFTER_CHAIN_LENGTH=$(echo $query_blocks_res | sed -n 's/.*chain_length *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
AFTER_FIRST_BLOCK_INDEX=$(echo $query_blocks_res | sed -n 's/.*first_block_index *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
|
||
DELTA=$(($NUM_OF_BATCHES * $NUM_OF_APPROVALS_PER_BATCH + 1)) | ||
EXPECTED_AFTER_CHAIN_LENGTH=$(($BEFORE_CHAIN_LENGTH + $DELTA)) | ||
if (($AFTER_CHAIN_LENGTH < $EXPECTED_AFTER_CHAIN_LENGTH)); then | ||
echo >&2 "The chain_length should have increased of $DELTA transactions but it is not. before:$BEFORE_CHAIN_LENGTH after:$AFTER_CHAIN_LENGTH" | ||
exit 2 | ||
fi | ||
|
||
if [ $BEFORE_FIRST_BLOCK_INDEX -eq $AFTER_FIRST_BLOCK_INDEX ]; then | ||
echo "Warning: no archival happened" | ||
fi | ||
|
||
echo "Approval test completed successfully!" |
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,73 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Submit an upgrade proposal to the NNS. | ||
|
||
set -euo pipefail | ||
#set -x | ||
|
||
if (($# != 0)); then | ||
echo >&2 "Usage: $0" | ||
exit 1 | ||
fi | ||
|
||
LEDGER_CANISTER_ID="ryjl3-tyaaa-aaaaa-aaaba-cai" | ||
ARCHIVE_CANISTER_ID="qjdve-lqaaa-aaaaa-aaaeq-cai" | ||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
LEDGER_DID="$SCRIPT_DIR/../icp_ledger/ledger.did" | ||
TMP_DIR="$SCRIPT_DIR/tmp" # need a persistent directory from within dev container | ||
NUM_OF_BATCHES=3 | ||
NUM_OF_TRANSFERS_PER_BATCH=20 # 100 fails for some reason related to the testnet setup | ||
AMOUNT_PER_TRANSFER="1:nat" | ||
AMOUNT_PER_APPROVAL="1000000000:nat" | ||
HOME="${DFX_HOME:-$HOME}" | ||
|
||
NNS_TEST_ID="nns_test_user_dfx_identity" | ||
dfx identity use "$NNS_TEST_ID" | ||
NNS_TEST_PRINCIPAL=$(dfx identity get-principal) | ||
|
||
query_blocks_res=$(dfx canister --network $NNS_URL call --candid "$LEDGER_DID" --query "$LEDGER_CANISTER_ID" query_blocks '(record {start=0:nat64;length=1:nat64})') | ||
BEFORE_CHAIN_LENGTH=$(echo $query_blocks_res | sed -n 's/.*chain_length *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
BEFORE_FIRST_BLOCK_INDEX=$(echo $query_blocks_res | sed -n 's/.*first_block_index *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
|
||
SPENDER_ID="spender_id" | ||
SPENDER_ID_HOME_DIR="$DFX_HOME/.config/dfx/identity/$SPENDER_ID" | ||
|
||
if [ -d "$SPENDER_ID_HOME_DIR" ]; then | ||
echo "Found $SPENDER_ID identity in $SPENDER_ID_HOME_DIR" | ||
else | ||
echo "No identity directory found, I'm going to create a new $SPENDER_ID identity and persist it" | ||
dfx identity new "$SPENDER_ID" --disable-encryption | ||
fi | ||
dfx identity use "$SPENDER_ID" | ||
SPENDER_PRINCIPAL=$(dfx identity get-principal) | ||
|
||
dfx identity use "$NNS_TEST_ID" | ||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_approve "(record {spender=record {owner=principal \"$SPENDER_PRINCIPAL\"}; amount=$AMOUNT_PER_APPROVAL},)" | ||
|
||
dfx identity use "$SPENDER_ID" | ||
|
||
for ((batch = 0; batch < $NUM_OF_BATCHES; batch++)); do | ||
echo "start sending batch $((batch + 1))/$NUM_OF_BATCHES of $NUM_OF_TRANSFERS_PER_BATCH txs" | ||
for ((t = 0; t < $NUM_OF_TRANSFERS_PER_BATCH; t++)); do | ||
dfx canister call --candid "$LEDGER_DID" --network "$NNS_URL" "$LEDGER_CANISTER_ID" icrc2_transfer_from "(record {from=record {owner=principal \"$NNS_TEST_PRINCIPAL\"}; to=record {owner=principal \"$SPENDER_PRINCIPAL\"}; amount=$AMOUNT_PER_TRANSFER},)" & | ||
done | ||
wait | ||
echo "done sending batch $((batch + 1))/$NUM_OF_BATCHES of $NUM_OF_TRANSFERS_PER_BATCH txs" | ||
done | ||
|
||
query_blocks_res=$(dfx canister --network $NNS_URL call --candid "$LEDGER_DID" --query "$LEDGER_CANISTER_ID" query_blocks '(record {start=0:nat64;length=1:nat64})') | ||
AFTER_CHAIN_LENGTH=$(echo $query_blocks_res | sed -n 's/.*chain_length *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
AFTER_FIRST_BLOCK_INDEX=$(echo $query_blocks_res | sed -n 's/.*first_block_index *= *\([^ ]\+\).*/\1/p' | tr -d '_') | ||
|
||
DELTA=$(($NUM_OF_BATCHES * $NUM_OF_TRANSFERS_PER_BATCH + 1)) | ||
EXPECTED_AFTER_CHAIN_LENGTH=$(($BEFORE_CHAIN_LENGTH + $DELTA)) | ||
if (($AFTER_CHAIN_LENGTH < $EXPECTED_AFTER_CHAIN_LENGTH)); then | ||
echo >&2 "The chain_length should have increased of $DELTA transactions but it is not. before:$BEFORE_CHAIN_LENGTH after:$AFTER_CHAIN_LENGTH" | ||
exit 2 | ||
fi | ||
|
||
if [ $BEFORE_FIRST_BLOCK_INDEX -eq $AFTER_FIRST_BLOCK_INDEX ]; then | ||
echo "Warning: no archival happened" | ||
fi | ||
|
||
echo "Transfers from test completed successfully!" |
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