Skip to content

Commit

Permalink
chore: more tests (#717)
Browse files Browse the repository at this point in the history
* tests for types.

* remove client and deprecated module lscosmos from coverage.

* add abci tests.

* improve chain test.go
  • Loading branch information
puneet2019 authored Jan 10, 2024
1 parent 4f9bbba commit 6256138
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
excludelist+=" $(find ./ -type f -name '*.pb.go')"
excludelist+=" $(find ./ -type f -name '*.pb.gw.go')"
excludelist+=" $(find ./ -type f -path './tests/mocks/*.go')"
excludelist+=" $(find ./ -type f -path './x/lscosmos/*')"
excludelist+=" $(find ./ -type f -path './x/liquidstake/client/*')"
excludelist+=" $(find ./ -type f -path './x/liquidstakeibc/client/*')"
excludelist+=" $(find ./ -type f -path './x/ratesync/client/*')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^.\///g')
echo "Excluding ${filename} from coverage report..."
Expand Down
32 changes: 32 additions & 0 deletions x/ratesync/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper_test

import liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"

func (suite *IntegrationTestSuite) TestBeginBlocker() {
keeper, ctx := suite.app.RatesyncKeeper, suite.ctx
_ = createNChain(keeper, ctx, 1)
suite.Require().NotPanics(func() {
keeper.BeginBlock(ctx)
})
hcs := keeper.GetAllHostChain(ctx)
hc := hcs[0]
hc.Features.LiquidStake.Enabled = true
keeper.SetHostChain(ctx, hc)
suite.Require().NotPanics(func() {
keeper.BeginBlock(ctx)
})
}

func (suite *IntegrationTestSuite) TestDoRecreateICA() {
keeper, ctx := suite.app.RatesyncKeeper, suite.ctx
hc := ValidHostChainInMsg(1)
keeper.SetHostChain(ctx, hc)
suite.Require().NotPanics(func() {
keeper.DoRecreateICA(ctx, hc)
})
hc.ICAAccount.ChannelState = liquidstakeibctypes.ICAAccount_ICA_CHANNEL_CREATED
suite.Require().NotPanics(func() {
keeper.DoRecreateICA(ctx, hc)
})

}
8 changes: 8 additions & 0 deletions x/ratesync/keeper/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func (suite *IntegrationTestSuite) TestHostChainRemove() {
}
}

func (suite *IntegrationTestSuite) TestGetHostChainsByChainID() {
keeper, ctx := suite.app.RatesyncKeeper, suite.ctx
items := createNChain(keeper, ctx, 10)
suite.Require().ElementsMatch(items, keeper.GetAllHostChain(ctx))
suite.Require().ElementsMatch(items, keeper.GetHostChainsByChainID(ctx, "test-1"))

}

