Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/consumer rewards e2e #301

Open
wants to merge 22 commits into
base: base/consumer-chain-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
41284f3
Fix: Consumer integration e2e test deps
maurolacy Nov 20, 2024
427dc45
Fix: e2e test targets
maurolacy Nov 20, 2024
bd8c221
Disable broken / failing e2e tests from e2e target
maurolacy Nov 20, 2024
63f33d0
Update copy / download contracts scripts
maurolacy Nov 20, 2024
53c3f30
Update contracts to latest v0.11.0
maurolacy Nov 20, 2024
b5b2d6a
Update babylon-sdk tag to (WIP) rewards e2e branch
maurolacy Nov 20, 2024
66ce706
Add babylon-sdk as sub-module
maurolacy Nov 21, 2024
326ec1e
Use babylon-sdk submodule ref during ibcsim-bcd build
maurolacy Nov 21, 2024
b2e98f0
Add finality contract to e2e test setup
maurolacy Nov 22, 2024
f7e6b4f
Improve flaky IBC transfer back checks
maurolacy Nov 22, 2024
9db92ee
Clean network before staking tests
maurolacy Nov 22, 2024
837cd10
Add consumer rewards test to bcd suite
maurolacy Nov 22, 2024
06a6aec
Update rewards e2e branch to latest
maurolacy Nov 23, 2024
21e977a
Rename to cc for consistency
maurolacy Nov 24, 2024
ce11ec8
Add balance / balances grpc queries to consumer controller
maurolacy Nov 24, 2024
8506e9e
Revert "Add consumer rewards test to bcd suite"
maurolacy Nov 24, 2024
75482f0
Now add consumer rewards test to bcd suite
maurolacy Nov 25, 2024
45059e0
Revert "Now add consumer rewards test to bcd suite"
maurolacy Nov 25, 2024
44917f0
Now really add consumer rewards test to bcd suite
maurolacy Nov 25, 2024
bfa37b7
Update rewards e2e branch to latest
maurolacy Nov 25, 2024
b5325e9
Add extra empty rewards check
maurolacy Nov 25, 2024
75f0103
Remove TODO
maurolacy Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "babylon-sdk"]
path = babylon-sdk
url = https://github.com/babylonlabs-io/babylon-sdk
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,31 +263,38 @@ endif

test-e2e: build-docker-e2e test-e2e-cache


test-e2e-cache:
go test -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-bcd-consumer-integration:
$(MAKE) test-e2e-cache-btc-timestamping
$(MAKE) test-e2e-cache-btc-staking
# $(MAKE) test-e2e-cache-btc-staking-integration
$(MAKE) clean-e2e
$(MAKE) test-e2e-cache-btc-staking-pre-approval
$(MAKE) test-e2e-cache-ibc-transfer
$(MAKE) test-e2e-cache-bcd-consumer-integration
# $(MAKE) test-e2e-cache-upgrade-v1

clean-e2e:
docker container rm -f $(shell docker container ls -a -q) || true
docker network prune -f || true

test-e2e-cache-bcd-consumer-integration: start-bcd-consumer-integration
go test -run TestBCDConsumerIntegrationTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-ibc-transfer:
go test -run TestIBCTranferTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-timestamping:
go test -run TestBTCTimestampingTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-timestamping-phase-2-hermes:
go test -run TestBTCTimestampingPhase2HermesTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-timestamping-phase-2-rly:
go test -run TestBTCTimestampingPhase2RlyTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-staking:
go test -run TestBTCStakingTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-staking-integration:
go test -run TestBTCStakingIntegrationTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-btc-staking-pre-approval:
go test -run TestBTCStakingPreApprovalTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-ibc-transfer:
go test -run TestIBCTranferTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

test-e2e-cache-upgrade-v1:
go test -run TestSoftwareUpgradeV1TestnetTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e

Expand Down Expand Up @@ -444,8 +451,11 @@ build-docker-e2e:
build-cosmos-relayer-docker: ## Build Docker image for the Cosmos relayer
$(MAKE) -C contrib/images cosmos-relayer

start-bcd-consumer-integration:
$(MAKE) -C contrib/images start-bcd-consumer-integration

