From 7bac6f0e252230a612fe754aa36eeea894125440 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Thu, 9 Jan 2025 14:55:35 +1100 Subject: [PATCH] rm gov prop for updating params --- contrib/images/ibcsim-bcd/setup-bcd.sh | 2 +- demo/app/app_test.go | 14 ++++++++++++++ tests/e2e/local_e2e_test.go | 24 +++--------------------- tests/e2e/types/test_client.go | 1 + x/babylon/client/cli/tx.go | 4 ++-- x/babylon/keeper/msg_server.go | 18 +++++------------- x/babylon/keeper/wasm.go | 2 ++ x/babylon/types/babylon.go | 4 ---- 8 files changed, 28 insertions(+), 41 deletions(-) diff --git a/contrib/images/ibcsim-bcd/setup-bcd.sh b/contrib/images/ibcsim-bcd/setup-bcd.sh index a2c63fa..1901c3b 100755 --- a/contrib/images/ibcsim-bcd/setup-bcd.sh +++ b/contrib/images/ibcsim-bcd/setup-bcd.sh @@ -109,4 +109,4 @@ sleep 10 # Echo the command with expanded variables echo "Instantiating contract $BABYLON_CONTRACT_CODE_FILE..." -$BINARY --home $CHAINDIR/$CHAINID tx babylon instantiate-babylon-contracts 1 2 3 "regtest" "01020304" 1 2 false "" "" "Test\ Consumer" "Test\ Consumer\ Description" "" --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 +$BINARY --home $CHAINDIR/$CHAINID tx babylon instantiate-babylon-contracts 1 2 3 "regtest" "01020304" 1 2 false "Test\ Consumer" "Test\ Consumer\ Description" "" --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 diff --git a/demo/app/app_test.go b/demo/app/app_test.go index 062661b..193f08e 100644 --- a/demo/app/app_test.go +++ b/demo/app/app_test.go @@ -141,4 +141,18 @@ func TestInstantiateBabylonContracts(t *testing.T) { // instantiate Babylon contract _, err = babylonMsgServer.InstantiateBabylonContracts(ctx, msg) require.NoError(t, err) + + // get params and verify contract addresses are set correctly + params := babylonKeeper.GetParams(ctx) + require.NotEmpty(t, params.BabylonContractAddress) + require.NotEmpty(t, params.BtcStakingContractAddress) + require.NotEmpty(t, params.BtcFinalityContractAddress) + + // verify addresses are valid + _, err = sdk.AccAddressFromBech32(params.BabylonContractAddress) + require.NoError(t, err) + _, err = sdk.AccAddressFromBech32(params.BtcStakingContractAddress) + require.NoError(t, err) + _, err = sdk.AccAddressFromBech32(params.BtcFinalityContractAddress) + require.NoError(t, err) } diff --git a/tests/e2e/local_e2e_test.go b/tests/e2e/local_e2e_test.go index 8475560..a711bee 100644 --- a/tests/e2e/local_e2e_test.go +++ b/tests/e2e/local_e2e_test.go @@ -8,7 +8,6 @@ import ( "github.com/babylonlabs-io/babylon-sdk/demo/app" appparams "github.com/babylonlabs-io/babylon-sdk/demo/app/params" "github.com/babylonlabs-io/babylon-sdk/tests/e2e/types" - bbntypes "github.com/babylonlabs-io/babylon-sdk/x/babylon/types" sdk "github.com/cosmos/cosmos-sdk/types" ibctesting2 "github.com/cosmos/ibc-go/v8/testing" "github.com/stretchr/testify/suite" @@ -97,28 +96,11 @@ func (s *BabylonSDKTestSuite) Test1ContractDeployment() { s.NoError(err) s.Equal(adminRespFinality["admin"], s.ConsumerCli.GetSender().String()) - // get contract addresses - babylonContractAddress := s.ConsumerContract.Babylon.String() - btcStakingContractAddress := s.ConsumerContract.BTCStaking.String() - btcFinalityContractAddress := s.ConsumerContract.BTCFinality.String() - - // update the contract address in parameters - msgUpdateParams := &bbntypes.MsgUpdateParams{ - Authority: s.ConsumerApp.BabylonKeeper.GetAuthority(), - Params: bbntypes.Params{ - MaxGasBeginBlocker: 500_000, - BabylonContractAddress: babylonContractAddress, - BtcStakingContractAddress: btcStakingContractAddress, - BtcFinalityContractAddress: btcFinalityContractAddress, - }, - } - s.ConsumerCli.MustExecGovProposal(msgUpdateParams) - // assert the contract addresses are updated params := s.ConsumerApp.BabylonKeeper.GetParams(s.ConsumerChain.GetContext()) - s.Equal(babylonContractAddress, params.BabylonContractAddress) - s.Equal(btcStakingContractAddress, params.BtcStakingContractAddress) - s.Equal(btcFinalityContractAddress, params.BtcFinalityContractAddress) + s.Equal(s.ConsumerContract.Babylon.String(), params.BabylonContractAddress) + s.Equal(s.ConsumerContract.BTCStaking.String(), params.BtcStakingContractAddress) + s.Equal(s.ConsumerContract.BTCFinality.String(), params.BtcFinalityContractAddress) } func (s *BabylonSDKTestSuite) Test2MockConsumerFpDelegation() { diff --git a/tests/e2e/types/test_client.go b/tests/e2e/types/test_client.go index 19920ae..c9a20ec 100644 --- a/tests/e2e/types/test_client.go +++ b/tests/e2e/types/test_client.go @@ -122,6 +122,7 @@ func (p *TestConsumerClient) BootstrapContracts() (*ConsumerContract, error) { if err != nil { return nil, err } + _, err = p.Chain.SendMsgs(msgInstantiate) if err != nil { return nil, err diff --git a/x/babylon/client/cli/tx.go b/x/babylon/client/cli/tx.go index 0515d98..741b76e 100644 --- a/x/babylon/client/cli/tx.go +++ b/x/babylon/client/cli/tx.go @@ -83,11 +83,11 @@ func ParseInstantiateArgs(args []string, sender string) (*types.MsgInstantiateBa func NewInstantiateBabylonContractsCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "instantiate-babylon-contracts [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [btc-staking-init-msg-hex] [btc-finality-init-msg-hex] [consumer-name] [consumer-description] [admin]", + Use: "instantiate-babylon-contracts [babylon-contract-code-id] [btc-staking-contract-code-id] [btc-finality-contract-code-id] [btc-network] [babylon-tag] [btc-confirmation-depth] [checkpoint-finalization-timeout] [notify-cosmos-zone] [consumer-name] [consumer-description] [admin]", Short: "Instantiate Babylon contracts", Long: "Instantiate Babylon contracts", Aliases: []string{"i"}, - Args: cobra.ExactArgs(13), + Args: cobra.ExactArgs(11), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { diff --git a/x/babylon/keeper/msg_server.go b/x/babylon/keeper/msg_server.go index 454d119..d6e2cb8 100644 --- a/x/babylon/keeper/msg_server.go +++ b/x/babylon/keeper/msg_server.go @@ -30,39 +30,31 @@ func (ms msgServer) InstantiateBabylonContracts(goCtx context.Context, req *type return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "only authority can override instantiated contracts; expected %s, got %s", ms.k.authority, req.Signer) } - // if admin is not set, then use gov authority - admin := req.Admin - if admin == "" { - admin = ms.k.authority - } - // construct the init message - initMsgBytes, err := types.NewInitMsg( + babylonInitMsg, err := types.NewInitMsg( req.Network, req.BabylonTag, req.BtcConfirmationDepth, req.CheckpointFinalizationTimeout, req.NotifyCosmosZone, - req.BtcStakingContractCodeId, - req.BtcFinalityContractCodeId, req.ConsumerName, req.ConsumerDescription, - admin, + req.Admin, ) if err != nil { return nil, err } - btcStakingInitMsg, err := types.NewBTCStakingInitMsg(admin) + btcStakingInitMsg, err := types.NewBTCStakingInitMsg(req.Admin) if err != nil { return nil, err } - btcFinalityInitMsg, err := types.NewBTCFinalityInitMsg(admin) + btcFinalityInitMsg, err := types.NewBTCFinalityInitMsg(req.Admin) if err != nil { return nil, err } // instantiate the contracts - babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, req.BabylonContractCodeId, req.BtcStakingContractCodeId, req.BtcFinalityContractCodeId, initMsgBytes, btcStakingInitMsg, btcFinalityInitMsg) + babylonContractAddr, btcStakingContractAddr, btcFinalityContractAddr, err := ms.k.InstantiateBabylonContracts(ctx, req.BabylonContractCodeId, req.BtcStakingContractCodeId, req.BtcFinalityContractCodeId, babylonInitMsg, btcStakingInitMsg, btcFinalityInitMsg) if err != nil { return nil, err } diff --git a/x/babylon/keeper/wasm.go b/x/babylon/keeper/wasm.go index a4fcfd1..f24a4f4 100644 --- a/x/babylon/keeper/wasm.go +++ b/x/babylon/keeper/wasm.go @@ -34,11 +34,13 @@ func (k Keeper) InstantiateBabylonContracts( if err != nil { return "", "", "", err } + // instantiate BTC staking contract btcStakingContractAddr, _, err := contractKeeper.Instantiate(ctx, btcStakingContractCodeId, govAddr, govAddr, btcStakingInitMsg, "BTC staking contract", nil) if err != nil { return "", "", "", err } + // instantiate BTC finality contract btcFinalityContractAddr, _, err := contractKeeper.Instantiate(ctx, btcFinalityContractCodeId, govAddr, govAddr, btcFinalityInitMsg, "BTC finality contract", nil) if err != nil { diff --git a/x/babylon/types/babylon.go b/x/babylon/types/babylon.go index 4adec9b..8483138 100644 --- a/x/babylon/types/babylon.go +++ b/x/babylon/types/babylon.go @@ -29,8 +29,6 @@ func NewInitMsg( btcConfirmationDepth uint32, checkpointFinalizationTimeout uint32, notifyCosmosZone bool, - btcStakingCodeId uint64, - btcFinalityCodeId uint64, consumerName string, consumerDescription string, admin string, @@ -41,10 +39,8 @@ func NewInitMsg( "btc_confirmation_depth": btcConfirmationDepth, "checkpoint_finalization_timeout": checkpointFinalizationTimeout, "notify_cosmos_zone": notifyCosmosZone, - "btc_staking_code_id": btcStakingCodeId, "consumer_name": consumerName, "consumer_description": consumerDescription, - "btc_finality_code_id": btcFinalityCodeId, "admin": admin, } initMsgBytes, err := json.Marshal(initMsg)