Skip to content

Commit

Permalink
fix tests and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Dec 20, 2023
1 parent c98b323 commit c0d3c7a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 28 deletions.
36 changes: 34 additions & 2 deletions x/ratesync/keeper/chain_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/ratesync/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
22 changes: 15 additions & 7 deletions x/ratesync/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,21 +29,25 @@ 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)
}
}

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
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion x/ratesync/keeper/setup_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
50 changes: 36 additions & 14 deletions x/ratesync/types/msgs_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand All @@ -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(),
},
},
}
Expand All @@ -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),
},
},
}
Expand All @@ -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),
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions x/ratesync/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0d3c7a

Please sign in to comment.