clean-docker-network:
$(DOCKER) network rm ${dockerNetworkList}
$(DOCKER) network rm ${dockerNetworkList} || true

build-test-wasm: ## Build WASM bindings for testing
$(DOCKER) run --rm -v "$(WASM_DIR)":/code \
Expand Down
1 change: 1 addition & 0 deletions babylon-sdk
Submodule babylon-sdk added at b21575
5 changes: 4 additions & 1 deletion contrib/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ cosmos-relayer-rmi:
docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true

build-ibcsim-bcd:
docker build --tag babylonlabs-io/ibcsim-bcd -f ibcsim-bcd/Dockerfile ${BABYLON_FULL_PATH}
cp -a $(BABYLON_FULL_PATH)/babylon-sdk/ $(BABYLON_FULL_PATH)/contrib/images/ibcsim-bcd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt we use git clone for getting babylon-sdk repo to a gitignore-ed directory, instead of a submodule? suggesting this as submodules are quite troublesome due to those git submodule init and git submodule update stuff

docker build --tag babylonlabs-io/ibcsim-bcd -f ibcsim-bcd/Dockerfile \
$(BABYLON_FULL_PATH)/contrib/images/ibcsim-bcd
rm -rf $(BABYLON_FULL_PATH)/contrib/images/ibcsim-bcd/babylon-sdk

ibcsim-bcd-rmi:
docker rmi babylonlabs-io/ibcsim-bcd 2>/dev/null; true
Expand Down
17 changes: 7 additions & 10 deletions contrib/images/ibcsim-bcd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ WORKDIR /work

ENV GO111MODULE on
ENV RELAYER_TAG v2.5.2
ENV BABYLON_SDK_TAG v0.3.0-rc.0

# Install the relayer
RUN git clone https://github.com/cosmos/relayer.git
RUN cd relayer && git fetch origin && git checkout ${RELAYER_TAG} && make install && cd -

# Install bcd
RUN git clone https://github.com/babylonlabs-io/babylon-sdk.git && \
cd babylon-sdk && \
git checkout ${BABYLON_SDK_TAG} && \
make install && \
cd -
ADD babylon-sdk /work/babylon-sdk
RUN cd babylon-sdk && make install && cd -

FROM debian:bullseye-slim AS run

Expand All @@ -53,10 +49,11 @@ COPY --from=build-env /go/bin/rly /usr/bin/rly
COPY --from=build-env /go/bin/bcd /usr/bin/bcd

WORKDIR /ibcsim-bcd
COPY contrib/images/ibcsim-bcd/wrapper.sh /ibcsim-bcd/wrapper.sh
COPY contrib/images/ibcsim-bcd/setup-bcd.sh /ibcsim-bcd/setup-bcd.sh
COPY test/e2e/bytecode/babylon_contract.wasm /ibcsim-bcd/babylon_contract.wasm
COPY test/e2e/bytecode/btc_staking.wasm /ibcsim-bcd/btc_staking.wasm
COPY wrapper.sh /ibcsim-bcd/wrapper.sh
COPY setup-bcd.sh /ibcsim-bcd/setup-bcd.sh
COPY --from=build-env /work/babylon-sdk/tests/testdata/babylon_contract.wasm /ibcsim-bcd/babylon_contract.wasm
COPY --from=build-env /work/babylon-sdk/tests/testdata/btc_staking.wasm /ibcsim-bcd/btc_staking.wasm
COPY --from=build-env /work/babylon-sdk/tests/testdata/btc_finality.wasm /ibcsim-bcd/btc_finality.wasm

ENV BABYLON_HOME=/data/node1/babylond
ENV BABYLON_NODE_RPC="http://babylondnode1:26657"
Expand Down
39 changes: 20 additions & 19 deletions contrib/images/ibcsim-bcd/setup-bcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

