Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kruspy committed Dec 13, 2023
1 parent 1e3122a commit cf2ca2a
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
39 changes: 39 additions & 0 deletions x/liquidstakeibc/keeper/icq_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,42 @@ func (suite *IntegrationTestSuite) TestKeeper_QueryRewardsHostChainAccountBalanc
})
}
}

func (suite *IntegrationTestSuite) TestKeeper_QueryNonCompoundableRewardsHostChainAccountBalance() {
pstakeApp, ctx := suite.app, suite.ctx
k := pstakeApp.LiquidStakeIBCKeeper
hc, found := k.GetHostChain(ctx, suite.chainB.ChainID)
suite.Require().Equal(found, true)

hc.RewardParams = &types.RewardParams{Destination: "cosmos1g4sr6pcr68v8ng8hfg4pj852cg6kg4cwe40wuw8nxdxl67xp0vusjfs3n0", Denom: "uatom"}
k.SetHostChain(ctx, hc)

hc2 := types.HostChain{RewardsAccount: &types.ICAAccount{Address: "invalid"}}

type args struct {
hc *types.HostChain
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Success",
args: args{hc: hc},
wantErr: false,
}, {
name: "invalid rewards addr",
args: args{hc: &hc2},
wantErr: true,
},
}
for _, tt := range tests {
suite.Run(tt.name, func() {

if err := k.QueryRewardsHostChainAccountBalance(ctx, tt.args.hc); (err != nil) != tt.wantErr {
suite.T().Errorf("QueryRewardsHostChainAccountBalance() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
64 changes: 64 additions & 0 deletions x/liquidstakeibc/keeper/icq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
icqtypes "github.com/persistenceOne/persistence-sdk/v2/x/interchainquery/types"

"github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/keeper"
)

Expand Down Expand Up @@ -269,3 +270,66 @@ func (suite *IntegrationTestSuite) TestRewardsAccountBalanceCallback() {
})
}
}

func (suite *IntegrationTestSuite) TestNonCompoundableRewardsAccountBalanceCallback() {
pstakeApp, ctx := suite.app, suite.ctx
k := pstakeApp.LiquidStakeIBCKeeper
hc, found := k.GetHostChain(ctx, suite.chainB.ChainID)
suite.Require().Equal(found, true)

makeData := func(denom string, amount int64) []byte {
coin := sdk.NewInt64Coin(denom, amount)
return pstakeApp.AppCodec().MustMarshal(&coin)
}
for i := range hc.Validators {
hc.Validators[i].DelegatedAmount = sdk.NewInt(1000000)
}
k.SetHostChain(ctx, hc)
type args struct {
ctx sdk.Context
data []byte
query icqtypes.Query
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Success, hits the cap",
args: args{
data: makeData(hc.HostDenom, 100),
query: icqtypes.Query{ChainId: hc.ChainId},
},
wantErr: false,
}, {
name: "Success, does not hit the cap",
args: args{
data: makeData(hc.HostDenom, 1),
query: icqtypes.Query{ChainId: hc.ChainId},
},
wantErr: false,
}, {
name: "invalid chain id",
args: args{
data: makeData(hc.HostDenom, 100),
query: icqtypes.Query{ChainId: "Invalid Chain ID"},
},
wantErr: true,
}, {
name: "invalid data",
args: args{
data: []byte("invalid"),
query: icqtypes.Query{ChainId: hc.ChainId},
},
wantErr: true,
},
}
for _, tt := range tests {
suite.Run(tt.name, func() {
if err := keeper.RewardsAccountBalanceCallback(k, ctx, tt.args.data, tt.args.query); (err != nil) != tt.wantErr {
suite.T().Errorf("RewardsAccountBalanceCallback() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit cf2ca2a

Please sign in to comment.