Skip to content

Commit

Permalink
added missing validations in genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
NagaTulasi committed Dec 17, 2024
1 parent d0166dd commit a0f9572
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
28 changes: 26 additions & 2 deletions x/lightclient/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,37 @@ func DefaultGenesisState() GenesisState {
}

func (g GenesisState) Validate() error {

clientSet := make(map[string]struct{})
for _, client := range g.CanonicalClients {
if client.RollappId == "" {
return fmt.Errorf("invalid rollapp id: %v", client)
return fmt.Errorf("invalid rollapp_id: %v", client)
}
if client.IbcClientId == "" {
return fmt.Errorf("invalid ibc client id: %v", client)
return fmt.Errorf("invalid ibc_client_id: %v", client)
}

clientKey := client.RollappId + ":" + client.IbcClientId
if _, exists := clientSet[clientKey]; exists {
return fmt.Errorf("duplicate canonical client found: %v", client)
}
clientSet[clientKey] = struct{}{}
}

signerSet := make(map[string]struct{})
for _, signer := range g.HeaderSigners {
if signer.SequencerAddress == "" {
return fmt.Errorf("invalid sequencer address: %v", signer)
}
if signer.ClientId == "" {
return fmt.Errorf("invalid client id: %v", signer)
}

signerKey := signer.SequencerAddress + ":" + fmt.Sprint(signer.Height)
if _, exists := signerSet[signerKey]; exists {
return fmt.Errorf("duplicate signer entry found: %v", signer)
}
signerSet[signerKey] = struct{}{}
}

return nil
Expand Down
38 changes: 38 additions & 0 deletions x/lightclient/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,44 @@ func TestGenesisValidate(t *testing.T) {
g: types.DefaultGenesisState(),
valid: true,
},
{
name: "duplicate canonical client",
g: types.GenesisState{
CanonicalClients: []types.CanonicalClient{
{RollappId: "rollapp-1", IbcClientId: "client-1"},
{RollappId: "rollapp-1", IbcClientId: "client-1"},
},
},
valid: false,
},
{
name: "duplicate header signer",
g: types.GenesisState{
HeaderSigners: []types.HeaderSignerEntry{
{SequencerAddress: "sequencer1", ClientId: "client1", Height: 100},
{SequencerAddress: "sequencer1", ClientId: "client1", Height: 100},
},
},
valid: false,
},
{
name: "empty sequencer address in header signer",
g: types.GenesisState{
HeaderSigners: []types.HeaderSignerEntry{
{SequencerAddress: "", ClientId: "client1", Height: 100},
},
},
valid: false,
},
{
name: "empty client id in header signer",
g: types.GenesisState{
HeaderSigners: []types.HeaderSignerEntry{
{SequencerAddress: "sequencer1", ClientId: "", Height: 100},
},
},
valid: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit a0f9572

Please sign in to comment.