display_usage() {
echo "Missing parameters. Please check if all parameters were specified."
echo "Usage: setup-bcd.sh [CHAIN_ID] [CHAIN_DIR] [RPC_PORT] [P2P_PORT] [PROFILING_PORT] [GRPC_PORT] [BABYLON_CONTRACT_CODE_DIR] [BTCSTAKING_CONTRACT_CODE_DIR] [INSTANTIATING_CFG]"
echo "Usage: setup-bcd.sh [CHAIN_ID] [CHAIN_DIR] [RPC_PORT] [P2P_PORT] [PROFILING_PORT] [GRPC_PORT] [BABYLON_CONTRACT_CODE_FILE] [BTCSTAKING_CONTRACT_CODE_FILE] [BTCFINALITY_CONTRACT_CODE_FILE] [INSTANTIATING_CFG]"
echo "Example: setup-bcd.sh test-chain-id ./data 26657 26656 6060 9090 ./babylon_contract.wasm '{"btc_confirmation_depth":1,"checkpoint_finalization_timeout":2,"network":"Regtest","babylon_tag":"bbn0", "notify_cosmos_zone":false, "btc_staking_code_id":2}'"
exit 1
}
Expand All @@ -21,7 +21,7 @@ redirect() {
fi
}

if [ "$#" -lt "8" ]; then
if [ "$#" -lt "9" ]; then
display_usage
exit 1
fi
Expand All @@ -32,9 +32,10 @@ RPCPORT=$3
P2PPORT=$4
PROFPORT=$5
GRPCPORT=$6
BABYLON_CONTRACT_CODE_DIR=$7
BTCSTAKING_CONTRACT_CODE_DIR=$8
INSTANTIATING_CFG=$9
BABYLON_CONTRACT_CODE_FILE=$7
BTCSTAKING_CONTRACT_CODE_FILE=$8
BTCFINALITY_CONTRACT_CODE_FILE=$9
INSTANTIATING_CFG=${10}

# ensure the binary exists
if ! command -v $BINARY &>/dev/null; then
Expand Down Expand Up @@ -97,31 +98,31 @@ sed -i 's/"bond_denom": "stake"/"bond_denom": "'"$DENOM"'"/g' $CHAINDIR/$CHAINID
# update contract address in genesis
babylonContractAddr=bbnc14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9syx25zf
btcStakingContractAddr=bbnc1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqgn0kq0
btcFinalityContractAddr=bbnc17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgssg3nft
sed -i 's/"babylon_contract_address": ""/"babylon_contract_address": "'"$babylonContractAddr"'"/g' $CHAINDIR/$CHAINID/config/genesis.json
sed -i 's/"btc_staking_contract_address": ""/"btc_staking_contract_address": "'"$btcStakingContractAddr"'"/g' $CHAINDIR/$CHAINID/config/genesis.json
sed -i 's/"btc_finality_contract_address": ""/"btc_finality_contract_address": "'"$btcFinalityContractAddr"'"/g' $CHAINDIR/$CHAINID/config/genesis.json

# Start
echo "Starting $BINARY..."
$BINARY --home $CHAINDIR/$CHAINID start --pruning=nothing --grpc-web.enable=false --grpc.address="0.0.0.0:$GRPCPORT" --log_level trace --trace --log_format 'plain' 2>&1 | tee $CHAINDIR/$CHAINID.log &
sleep 20

# upload contract code
echo "Uploading babylon contract code $BABYLON_CONTRACT_CODE_DIR..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm store "$BABYLON_CONTRACT_CODE_DIR" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.01ustake --node http://localhost:$RPCPORT -y
sleep 5
echo "Uploading babylon contract code $BABYLON_CONTRACT_CODE_FILE..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm store "$BABYLON_CONTRACT_CODE_FILE" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.01ustake --node http://localhost:$RPCPORT -y
sleep 10

# upload contract code
echo "Uploading btcstaking contract code $BTCSTAKING_CONTRACT_CODE_DIR..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm store "$BTCSTAKING_CONTRACT_CODE_DIR" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.01ustake --node http://localhost:$RPCPORT -y
sleep 5
echo "Uploading btcstaking contract code $BTCSTAKING_CONTRACT_CODE_FILE..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm store "$BTCSTAKING_CONTRACT_CODE_FILE" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.01ustake --node http://localhost:$RPCPORT -y
sleep 10

