Skip to content

Commit

Permalink
tests for types.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 committed Jan 9, 2024
1 parent b020194 commit f2f4e17
Showing 1 changed file with 104 additions and 1 deletion.
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 f2f4e17

Please sign in to comment.