Skip to content

Commit

Permalink
genesis. test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 14, 2024
1 parent 2ba349e commit 28829ed
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 24 deletions.
128 changes: 110 additions & 18 deletions x/participation/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,169 @@ package types_test
import (
"testing"

sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/require"

"github.com/ignite/network/testutil/sample"
"github.com/ignite/network/x/participation/types"
)

func TestGenesisState_Validate(t *testing.T) {
tests := []struct {
desc string
var (
addr1 = sample.Address(r)
addr2 = sample.Address(r)
auctionID1 = uint64(0)
auctionID2 = uint64(1)
)

for _, tc := range []struct {
name string
genState *types.GenesisState
valid bool
}{
{
desc: "default is valid",
name: "should validate default genesis state",
genState: types.DefaultGenesis(),
valid: true,
},
{
desc: "valid genesis state",
name: "should validate valid genesis state",
genState: &types.GenesisState{
Params: types.DefaultParams(),
UsedAllocationsList: []types.UsedAllocations{
{
Address: addr1,
NumAllocations: sdkmath.ZeroInt(),
},
{
Address: addr2,
NumAllocations: sdkmath.ZeroInt(),
},
},
AuctionUsedAllocationsList: []types.AuctionUsedAllocations{
{
Address: "0",
Address: addr1,
AuctionID: auctionID1,
NumAllocations: sdkmath.ZeroInt(),
},
{
Address: "1",
Address: addr2,
AuctionID: auctionID2,
NumAllocations: sdkmath.ZeroInt(),
},
},
// this line is used by starport scaffolding # types/genesis/validField
},
valid: true,
},
{
name: "should validate with matching usedAllocations and auctionUsedAllocations",
genState: &types.GenesisState{
Params: types.DefaultParams(),
UsedAllocationsList: []types.UsedAllocations{
{
Address: "0",
Address: addr1,
NumAllocations: sdkmath.NewInt(5),
},
},
AuctionUsedAllocationsList: []types.AuctionUsedAllocations{
{
Address: addr1,
AuctionID: auctionID1,
NumAllocations: sdkmath.NewInt(2),
Withdrawn: false,
},
{
Address: "1",
Address: addr1,
AuctionID: auctionID2,
NumAllocations: sdkmath.NewInt(3),
Withdrawn: false,
},
},
// this line is used by starport scaffolding # types/genesis/validField
},
valid: true,
},
{
desc: "duplicated auctionUsedAllocations",
name: "should prevent duplicated usedAllocations",
genState: &types.GenesisState{
UsedAllocationsList: []types.UsedAllocations{
{
Address: addr1,
NumAllocations: sdkmath.ZeroInt(),
},
{
Address: addr1,
NumAllocations: sdkmath.ZeroInt(),
},
},
},
valid: false,
},
{
name: "should prevent duplicated auctionUsedAllocations",
genState: &types.GenesisState{
UsedAllocationsList: []types.UsedAllocations{
{
Address: addr1,
NumAllocations: sdkmath.ZeroInt(),
},
},
AuctionUsedAllocationsList: []types.AuctionUsedAllocations{
{
Address: "0",
Address: addr1,
AuctionID: auctionID1,
NumAllocations: sdkmath.ZeroInt(),
},
{
Address: "0",
Address: addr1,
AuctionID: auctionID1,
NumAllocations: sdkmath.ZeroInt(),
},
},
},
valid: false,
},
{
desc: "duplicated usedAllocations",
name: "should prevent invalid address in auctionUsedAllocations",
genState: &types.GenesisState{
AuctionUsedAllocationsList: []types.AuctionUsedAllocations{
{
Address: addr1,
AuctionID: auctionID1,
},
},
},
valid: false,
},
{
name: "should prevent mismatch between usedAllocations and auctionUsedAllocations",
genState: &types.GenesisState{
UsedAllocationsList: []types.UsedAllocations{
{
Address: "0",
Address: addr1,
NumAllocations: sdkmath.NewInt(10),
},
},
AuctionUsedAllocationsList: []types.AuctionUsedAllocations{
{
Address: "0",
Address: addr1,
AuctionID: auctionID1,
NumAllocations: sdkmath.NewInt(2),
Withdrawn: false,
},
{
Address: addr1,
AuctionID: auctionID2,
NumAllocations: sdkmath.NewInt(8),
Withdrawn: true,
},
},
},
valid: false,
},
// this line is used by starport scaffolding # types/genesis/testcase
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.genState.Validate()
if tc.valid {
require.NoError(t, err)
Expand Down
11 changes: 11 additions & 0 deletions x/participation/types/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package types_test

import "math/rand"

var r *rand.Rand

// initialize random generator
func init() {
s := rand.NewSource(1)
r = rand.New(s)
}
6 changes: 0 additions & 6 deletions x/profile/types/message_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ func TestMsgUpdateValidatorDescription_ValidateBasic(t *testing.T) {
err error
}{
{
name: "should prevent validate invalid validator address",
msg: types.MsgUpdateValidatorDescription{
Address: "invalid address",
},
err: types.ErrInvalidValidatorAddress,
}, {
name: "should prevent validate emtpy description",
msg: types.MsgUpdateValidatorDescription{
Address: addr,
Expand Down

0 comments on commit 28829ed

Please sign in to comment.