# Echo the command with expanded variables
echo "Echoing the command with expanded variables:"
echo "Instantiating contract with code $BABYLON_CONTRACT_CODE_DIR..."
echo "$BINARY --home $CHAINDIR/$CHAINID tx wasm instantiate 1 \"$INSTANTIATING_CFG\" --admin=$(bcd --home $CHAINDIR/$CHAINID keys show user --keyring-backend test -a) --label \"v0.0.1\" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.001ustake --node http://localhost:$RPCPORT -y --amount 100000stake"
# upload contract code
echo "Uploading btcfinality contract code $BTCFINALITY_CONTRACT_CODE_FILE..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm store "$BTCFINALITY_CONTRACT_CODE_FILE" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.01ustake --node http://localhost:$RPCPORT -y
sleep 10

# Then, execute the actual command
echo "Executing the command:"
echo "Instantiating contract with code $BABYLON_CONTRACT_CODE_DIR..."
# Echo the command with expanded variables
echo "Instantiating contract $BABYLON_CONTRACT_CODE_FILE..."
$BINARY --home $CHAINDIR/$CHAINID tx wasm instantiate 1 "$INSTANTIATING_CFG" --admin=$(bcd --home $CHAINDIR/$CHAINID keys show user --keyring-backend test -a) --label "v0.0.1" $KEYRING --from user --chain-id $CHAINID --gas 20000000000 --gas-prices 0.001ustake --node http://localhost:$RPCPORT -y --amount 100000stake

10 changes: 3 additions & 7 deletions contrib/images/ibcsim-bcd/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ CONSUMER_KEY="bcd-key"
CONSUMER_CHAIN_ID="bcd-test"

# 1. Create a bcd testnet with Babylon contract
# CONSUMER_NAME="Test Consumer"
# CONSUMER_DESCRIPTION="Test Consumer Description"
# BABYLON_TAG="01020304"
# BTC_STAKING_CODE_ID=2

./setup-bcd.sh $CONSUMER_CHAIN_ID $CONSUMER_CONF 26657 26656 6060 9090 ./babylon_contract.wasm ./btc_staking.wasm '{
./setup-bcd.sh $CONSUMER_CHAIN_ID $CONSUMER_CONF 26657 26656 6060 9090 ./babylon_contract.wasm ./btc_staking.wasm ./btc_finality.wasm '{
"network": "regtest",
"babylon_tag": "01020304",
"btc_confirmation_depth": 1,
"checkpoint_finalization_timeout": 2,
"notify_cosmos_zone": false,
"btc_staking_code_id": 2,
"consumer_name": "Test Consumer",
"consumer_description": "Test Consumer Description"
"consumer_description": "Test Consumer Description",
"btc_finality_code_id": 3
}'

sleep 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ import (
)

type CosmwasmConfig struct {
Key string `long:"key" description:"name of the key to sign transactions with"`
ChainID string `long:"chain-id" description:"chain id of the chain to connect to"`
RPCAddr string `long:"rpc-address" description:"address of the rpc server to connect to"`
GRPCAddr string `long:"grpc-address" description:"address of the grpc server to connect to"`
AccountPrefix string `long:"acc-prefix" description:"account prefix to use for addresses"`
KeyringBackend string `long:"keyring-type" description:"type of keyring to use"`
GasAdjustment float64 `long:"gas-adjustment" description:"adjustment factor when using gas estimation"`
GasPrices string `long:"gas-prices" description:"comma separated minimum gas prices to accept for transactions"`
KeyDirectory string `long:"key-dir" description:"directory to store keys in"`
Debug bool `long:"debug" description:"flag to print debug output"`
Timeout time.Duration `long:"timeout" description:"client timeout when doing queries"`
BlockTimeout time.Duration `long:"block-timeout" description:"block timeout when waiting for block events"`
OutputFormat string `long:"output-format" description:"default output when printint responses"`
SignModeStr string `long:"sign-mode" description:"sign mode to use"`
BtcStakingContractAddress string `long:"btc-staking-contract-address" description:"address of the BTC staking contract"`
Key string `long:"key" description:"name of the key to sign transactions with"`
ChainID string `long:"chain-id" description:"chain id of the chain to connect to"`
RPCAddr string `long:"rpc-address" description:"address of the rpc server to connect to"`
GRPCAddr string `long:"grpc-address" description:"address of the grpc server to connect to"`
AccountPrefix string `long:"acc-prefix" description:"account prefix to use for addresses"`
KeyringBackend string `long:"keyring-type" description:"type of keyring to use"`
GasAdjustment float64 `long:"gas-adjustment" description:"adjustment factor when using gas estimation"`
GasPrices string `long:"gas-prices" description:"comma separated minimum gas prices to accept for transactions"`
KeyDirectory string `long:"key-dir" description:"directory to store keys in"`
Debug bool `long:"debug" description:"flag to print debug output"`
Timeout time.Duration `long:"timeout" description:"client timeout when doing queries"`
BlockTimeout time.Duration `long:"block-timeout" description:"block timeout when waiting for block events"`
OutputFormat string `long:"output-format" description:"default output when printint responses"`
SignModeStr string `long:"sign-mode" description:"sign mode to use"`
BtcStakingContractAddress string `long:"btc-staking-contract-address" description:"address of the BTC staking contract"`
BtcFinalityContractAddress string `long:"btc-finality-contract-address" description:"address of the BTC finality contract"`
}

