Skip to content

Commit

Permalink
rm gov prop for updating params
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Jan 9, 2025
1 parent feb7adc commit 7bac6f0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 41 deletions.
2 changes: 1 addition & 1 deletion contrib/images/ibcsim-bcd/setup-bcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions demo/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
24 changes: 3 additions & 21 deletions tests/e2e/local_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/types/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/babylon/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 5 additions & 13 deletions x/babylon/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions x/babylon/keeper/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions x/babylon/types/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ func NewInitMsg(
btcConfirmationDepth uint32,
checkpointFinalizationTimeout uint32,
notifyCosmosZone bool,
btcStakingCodeId uint64,
btcFinalityCodeId uint64,
consumerName string,
consumerDescription string,
admin string,
Expand All @@ -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)
Expand Down

0 comments on commit 7bac6f0

Please sign in to comment.