github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/mempool/mempool_test.go (about)

     1  package mempool
     2  
     3  import (
     4  	"testing"
     5  
     6  	abci "github.com/line/ostracon/abci/types"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestPostCheckMaxGas(t *testing.T) {
    11  	tests := []struct {
    12  		res       *abci.ResponseCheckTx
    13  		postCheck PostCheckFunc
    14  		ok        bool
    15  	}{
    16  		{&abci.ResponseCheckTx{GasWanted: 10}, PostCheckMaxGas(10), true},
    17  		{&abci.ResponseCheckTx{GasWanted: 10}, PostCheckMaxGas(-1), true},
    18  		{&abci.ResponseCheckTx{GasWanted: -1}, PostCheckMaxGas(10), false},
    19  		{&abci.ResponseCheckTx{GasWanted: 11}, PostCheckMaxGas(10), false},
    20  	}
    21  	for tcIndex, tt := range tests {
    22  		err := tt.postCheck(nil, tt.res)
    23  		if tt.ok {
    24  			require.NoError(t, err, "postCheck should not return error, on test case %d", tcIndex)
    25  		} else {
    26  			require.Error(t, err, "postCheck should return error, on test case %d", tcIndex)
    27  		}
    28  	}
    29  }