func (suite *IntegrationTestSuite) TestHostChainGetAll() {
keeper, ctx := suite.app.RatesyncKeeper, suite.ctx
items := createNChain(keeper, ctx, 10)
Expand Down
105 changes: 104 additions & 1 deletion x/ratesync/types/types_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package types

import (
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
"testing"

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

func TestTypes(t *testing.T) {
// hostchain
hc := ValidHostChainInMsg(0)
require.NoError(t, hc.ValidateBasic())

Expand Down Expand Up @@ -42,4 +45,104 @@ func TestTypes(t *testing.T) {
hc2.Features.LiquidStake.Enabled = true
require.True(t, hc2.IsActive())

// features
features := ValidHostChainInMsg(0).Features
require.NoError(t, features.ValdidateBasic())
features.LiquidStakeIBC.FeatureType = FeatureType_LIQUID_STAKE
require.Error(t, features.ValdidateBasic())
features = ValidHostChainInMsg(0).Features
features.LiquidStakeIBC.Enabled = true
require.Error(t, features.ValdidateBasic())

features = ValidHostChainInMsg(0).Features
features.LiquidStake.FeatureType = FeatureType_LIQUID_STAKE_IBC
require.Error(t, features.ValdidateBasic())
features = ValidHostChainInMsg(0).Features
features.LiquidStake.Enabled = true
require.Error(t, features.ValdidateBasic())

//liquidstakeFeature
lsfeature := ValidHostChainInMsg(0).Features.LiquidStake
require.NoError(t, lsfeature.ValdidateBasic())
lsfeature.Instantiation = InstantiationState_INSTANTIATION_INITIATED
require.Error(t, lsfeature.ValdidateBasic())

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature.Enabled = true
require.Error(t, lsfeature.ValdidateBasic())
lsfeature.ContractAddress = authtypes.NewModuleAddress("contract").String()
require.Error(t, lsfeature.ValdidateBasic())

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature.CodeID = 1 //non zero
lsfeature.Instantiation = InstantiationState_INSTANTIATION_INITIATED
require.NoError(t, lsfeature.ValdidateBasic())
lsfeature.Enabled = true
require.Error(t, lsfeature.ValdidateBasic())
lsfeature.ContractAddress = authtypes.NewModuleAddress("contract").String()
require.Error(t, lsfeature.ValdidateBasic())

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature.CodeID = 1 //non zero
lsfeature.Instantiation = InstantiationState_INSTANTIATION_COMPLETED
require.Error(t, lsfeature.ValdidateBasic())
lsfeature.ContractAddress = authtypes.NewModuleAddress("contract").String()
require.NoError(t, lsfeature.ValdidateBasic())
lsfeature.ContractAddress = "cosmos1xxxxxx"
require.Error(t, lsfeature.ValdidateBasic())

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature.Denoms = []string{"*", "stk/uxprt"}
require.Error(t, lsfeature.ValdidateBasic())

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
require.Equal(t, false, lsfeature.AllowsAllDenoms())
require.Equal(t, false, lsfeature.AllowsDenom("stk/uxprt"))
lsfeature.Denoms = []string{"*"}
require.NoError(t, lsfeature.ValdidateBasic())
require.Equal(t, true, lsfeature.AllowsAllDenoms())
require.Equal(t, true, lsfeature.AllowsDenom("stk/uxprt"))
lsfeature.Denoms = []string{"*", "stk/uxprt"}
require.Equal(t, false, lsfeature.AllowsAllDenoms())
require.Equal(t, true, lsfeature.AllowsDenom("stk/uxprt"))

lsfeature = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature2 := ValidHostChainInMsg(0).Features.LiquidStake
require.Equal(t, true, lsfeature.Equals(lsfeature2))

lsfeature2 = ValidHostChainInMsg(0).Features.LiquidStake
lsfeature2.Enabled = true
require.Equal(t, false, lsfeature.Equals(lsfeature2))
lsfeature2.FeatureType = FeatureType_LIQUID_STAKE_IBC
require.Equal(t, false, lsfeature.Equals(lsfeature2))
lsfeature2.Denoms = []string{"*"}
require.Equal(t, false, lsfeature.Equals(lsfeature2))
lsfeature2.ContractAddress = "cosmos1xxx"
require.Equal(t, false, lsfeature.Equals(lsfeature2))
lsfeature2.Instantiation = InstantiationState_INSTANTIATION_COMPLETED
require.Equal(t, false, lsfeature.Equals(lsfeature2))
lsfeature2.CodeID = 1
require.Equal(t, false, lsfeature.Equals(lsfeature2))

require.Equal(t, "pstake_ratesync_1", DefaultPortOwner(1))
require.Equal(t, "icacontroller-pstake_ratesync_1", MustICAPortIDFromOwner(DefaultPortOwner(1)))
require.Panics(t, func() {
MustICAPortIDFromOwner("")
})

owner, err := OwnerFromPortID("icacontroller-pstake_ratesync_1")
require.NoError(t, err)
require.Equal(t, "pstake_ratesync_1", owner)

owner, err = OwnerFromPortID("ica-pstake_ratesync_1")
require.Error(t, err)
require.Equal(t, "", owner)

id, err := IDFromPortID("icacontroller-pstake_ratesync_1")
require.NoError(t, err)
require.Equal(t, uint64(1), id)

id, err = IDFromPortID("icacontroller-pstake_ratesync1")
require.Error(t, err)
require.Equal(t, uint64(0), id)
}

0 comments on commit 6256138

Please sign in to comment.