Skip to content

Commit

Permalink
fix some tests cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 2, 2024
1 parent 7339325 commit 5185311
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 64 deletions.
8 changes: 3 additions & 5 deletions x/launch/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ func (gs GenesisState) Validate() error {
}

// Check for duplicated index in paramChange
paramChangeIndexMap := make(map[string]struct{})

paramChangeIndexMap := make(map[uint64]struct{})
for _, elem := range gs.ParamChangeList {
index := fmt.Sprint(elem.LaunchID)
if _, ok := paramChangeIndexMap[index]; ok {
if _, ok := paramChangeIndexMap[elem.LaunchID]; ok {
return fmt.Errorf("duplicated index for paramChange")
}
paramChangeIndexMap[index] = struct{}{}
paramChangeIndexMap[elem.LaunchID] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate

Expand Down
39 changes: 16 additions & 23 deletions x/monitoringc/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,47 @@ func (gs GenesisState) Validate() error {
}
// Check for duplicated index in launchIDFromChannelID
launchIDFromChannelIDIndexMap := make(map[string]struct{})

for _, elem := range gs.LaunchIDFromChannelIDList {
index := fmt.Sprint(elem.ChannelID)
if _, ok := launchIDFromChannelIDIndexMap[index]; ok {
if _, ok := launchIDFromChannelIDIndexMap[elem.ChannelID]; ok {
return fmt.Errorf("duplicated index for launchIDFromChannelID")
}
launchIDFromChannelIDIndexMap[index] = struct{}{}
launchIDFromChannelIDIndexMap[elem.ChannelID] = struct{}{}
}

// Check for duplicated index in launchIDFromVerifiedClientID
launchIDFromVerifiedClientIDIndexMap := make(map[string]struct{})

for _, elem := range gs.LaunchIDFromVerifiedClientIDList {
index := fmt.Sprint(elem.ClientID)
if _, ok := launchIDFromVerifiedClientIDIndexMap[index]; ok {
if _, ok := launchIDFromVerifiedClientIDIndexMap[elem.ClientID]; ok {
return fmt.Errorf("duplicated index for launchIDFromVerifiedClientID")
}
launchIDFromVerifiedClientIDIndexMap[index] = struct{}{}
launchIDFromVerifiedClientIDIndexMap[elem.ClientID] = struct{}{}
}
// Check for duplicated index in monitoringHistory
monitoringHistoryIndexMap := make(map[string]struct{})

// Check for duplicated index in monitoringHistory
monitoringHistoryIndexMap := make(map[uint64]struct{})
for _, elem := range gs.MonitoringHistoryList {
index := fmt.Sprint(elem.LaunchID)
if _, ok := monitoringHistoryIndexMap[index]; ok {
if _, ok := monitoringHistoryIndexMap[elem.LaunchID]; ok {
return fmt.Errorf("duplicated index for monitoringHistory")
}
monitoringHistoryIndexMap[index] = struct{}{}
monitoringHistoryIndexMap[elem.LaunchID] = struct{}{}
}

// Check for duplicated index in verifiedClientID
verifiedClientIDIndexMap := make(map[string]struct{})

verifiedClientIDIndexMap := make(map[uint64]struct{})
for _, elem := range gs.VerifiedClientIDList {
index := fmt.Sprint(elem.LaunchID)
if _, ok := verifiedClientIDIndexMap[index]; ok {
if _, ok := verifiedClientIDIndexMap[elem.LaunchID]; ok {
return fmt.Errorf("duplicated index for verifiedClientID")
}
verifiedClientIDIndexMap[index] = struct{}{}
verifiedClientIDIndexMap[elem.LaunchID] = struct{}{}
}
// Check for duplicated index in providerClientID
providerClientIDIndexMap := make(map[string]struct{})

// Check for duplicated index in providerClientID
providerClientIDIndexMap := make(map[uint64]struct{})
for _, elem := range gs.ProviderClientIDList {
index := fmt.Sprint(elem.LaunchID)
if _, ok := providerClientIDIndexMap[index]; ok {
if _, ok := providerClientIDIndexMap[elem.LaunchID]; ok {
return fmt.Errorf("duplicated index for providerClientID")
}
providerClientIDIndexMap[index] = struct{}{}
providerClientIDIndexMap[elem.LaunchID] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate

Expand Down
13 changes: 5 additions & 8 deletions x/participation/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@ func DefaultGenesis() *GenesisState {
func (gs GenesisState) Validate() error {
// Check for duplicated index in auctionUsedAllocations
auctionUsedAllocationsIndexMap := make(map[string]struct{})

for _, elem := range gs.AuctionUsedAllocationsList {
index := fmt.Sprint(elem.Address)
if _, ok := auctionUsedAllocationsIndexMap[index]; ok {
if _, ok := auctionUsedAllocationsIndexMap[elem.Address]; ok {
return fmt.Errorf("duplicated index for auctionUsedAllocations")
}
auctionUsedAllocationsIndexMap[index] = struct{}{}
auctionUsedAllocationsIndexMap[elem.Address] = struct{}{}
}

// Check for duplicated index in usedAllocations
usedAllocationsIndexMap := make(map[string]struct{})

for _, elem := range gs.UsedAllocationsList {
index := fmt.Sprint(elem.Address)
if _, ok := usedAllocationsIndexMap[index]; ok {
if _, ok := usedAllocationsIndexMap[elem.Address]; ok {
return fmt.Errorf("duplicated index for usedAllocations")
}
usedAllocationsIndexMap[index] = struct{}{}
usedAllocationsIndexMap[elem.Address] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate

Expand Down
16 changes: 6 additions & 10 deletions x/project/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ func DefaultGenesis() *GenesisState {
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in mainnetAccount
mainnetAccountIndexMap := make(map[string]struct{})

mainnetAccountIndexMap := make(map[uint64]struct{})
for _, elem := range gs.MainnetAccountList {
index := fmt.Sprint(elem.ProjectID)
if _, ok := mainnetAccountIndexMap[index]; ok {
if _, ok := mainnetAccountIndexMap[elem.ProjectID]; ok {
return fmt.Errorf("duplicated index for mainnetAccount")
}
mainnetAccountIndexMap[index] = struct{}{}
mainnetAccountIndexMap[elem.ProjectID] = struct{}{}
}
// Check for duplicated ID in project
projectIDMap := make(map[uint64]bool)
Expand All @@ -44,14 +42,12 @@ func (gs GenesisState) Validate() error {
projectIDMap[elem.ProjectID] = true
}
// Check for duplicated index in projectChains
projectChainsIndexMap := make(map[string]struct{})

projectChainsIndexMap := make(map[uint64]struct{})
for _, elem := range gs.ProjectChainsList {
index := fmt.Sprint(elem.ProjectID)
if _, ok := projectChainsIndexMap[index]; ok {
if _, ok := projectChainsIndexMap[elem.ProjectID]; ok {
return fmt.Errorf("duplicated index for projectChains")
}
projectChainsIndexMap[index] = struct{}{}
projectChainsIndexMap[elem.ProjectID] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate

Expand Down
11 changes: 6 additions & 5 deletions x/reward/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ func DefaultGenesis() *GenesisState {
// failure.
func (gs GenesisState) Validate() error {
// Check for duplicated index in rewardPool
rewardPoolIndexMap := make(map[string]struct{})

rewardPoolIndexMap := make(map[uint64]struct{})
for _, elem := range gs.RewardPoolList {
index := fmt.Sprint(elem.LaunchID)
if _, ok := rewardPoolIndexMap[index]; ok {
if err := elem.Validate(); err != nil {
return err
}
if _, ok := rewardPoolIndexMap[elem.LaunchID]; ok {
return fmt.Errorf("duplicated index for rewardPool")
}
rewardPoolIndexMap[index] = struct{}{}
rewardPoolIndexMap[elem.LaunchID] = struct{}{}
}
// this line is used by starport scaffolding # genesis/types/validate

Expand Down
13 changes: 0 additions & 13 deletions x/reward/types/reward_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ func TestRewardPool_Validate(t *testing.T) {
Closed: false,
},
},
{
name: "should prevent with invalid provider address",
rewardPool: types.RewardPool{
LaunchID: 1,
Provider: "invalid address",
InitialCoins: validInitialCoins,
RemainingCoins: validRemainingCoins,
LastRewardHeight: 50,
CurrentRewardHeight: 100,
Closed: false,
},
wantErr: true,
},
{
name: "should prevent with empty initial coins",
rewardPool: types.RewardPool{
Expand Down

0 comments on commit 5185311

Please sign in to comment.