diff --git a/x/ratesync/keeper/chain_test.go b/x/ratesync/keeper/chain_test.go index 279835ecc..4bf5b6eab 100644 --- a/x/ratesync/keeper/chain_test.go +++ b/x/ratesync/keeper/chain_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" "strconv" "github.com/persistenceOne/pstake-native/v2/x/ratesync/keeper" @@ -12,11 +14,41 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize +var ValidHostChainInMsg = func(id uint64) types.HostChain { + return types.HostChain{ + ID: id, + ChainID: "test-1", + ConnectionID: ibcexported.LocalhostConnectionID, + ICAAccount: liquidstakeibctypes.ICAAccount{ + Address: "", + Balance: sdk.Coin{Denom: "", Amount: sdk.ZeroInt()}, + Owner: types.DefaultPortOwner(id), + ChannelState: 0, + }, + Features: types.Feature{ + LiquidStakeIBC: types.LiquidStake{ + FeatureType: 0, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }, + LiquidStake: types.LiquidStake{ + FeatureType: 1, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }}, + } +} + func createNChain(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.HostChain { items := make([]types.HostChain, n) for i := range items { - items[i].ID = uint64(i) - + items[i] = ValidHostChainInMsg(uint64(i)) keeper.SetHostChain(ctx, items[i]) } return items diff --git a/x/ratesync/keeper/msg_server.go b/x/ratesync/keeper/msg_server.go index 89615ad3f..6832c5bd2 100644 --- a/x/ratesync/keeper/msg_server.go +++ b/x/ratesync/keeper/msg_server.go @@ -280,7 +280,7 @@ func (k msgServer) DeleteHostChain(goCtx context.Context, msg *types.MsgDeleteHo // check pending packets, do not allow to delete if packets are pending. portID := types.MustICAPortIDFromOwner(hc.ICAAccount.Owner) - channelID, ok := k.icaControllerKeeper.GetOpenActiveChannel(ctx, hc.ChainID, portID) + channelID, ok := k.icaControllerKeeper.GetOpenActiveChannel(ctx, hc.ConnectionID, portID) if !ok { return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "PortID: %s, connectionID: %s", portID, hc.ConnectionID) } diff --git a/x/ratesync/keeper/msg_server_test.go b/x/ratesync/keeper/msg_server_test.go index 795281768..702a703e8 100644 --- a/x/ratesync/keeper/msg_server_test.go +++ b/x/ratesync/keeper/msg_server_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "context" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,14 +29,15 @@ func (suite *IntegrationTestSuite) TestChainMsgServerCreate() { wctx := sdk.WrapSDKContext(ctx) for i := 0; i < 5; i++ { + hc := ValidHostChainInMsg(0) + hc.ChainID = ctx.ChainID() expected := &types.MsgCreateHostChain{Authority: GovAddress.String(), - HostChain: types.HostChain{ID: uint64(i + 1)}, + HostChain: hc, } _, err := srv.CreateHostChain(wctx, expected) suite.Require().NoError(err) _, found := k.GetHostChain(ctx, - expected.HostChain.ID, - ) + uint64(i+1)) suite.Require().True(found) } } @@ -43,6 +45,9 @@ func (suite *IntegrationTestSuite) TestChainMsgServerCreate() { func (suite *IntegrationTestSuite) TestChainMsgServerUpdate() { k, ctx := suite.app.RatesyncKeeper, suite.ctx hc := createNChain(k, ctx, 1)[0] + hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED + hc.ChainID = ctx.ChainID() + k.SetHostChain(ctx, hc) hc2 := types.HostChain{ID: 1} tests := []struct { desc string @@ -94,8 +99,11 @@ func (suite *IntegrationTestSuite) TestChainMsgServerUpdate() { func (suite *IntegrationTestSuite) TestChainMsgServerDelete() { k, ctx := suite.app.RatesyncKeeper, suite.ctx - _ = createNChain(k, ctx, 1)[0] - + hcs := createNChain(k, ctx, 5) + hc := hcs[1] + hc.ChainID = ctx.ChainID() + hc.ConnectionID = "connection-0" + k.SetHostChain(ctx, hc) tests := []struct { desc string request *types.MsgDeleteHostChain @@ -104,13 +112,13 @@ func (suite *IntegrationTestSuite) TestChainMsgServerDelete() { { desc: "Completed", request: &types.MsgDeleteHostChain{Authority: GovAddress.String(), - ID: 0, + ID: 1, }, }, { desc: "Unauthorized", request: &types.MsgDeleteHostChain{Authority: "B", - ID: 0, + ID: 2, }, err: sdkerrors.ErrorInvalidSigner, }, diff --git a/x/ratesync/keeper/setup_suite_test.go b/x/ratesync/keeper/setup_suite_test.go index b8b7cd3fb..e0289f2b1 100644 --- a/x/ratesync/keeper/setup_suite_test.go +++ b/x/ratesync/keeper/setup_suite_test.go @@ -90,7 +90,7 @@ func (suite *IntegrationTestSuite) SetupTest() { suite.app = suite.chainA.App.(*app.PstakeApp) //suite.SetupHostChainAB() - //suite.SetupICAChannelsAB() + suite.SetupICAChannelsAB() suite.Transfer(suite.transferPathAB, sdk.NewCoin("uatom", sdk.NewInt(1000000000000))) suite.Transfer(suite.transferPathAC, sdk.NewCoin("uosmo", sdk.NewInt(1000000000000))) diff --git a/x/ratesync/types/msgs_test.go b/x/ratesync/types/msgs_test.go index aa84369ab..d3e7b3e60 100644 --- a/x/ratesync/types/msgs_test.go +++ b/x/ratesync/types/msgs_test.go @@ -1,6 +1,7 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" "testing" @@ -10,19 +11,35 @@ import ( "github.com/stretchr/testify/require" ) -var ValidHostChainInMsg = HostChain{ - ID: 1, - ChainID: "test-1", - ConnectionID: ibcexported.LocalhostConnectionID, - ICAAccount: types.ICAAccount{}, - Features: Feature{LiquidStakeIBC: LiquidStake{ - FeatureType: 0, - CodeID: 0, - Instantiation: 0, - ContractAddress: "", - Denoms: []string{}, - Enabled: false, - }}, +var ValidHostChainInMsg = func(id uint64) HostChain { + return HostChain{ + ID: id, + ChainID: "test-1", + ConnectionID: ibcexported.LocalhostConnectionID, + ICAAccount: types.ICAAccount{ + Address: "", + Balance: sdk.Coin{}, + Owner: "", + ChannelState: 0, + }, + Features: Feature{ + LiquidStakeIBC: LiquidStake{ + FeatureType: 0, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: []string{}, + Enabled: false, + }, + LiquidStake: LiquidStake{ + FeatureType: 1, + CodeID: 0, + Instantiation: 0, + ContractAddress: "", + Denoms: nil, + Enabled: false, + }}, + } } func TestMsgUpdateParams_ValidateBasic(t *testing.T) { @@ -40,7 +57,8 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { }, { name: "valid address", msg: MsgUpdateParams{ - Authority: authtypes.NewModuleAddress("addr1").String(), + Authority: authtypes.NewModuleAddress("addr").String(), + Params: DefaultParams(), }, }, } @@ -66,12 +84,14 @@ func TestMsgCreateHostChain_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgCreateHostChain{ Authority: "invalid_address", + HostChain: ValidHostChainInMsg(0), }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgCreateHostChain{ Authority: authtypes.NewModuleAddress("addr1").String(), + HostChain: ValidHostChainInMsg(0), }, }, } @@ -97,12 +117,14 @@ func TestMsgUpdateHostChain_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgUpdateHostChain{ Authority: "invalid_address", + HostChain: ValidHostChainInMsg(1), }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgUpdateHostChain{ Authority: authtypes.NewModuleAddress("addr1").String(), + HostChain: ValidHostChainInMsg(1), }, }, } diff --git a/x/ratesync/types/params.go b/x/ratesync/types/params.go index 757c9cd83..9d14b1ac4 100644 --- a/x/ratesync/types/params.go +++ b/x/ratesync/types/params.go @@ -10,15 +10,15 @@ import ( var DefaultAdmin = authtypes.NewModuleAddress(govtypes.ModuleName) // NewParams creates a new Params instance -func NewParams() Params { +func NewParams(admin sdk.AccAddress) Params { return Params{ - Admin: DefaultAdmin.String(), + Admin: admin.String(), } } // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams() + return NewParams(DefaultAdmin) } // Validate validates the set of params