Skip to content

Commit

Permalink
added additional check as reponse is ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Apr 4, 2024
1 parent b81f064 commit 50fbf2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ func (d *HubClient) GetLatestBatch(rollappID string) (*settlement.ResultRetrieve
return nil, err
}

// not supposed to happen, but just in case
if latestStateInfoIndexResp == nil {
return nil, settlement.ErrEmptyResponse
}

Check warning on line 312 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L311-L312

Added lines #L311 - L312 were not covered by tests

latestBatch, err := d.GetBatchAtIndex(rollappID, latestStateInfoIndexResp.StateIndex.Index)
if err != nil {
return nil, err
Expand All @@ -332,9 +337,11 @@ func (d *HubClient) GetBatchAtIndex(rollappID string, index uint64) (*settlement
if err != nil {
return nil, err
}
// not supposed to happen, but just in case
if stateInfoResp == nil {
return nil, settlement.ErrBatchNotFound
return nil, settlement.ErrEmptyResponse
}

Check warning on line 343 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L342-L343

Added lines #L342 - L343 were not covered by tests

return d.convertStateInfoToResultRetrieveBatch(&stateInfoResp.StateInfo)
}

Expand All @@ -356,6 +363,11 @@ func (d *HubClient) GetSequencers(rollappID string) ([]*types.Sequencer, error)
return nil, err
}

Check warning on line 364 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L363-L364

Added lines #L363 - L364 were not covered by tests

// not supposed to happen, but just in case
if res == nil {
return nil, settlement.ErrEmptyResponse

Check warning on line 368 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L368

Added line #L368 was not covered by tests
}

sequencersList := make([]*types.Sequencer, 0, len(res.Sequencers))
for _, sequencer := range res.Sequencers {
var pubKey cryptotypes.PubKey
Expand Down
2 changes: 2 additions & 0 deletions settlement/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "errors"
var (
// ErrBatchNotFound is returned when a batch is not found for the rollapp.
ErrBatchNotFound = errors.New("batch not found")
// ErrEmptyResponse is returned when the response is empty.
ErrEmptyResponse = errors.New("empty response")
// ErrNoSequencerForRollapp is returned when a sequencer is not found for the rollapp.
ErrNoSequencerForRollapp = errors.New("no sequencer registered on the hub for this rollapp")
// ErrBatchNotAccepted is returned when a batch is not accepted by the settlement layer.
Expand Down

0 comments on commit 50fbf2b

Please sign in to comment.