Skip to content

Commit

Permalink
fix UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Aug 30, 2024
1 parent c6435d6 commit cd0b35f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
70 changes: 0 additions & 70 deletions x/ccv/provider/types/legacy_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,76 +542,6 @@ func TestChangeRewardDenomsProposalValidateBasic(t *testing.T) {
}
}

func TestMsgUpdateConsumerValidateBasic(t *testing.T) {
testCases := []struct {
name string
powerShapingParameters types.PowerShapingParameters
expPass bool
}{
{
"success",
types.PowerShapingParameters{
Top_N: 50,
ValidatorsPowerCap: 100,
ValidatorSetCap: 34,
Allowlist: []string{"addr1"},
Denylist: nil,
MinStake: 0,
AllowInactiveVals: false,
},
true,
},
{
"top N is invalid",
types.PowerShapingParameters{
Top_N: 10,
ValidatorsPowerCap: 0,
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
},
false,
},
{
"validators power cap is invalid",
types.PowerShapingParameters{
Top_N: 50,
ValidatorsPowerCap: 101,
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
MinStake: 0,
AllowInactiveVals: false,
},
false,
},
{
"valid proposal",
types.PowerShapingParameters{
Top_N: 54,
ValidatorsPowerCap: 92,
ValidatorSetCap: 0,
Allowlist: []string{"addr1"},
Denylist: []string{"addr2", "addr3"},
MinStake: 0,
AllowInactiveVals: false,
},
true,
},
}

for _, tc := range testCases {
// TODO (PERMISSIONLESS) add more tests
msg, _ := types.NewMsgUpdateConsumer("", "0", "cosmos1p3ucd3ptpw902fluyjzhq3ffgq4ntddac9sa3s", nil, nil, &tc.powerShapingParameters)
err := msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid case: %s should not return error. got %w", tc.name, err)
} else {
require.Error(t, err, "invalid case: '%s' must return error but got none", tc.name)
}
}
}

func TestValidatePSSFeatures(t *testing.T) {
require.NoError(t, types.ValidatePSSFeatures(0, 0))
require.NoError(t, types.ValidatePSSFeatures(50, 0))
Expand Down
74 changes: 74 additions & 0 deletions x/ccv/provider/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,77 @@ func TestValidateByteSlice(t *testing.T) {
}
}
}

func TestMsgUpdateConsumerValidateBasic(t *testing.T) {
consAddr1 := "cosmosvalcons1qmq08eruchr5sf5s3rwz7djpr5a25f7xw4mceq"
consAddr2 := "cosmosvalcons1nx7n5uh0ztxsynn4sje6eyq2ud6rc6klc96w39"
consAddr3 := "cosmosvalcons1muys5jyqk4xd27e208nym85kn0t4zjcfeu63fe"

testCases := []struct {
name string
powerShapingParameters types.PowerShapingParameters
expPass bool
}{
{
"success",
types.PowerShapingParameters{
Top_N: 50,
ValidatorsPowerCap: 100,
ValidatorSetCap: 34,
Allowlist: []string{consAddr1},
Denylist: nil,
MinStake: 0,
AllowInactiveVals: false,
},
true,
},
{
"top N is invalid",
types.PowerShapingParameters{
Top_N: 10,
ValidatorsPowerCap: 0,
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
},
false,
},
{
"validators power cap is invalid",
types.PowerShapingParameters{
Top_N: 50,
ValidatorsPowerCap: 101,
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
MinStake: 0,
AllowInactiveVals: false,
},
false,
},
{
"valid proposal",
types.PowerShapingParameters{
Top_N: 54,
ValidatorsPowerCap: 92,
ValidatorSetCap: 0,
Allowlist: []string{consAddr1},
Denylist: []string{consAddr2, consAddr3},
MinStake: 0,
AllowInactiveVals: false,
},
true,
},
}

for _, tc := range testCases {
// TODO (PERMISSIONLESS) add more tests
msg, _ := types.NewMsgUpdateConsumer("", "0", "cosmos1p3ucd3ptpw902fluyjzhq3ffgq4ntddac9sa3s", nil, nil, &tc.powerShapingParameters)
err := msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid case: %s should not return error. got %w", tc.name, err)
} else {
require.Error(t, err, "invalid case: '%s' must return error but got none", tc.name)
}
}
}

0 comments on commit cd0b35f

Please sign in to comment.