Skip to content

Commit

Permalink
Merge branch 'f/consumer-reward-e2e' into feat/permissioned-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Nov 26, 2024
2 parents 84ee829 + bc2e4bd commit b1a2eb1
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 205 deletions.
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
9 changes: 4 additions & 5 deletions contrib/images/ibcsim-bcd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH /go
ENV PATH $GOPATH/bin:$PATH

WORKDIR /work

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

# Install the relayer
RUN git clone https://github.com/cosmos/relayer.git
Expand Down Expand Up @@ -55,8 +53,9 @@ 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 --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

0 comments on commit b1a2eb1

Please sign in to comment.