Skip to content

Commit

Permalink
add more assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 6, 2024
1 parent 601db42 commit c3537a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/lanes/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func NewMempool[C comparable](
) (*Mempool[C], error) {
if !ratio.IsPositive() {
return nil, errors.New("mempool creation; ratio must be positive")
} else if ratio.GT(math.LegacyOneDec()) {
return nil, errors.New("mempool creation; ratio must be less than or equal to 1")
}
if txEncoder == nil {
return nil, errors.New("mempool creation; tx encoder is nil")
}

Check warning on line 61 in app/lanes/mempool.go

View check run for this annotation

Codecov / codecov/patch

app/lanes/mempool.go#L60-L61

Added lines #L60 - L61 were not covered by tests

return &Mempool[C]{
Expand Down
22 changes: 22 additions & 0 deletions app/lanes/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ func Test_MempoolInsert(t *testing.T) {
signerExtractor := signer_extraction.NewDefaultAdapter()
encodingConfig := params.MakeEncodingConfig()
txEncoder := encodingConfig.TxConfig.TxEncoder()

// cannot create mempool with negative ratio
_, err := lanes.NewMempool(
blockbase.NewDefaultTxPriority(),
signerExtractor,
1, // max txs
math.LegacyNewDecFromInt(math.NewInt(-1)), // max block space
txEncoder,
)
require.Error(t, err)

// cannot create mempool with ratio greater than 1
_, err = lanes.NewMempool(
blockbase.NewDefaultTxPriority(),
signerExtractor,
1, // max txs
math.LegacyNewDecFromInt(math.NewInt(2)), // max block space
txEncoder,
)
require.Error(t, err)

// valid creation
mempool, err := lanes.NewMempool(
blockbase.NewDefaultTxPriority(),
signerExtractor,
Expand Down

0 comments on commit c3537a8

Please sign in to comment.