From e594015286a3beb1cb4d2af37eef1fd5cec6826e Mon Sep 17 00:00:00 2001 From: jesse snyder Date: Fri, 30 Aug 2024 16:11:32 -0600 Subject: [PATCH] chore: ibc e2e smoke test (#1284) ## Summary Adds smoke test for end to end Celestia > Astria > EVM > back to Astria > Celestia bridging ## Background Smoke tests r gud ## Changes * Combines work from withdraw smoke tests and ibc bridging tests ## Testing This is the PR for the testing --------- Co-authored-by: Jordan Oroshiba --- charts/README.md | 15 +++ charts/ibc-test.just | 150 +++++++++++++++++++++++-- dev/kubetail.just | 22 ++++ dev/values/rollup/ibc-bridge-test.yaml | 21 ++++ justfile | 3 + 5 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 dev/kubetail.just diff --git a/charts/README.md b/charts/README.md index e2bafbf0e5..79a8648b6e 100644 --- a/charts/README.md +++ b/charts/README.md @@ -180,6 +180,21 @@ To deploy and run this: # Clean up deployed test ``` +## Running an IBC Smoke Test + +You can run a smoke test which ensures that full IBC bridge functionality is +working both up and down the stack. + +1. Bridges from Celestia to Astria to EVM +2. Withdraws from EVM to Astria to Celestia + +```sh +> just deploy cluster +> just ibc-test deploy +> just ibc-test run +> just ibc-test delete +``` + ## Examining Deployments [k9s](https://k9scli.io/) is a useful utility for inspecting deployed diff --git a/charts/ibc-test.just b/charts/ibc-test.just index c70db81001..b5538fdf02 100644 --- a/charts/ibc-test.just +++ b/charts/ibc-test.just @@ -1,3 +1,6 @@ +_default: + @just --list ibc-test + defaultTag := "" delete: @@ -37,16 +40,20 @@ run: set -e initial_balance=$(just evm-get-balance {{evm_destination_address}}) + initial_celestia_balance=$(just ibc-test get-celestia-balance) # Create a bridge account on the sequencer - just init-ibc-bridge {{ sequencer_tia_bridge_pkey }} transfer/channel-0/utia nria + just init-ibc-bridge {{sequencer_tia_bridge_pkey}} transfer/channel-0/utia nria # Execute the transfer from Celestia to the Rollup just ibc-test _do-ibc-transfer # Multiplication factor is 10^-6 (utia to tia) * 10^18 (rollup factor) = 10^12 - let expected_balance="$initial_balance + {{ transfer_amount }} * 10**12" + let expected_balance="$initial_balance + {{transfer_amount}} * 10**12" + # `bc` because very large number + expected_celestia_balance=$(echo "$initial_celestia_balance - {{transfer_amount}} - {{transfer_fees}}" | bc) + # check that evm balance updated correctly for i in {1..50} do current_balance=$(just evm-get-balance {{evm_destination_address}}) @@ -62,7 +69,78 @@ run: echo "expected balance was not found; IBC transfer from Celestia to the Rollup failed" exit 1 fi - + + # check that celestia balance updated correctly + for i in {1..50} + do + current_celestia_balance=$(just ibc-test get-celestia-balance) + echo "check $i, balance: $current_celestia_balance, expected: $expected_celestia_balance" + if (( $expected_celestia_balance == $current_celestia_balance )); then + expected_celestia_balance_found="1" + break + else + sleep 1 + fi + done + if [[ -z $expected_celestia_balance_found ]]; then + echo "expected celestia balance was not found after withdraw; IBC transfer from Celestia to the Rollup failed" + exit 1 + fi + + # test IBC withdrawal from the EVM to Celestia + initial_balance=$(just evm-get-balance {{evm_destination_address}}) + let expected_evm_balance="$initial_balance - 1000000000000" + + initial_celestia_balance=$(just ibc-test get-celestia-balance) + # `bc` because very large number + # WITHDRAW_AMOUNT / 10^(18-6) = 1 + expected_celestia_balance=$(echo "$initial_celestia_balance + 1" | bc) + echo "Initial Celestia balance $initial_celestia_balance" + + echo "Performing IBC withdrawal from the EVM to Celestia..." + just evm-send-raw-transaction {{evm_withdraw_tx_raw}} + + # check that evm balance updated correctly + for i in {1..50} + do + tx_receipt=$(just evm-get-transaction-receipt {{evm_withdraw_tx_hash}}) + if [[ $tx_receipt != "null" ]]; then + echo "Transaction receipt found: $tx_receipt" + tx_receipt_found="1" + current_balance=$(just evm-get-balance {{evm_destination_address}}) + if (( $expected_evm_balance == $current_balance )); then + echo "EVM balance updated correctly - expected: $expected_evm_balance, actual: $current_balance" + break + else + echo "EVM balance not updated correctly - expected: $expected_evm_balance, actual: $current_balance" + exit 1 + fi + break + else + sleep 1 + fi + done + if [[ -z $tx_receipt_found ]]; then + echo "Transaction receipt not found; IBC transfer from the Rollup to Celestia failed" + exit 1 + fi + + # check that celestia balance updated correctly + for i in {1..50} + do + current_celestia_balance=$(just ibc-test get-celestia-balance) + echo "check $i, balance: $current_celestia_balance, expected: $expected_celestia_balance" + if (( $expected_celestia_balance == $current_celestia_balance )); then + expected_celestia_balance_after_wd="1" + break + else + sleep 1 + fi + done + if [[ -z $expected_celestia_balance_after_wd ]]; then + echo "expected celestia balance was not found after withdraw; IBC transfer from the Rollup to Celestia failed" + exit 1 + fi bridge_address := "astria1d7zjjljc0dsmxa545xkpwxym86g8uvvwhtezcr" celestia_dev_account_address := "celestia1m0ksdjl2p5nzhqy3p47fksv52at3ln885xvl96" @@ -70,9 +148,22 @@ celestia_chain_id := "celestia-local-0" celestia_node_url := "http://rpc.app.celestia.localdev.me:80" sequencer_tia_bridge_pkey := "6015fbe1c365d3c5ef92dc891db8c5bb26ad454bec2db4762b96e9f8b2430285" keyring_backend := "test" +celestia_desitnation_address := "0x4a58639fb5458e65e4fa917ff951c390292c24a1" # This is the same address as used in deploy.just evm_destination_address := "0xaC21B97d35Bf75A7dAb16f35b111a50e78A72F30" +evm_rpc_url := "http://executor.astria.localdev.me" +evm_withdraw_tx_hash := "0x3f1a45c167fd147e92c8c9e0570eff7c4fbe7dc5ca7ce2a52a734f91cd6f72c3" +# evm_withdraw_tx_raw is the tx to the withdraw smart contract on the evm. +# Uses private key for 0xaC21B97d35Bf75A7dAb16f35b111a50e78A72F30 to sign tx. +# was created via: +# `forge script script/AstriaWithdrawer.s.sol:AstriaWithdrawerScript ... --sig "withdrawToIbcChain()"` +# w/ values: +# PRIVATE_KEY=0x8b3a7999072c9c9314c084044fe705db11714c6c4ed7cddb64da18ea270dd203 +# ASTRIA_WITHDRAWER=0xA58639fB5458e65E4fA917FF951C390292C24A15 +# ORIGIN_DESTINATION_CHAIN_ADDRESS=celestia1m0ksdjl2p5nzhqy3p47fksv52at3ln885xvl96 +# AMOUNT=1000000000000 +evm_withdraw_tx_raw := "0xf9012f80843b9aca07828fd794a58639fb5458e65e4fa917ff951c390292c24a1585e8d4a51000b8c4a996e020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002f63656c6573746961316d306b73646a6c3270356e7a68717933703437666b737635326174336c6e38383578766c393600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000820a95a04bc5ecc41a817099c62646713c907a302f0a81c879484f0d92fbc13d0d90d3c5a00da984f38e670402326f840dea26c5171557862aa16cfb5078d75627f6aea742" # all in units of utia transfer_amount := "53000" @@ -83,17 +174,54 @@ defaultNamespace := "astria-dev-cluster" [no-cd] _do-ibc-transfer namespace=defaultNamespace: echo "Performing IBC transfer..." - kubectl exec -n {{ namespace }} pods/celestia-local-0 celestia-app -- /bin/bash -c \ + kubectl exec -n {{namespace}} pods/celestia-local-0 celestia-app -- /bin/bash -c \ 'celestia-appd tx ibc-transfer transfer \ transfer \ channel-0 \ - {{ bridge_address }} \ - "{{ transfer_amount }}utia" \ - --memo="{\"rollupDepositAddress\":\"{{ evm_destination_address }}\"}" \ - --chain-id="{{ celestia_chain_id }}" \ - --from="{{ celestia_dev_account_address }}" \ - --fees="{{ transfer_fees }}utia" \ + {{bridge_address}} \ + "{{transfer_amount}}utia" \ + --memo="{\"rollupDepositAddress\":\"{{evm_destination_address}}\"}" \ + --chain-id="{{celestia_chain_id}}" \ + --from="{{celestia_dev_account_address}}" \ + --fees="{{transfer_fees}}utia" \ --yes \ --log_level=debug \ --home /home/celestia \ - --keyring-backend="{{ keyring_backend }}"' + --keyring-backend="{{keyring_backend}}"' + +get-celestia-balance address=celestia_dev_account_address namespace=defaultNamespace: + #!/usr/bin/env bash + balance=$(kubectl exec -n {{namespace}} pods/celestia-local-0 celestia-app -- /bin/bash -c \ + 'celestia-appd query bank balances --denom utia --output json {{address}}' | jq '.amount') + # remove quotes + balance=${balance//\"/} + echo $balance + +# helper command to call withdraw smart contract, in aid of getting its raw bytes for the tests. +_forge-ibc-withdraw: + #!/usr/bin/env bash + # This is a helper script to call the withdraw contract on the evm, b/c we want its raw bytes. + # Using the tx's raw bytes allows us to avoid the dependency on forge in ci/cd. + # + # NOTE - There is a .env in ../crates/astria-bridge-contracts/astria-bridge-contracts that needs to be populated correctly. + # + # NOTE - to get raw bytes, copy the success hash from the output, then: + # e.g. `just evm-get-raw-transaction 0x3f1a45c167fd147e92c8c9e0570eff7c4fbe7dc5ca7ce2a52a734f91cd6f72c3` + # This script called from `/charts/deploy.just, so cd'ing to contract directory + cd ../crates/astria-bridge-contracts/astria-bridge-contracts + pwd + echo "Calling withdraw contract using forge" + forge script script/AstriaWithdrawer.s.sol:AstriaWithdrawerScript \ + --rpc-url {{evm_rpc_url}} \ + --legacy \ + --broadcast \ + --sig "withdrawToIbcChain()" -vvvv + +# FIXME - delete after development +cb address=celestia_dev_account_address namespace=defaultNamespace: + kubectl exec -n {{namespace}} pods/celestia-local-0 celestia-app -- /bin/bash -c \ + 'celestia-appd query bank balances {{address}}' + +# init sequencer bridge account +init-bridge-acct: + just init-ibc-bridge {{sequencer_tia_bridge_pkey}} transfer/channel-0/utia nria diff --git a/dev/kubetail.just b/dev/kubetail.just new file mode 100644 index 0000000000..f444c3cae5 --- /dev/null +++ b/dev/kubetail.just @@ -0,0 +1,22 @@ +# commands to simplify Kubetail usage + +_default: + @just --list kubetail + +# add the kubetail chart repository +add-repo: + helm repo add kubetail https://kubetail-org.github.io/helm-charts/ + +# install kubetail chart +install: + # ensure the kubetail chart repository is added + just kubetail add-repo + helm install kubetail kubetail/kubetail --namespace kubetail --create-namespace + +# uninstall kubetail chart +uninstall: + helm uninstall -n kubetail kubetail + +# port forward the kubetail service so we can connect on our local machine +port-forward: + kubectl port-forward -n kubetail svc/kubetail 4000:80 diff --git a/dev/values/rollup/ibc-bridge-test.yaml b/dev/values/rollup/ibc-bridge-test.yaml index e438e19722..d46f911657 100644 --- a/dev/values/rollup/ibc-bridge-test.yaml +++ b/dev/values/rollup/ibc-bridge-test.yaml @@ -7,3 +7,24 @@ evm-rollup: startHeight: 1 assetDenom: "transfer/channel-0/utia" assetPrecision: 6 + alloc: + - address: "0x4e59b44847b379578588920cA78FbF26c0B4956C" + value: + balance: "0" + code: "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3" + # bridge withdrawer contract + - address: "0xA58639fB5458e65E4fA917FF951C390292C24A15" + value: + balance: "0" + code: "0x60806040526004361061004a5760003560e01c80637eb6dec71461004f578063a996e0201461009d578063b6476c7e146100b2578063bab916d0146100d4578063db97dc98146100e7575b600080fd5b34801561005b57600080fd5b506100837f000000000000000000000000000000000000000000000000000000000000000681565b60405163ffffffff90911681526020015b60405180910390f35b6100b06100ab366004610315565b6100fc565b005b3480156100be57600080fd5b506100c761019e565b6040516100949190610386565b6100b06100e23660046103d4565b61022c565b3480156100f357600080fd5b506100c76102bf565b3460006101297f000000000000000000000000000000000000000000000000000000e8d4a5100083610416565b1161014f5760405162461bcd60e51b815260040161014690610438565b60405180910390fd5b34336001600160a01b03167f0c64e29a5254a71c7f4e52b3d2d236348c80e00a00ba2e1961962bd2827c03fb8787878760405161018f94939291906104ef565b60405180910390a35050505050565b600180546101ab90610521565b80601f01602080910402602001604051908101604052809291908181526020018280546101d790610521565b80156102245780601f106101f957610100808354040283529160200191610224565b820191906000526020600020905b81548152906001019060200180831161020757829003601f168201915b505050505081565b3460006102597f000000000000000000000000000000000000000000000000000000e8d4a5100083610416565b116102765760405162461bcd60e51b815260040161014690610438565b34336001600160a01b03167f0f4961cab7530804898499aa89f5ec81d1a73102e2e4a1f30f88e5ae3513ba2a85856040516102b292919061055b565b60405180910390a3505050565b600080546101ab90610521565b60008083601f8401126102de57600080fd5b50813567ffffffffffffffff8111156102f657600080fd5b60208301915083602082850101111561030e57600080fd5b9250929050565b6000806000806040858703121561032b57600080fd5b843567ffffffffffffffff81111561034257600080fd5b61034e878288016102cc565b909550935050602085013567ffffffffffffffff81111561036e57600080fd5b61037a878288016102cc565b95989497509550505050565b602081526000825180602084015260005b818110156103b45760208186018101516040868401015201610397565b506000604082850101526040601f19601f83011684010191505092915050565b600080602083850312156103e757600080fd5b823567ffffffffffffffff8111156103fe57600080fd5b61040a858286016102cc565b90969095509350505050565b60008261043357634e487b7160e01b600052601260045260246000fd5b500490565b60208082526062908201527f417374726961576974686472617765723a20696e73756666696369656e74207660408201527f616c75652c206d7573742062652067726561746572207468616e203130202a2a60608201527f20283138202d20424153455f434841494e5f41535345545f505245434953494f6080820152614e2960f01b60a082015260c00190565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6040815260006105036040830186886104c6565b82810360208401526105168185876104c6565b979650505050505050565b600181811c9082168061053557607f821691505b60208210810361055557634e487b7160e01b600052602260045260246000fd5b50919050565b60208152600061056f6020830184866104c6565b94935050505056fea2646970667358221220b73dc5c9f22e03fd058515a01358b35c200504a51138854bd076ae6e13d4bfce64736f6c634300081a0033" + +evm-bridge-withdrawer: + enabled: true + config: + minExpectedFeeAssetBalance: "0" + sequencerBridgeAddress: "astria1d7zjjljc0dsmxa545xkpwxym86g8uvvwhtezcr" + feeAssetDenom: "nria" + rollupAssetDenom: "transfer/channel-0/utia" + evmContractAddress: "0xA58639fB5458e65E4fA917FF951C390292C24A15" + sequencerPrivateKey: + devContent: "6015fbe1c365d3c5ef92dc891db8c5bb26ad454bec2db4762b96e9f8b2430285" diff --git a/justfile b/justfile index b9a98f653a..a412fbd7b4 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,8 @@ import 'charts/deploy.just' +# commands to simplify Kubetail usage +mod kubetail 'dev/kubetail.just' + default: @just --list