From 10eb3f1220d06c3fa68de0313c69f24b03bc2b17 Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:17:51 +0200 Subject: [PATCH] feat: ACLs e2e test (#76) * feat: acl e2e test * fix: setup private key * fix: comments * fix: comments * fix: comments --- test/access-list-e2e.bats | 121 ++++++++++++++++++++++++++++++++++++++ test/helpers/common.bash | 1 + 2 files changed, 122 insertions(+) create mode 100644 test/access-list-e2e.bats diff --git a/test/access-list-e2e.bats b/test/access-list-e2e.bats new file mode 100644 index 00000000..c47b004a --- /dev/null +++ b/test/access-list-e2e.bats @@ -0,0 +1,121 @@ +setup() { + load 'helpers/common-setup' + load 'helpers/common' + _common_setup + + readonly enclave=${ENCLAVE:-cdk-v1} + readonly sequencer=${KURTOSIS_NODE:-cdk-erigon-sequencer-001} + readonly node=${KURTOSIS_NODE:-cdk-erigon-node-001} + readonly rpc_url=${RPC_URL:-$(kurtosis port print "$enclave" "$node" http-rpc)} + readonly key=${SENDER_key:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} + readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} + readonly data_dir=${ACL_DATA_DIR:-"/home/erigon/data/dynamic-kurtosis-sequencer/txpool/acls"} + readonly kurtosis_sequencer_wrapper=${KURTOSIS_WRAPPER:-"kurtosis service exec $enclave $sequencer"} +} + +teardown() { + run set_acl_mode "disabled" +} + +# Helper function to add address to acl dynamically +add_to_access_list() { + local acl_type="$1" + local policy="$2" + local sender=$(cast wallet address "$key") + + run $kurtosis_sequencer_wrapper "acl add --datadir $data_dir --address $sender --type $acl_type --policy $policy" +} + +# Helper function to set the acl mode command dynamically +set_acl_mode() { + local mode="$1" + + run $kurtosis_sequencer_wrapper "acl mode --datadir $data_dir --mode $mode" +} + +@test "Test Block List - Sending regular transaction when address not in block list" { + local value="10ether" + run set_acl_mode "blocklist" + run sendTx $key $receiver $value + + assert_success + assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" +} + +@test "Test Block List - Sending contracts deploy transaction when address not in block list" { + local contract_artifact="./contracts/erc20mock/ERC20Mock.json" + run set_acl_mode "blocklist" + run deployContract $key $contract_artifact + + assert_success + + contract_addr=$(echo "$output" | tail -n 1) + assert_output --regexp "0x[a-fA-F0-9]{40}" +} + +@test "Test Block List - Sending regular transaction when address is in block list" { + local value="10ether" + + run set_acl_mode "blocklist" + run add_to_access_list "blocklist" "sendTx" + + run sendTx $key $receiver $value + + assert_failure + assert_output --partial "sender disallowed to send tx by ACL policy" +} + +@test "Test Block List - Sending contracts deploy transaction when address is in block list" { + local contract_artifact="./contracts/erc20mock/ERC20Mock.json" + + run set_acl_mode "blocklist" + run add_to_access_list "blocklist" "deploy" + run deployContract $key $contract_artifact + + assert_failure + assert_output --partial "sender disallowed to deploy contract by ACL policy" +} + +@test "Test Allow List - Sending regular transaction when address not in allow list" { + local value="10ether" + + run set_acl_mode "allowlist" + run sendTx $key $receiver $value + + assert_failure + assert_output --partial "sender disallowed to send tx by ACL policy" +} + +@test "Test Allow List - Sending contracts deploy transaction when address not in allow list" { + local contract_artifact="./contracts/erc20mock/ERC20Mock.json" + + run set_acl_mode "allowlist" + run deployContract $key $contract_artifact + + assert_failure + assert_output --partial "sender disallowed to deploy contract by ACL policy" +} + +@test "Test Allow List - Sending regular transaction when address is in allow list" { + local value="10ether" + + run set_acl_mode "allowlist" + run add_to_access_list "allowlist" "sendTx" + run sendTx $key $receiver $value + + assert_success + assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" +} + +@test "Test Allow List - Sending contracts deploy transaction when address is in allow list" { + local contract_artifact="./contracts/erc20mock/ERC20Mock.json" + + run set_acl_mode "allowlist" + run add_to_access_list "allowlist" "deploy" + run deployContract $key $contract_artifact + + assert_success + + contract_addr=$(echo "$output" | tail -n 1) + assert_output --regexp "0x[a-fA-F0-9]{40}" +} diff --git a/test/helpers/common.bash b/test/helpers/common.bash index 709bf843..15057d17 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -54,6 +54,7 @@ function deployContract() { if [[ -z "$deployed_contract_address" ]]; then echo "Error: Failed to extract deployed contract address" + echo "$cast_output" return 1 fi