func (cfg *CosmwasmConfig) Validate() error {
if _, err := url.Parse(cfg.RPCAddr); err != nil {
return fmt.Errorf("rpc-addr is not correctly formatted: %w", err)
return fmt.Errorf("rpc-address is not correctly formatted: %w", err)
}

if _, err := url.Parse(cfg.GRPCAddr); err != nil {
return fmt.Errorf("grpc-address is not correctly formatted: %w", err)
}

if cfg.Timeout <= 0 {
Expand All @@ -43,30 +48,39 @@ func (cfg *CosmwasmConfig) Validate() error {

_, _, err := bech32.Decode(cfg.BtcStakingContractAddress, len(cfg.BtcStakingContractAddress))
if err != nil {
return fmt.Errorf("babylon-contract-address: invalid bech32 address: %w", err)
return fmt.Errorf("btc-staking-contract-address: invalid bech32 address: %w", err)
}
if !strings.HasPrefix(cfg.BtcStakingContractAddress, cfg.AccountPrefix) {
return fmt.Errorf("babylon-contract-address: invalid address prefix: %w", err)
return fmt.Errorf("btc-staking-contract-address: invalid address prefix: %w", err)
}

_, _, err = bech32.Decode(cfg.BtcFinalityContractAddress, len(cfg.BtcFinalityContractAddress))
if err != nil {
return fmt.Errorf("btc-finality-contract-address: invalid bech32 address: %w", err)
}
if !strings.HasPrefix(cfg.BtcFinalityContractAddress, cfg.AccountPrefix) {
return fmt.Errorf("btc-finality-contract-address: invalid address prefix: %w", err)
}
return nil
}

func DefaultCosmwasmConfig() *CosmwasmConfig {
return &CosmwasmConfig{
Key: "validator",
ChainID: "wasmd-test",
RPCAddr: "http://localhost:26677",
GRPCAddr: "https://localhost:9092",
AccountPrefix: "wasm",
KeyringBackend: "test",
GasAdjustment: 1.3,
GasPrices: "1ustake",
Debug: true,
Timeout: 20 * time.Second,
BlockTimeout: 1 * time.Minute,
OutputFormat: "direct",
SignModeStr: "",
BtcStakingContractAddress: "",
Key: "validator",
ChainID: "wasmd-test",
RPCAddr: "http://localhost:26677",
GRPCAddr: "http://localhost:9092",
AccountPrefix: "wasm",
KeyringBackend: "test",
GasAdjustment: 1.3,
GasPrices: "1ustake",
Debug: true,
Timeout: 20 * time.Second,
BlockTimeout: 1 * time.Minute,
OutputFormat: "direct",
SignModeStr: "",
BtcStakingContractAddress: "",
BtcFinalityContractAddress: "",
}
}

Expand All @@ -75,6 +89,7 @@ func (cfg *CosmwasmConfig) ToQueryClientConfig() *config.CosmwasmConfig {
Key: cfg.Key,
ChainID: cfg.ChainID,
RPCAddr: cfg.RPCAddr,
GRPCAddr: cfg.GRPCAddr,
AccountPrefix: cfg.AccountPrefix,
KeyringBackend: cfg.KeyringBackend,
GasAdjustment: cfg.GasAdjustment,
Expand Down
Loading
Loading