github.com/evdatsion/aphelion-dpos-bft@v0.32.1/rpc/core/blocks_test.go (about)

     1  package core
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestBlockchainInfo(t *testing.T) {
    11  
    12  	cases := []struct {
    13  		min, max     int64
    14  		height       int64
    15  		limit        int64
    16  		resultLength int64
    17  		wantErr      bool
    18  	}{
    19  
    20  		// min > max
    21  		{0, 0, 0, 10, 0, true},  // min set to 1
    22  		{0, 1, 0, 10, 0, true},  // max set to height (0)
    23  		{0, 0, 1, 10, 1, false}, // max set to height (1)
    24  		{2, 0, 1, 10, 0, true},  // max set to height (1)
    25  		{2, 1, 5, 10, 0, true},
    26  
    27  		// negative
    28  		{1, 10, 14, 10, 10, false}, // control
    29  		{-1, 10, 14, 10, 0, true},
    30  		{1, -10, 14, 10, 0, true},
    31  		{-9223372036854775808, -9223372036854775788, 100, 20, 0, true},
    32  
    33  		// check limit and height
    34  		{1, 1, 1, 10, 1, false},
    35  		{1, 1, 5, 10, 1, false},
    36  		{2, 2, 5, 10, 1, false},
    37  		{1, 2, 5, 10, 2, false},
    38  		{1, 5, 1, 10, 1, false},
    39  		{1, 5, 10, 10, 5, false},
    40  		{1, 15, 10, 10, 10, false},
    41  		{1, 15, 15, 10, 10, false},
    42  		{1, 15, 15, 20, 15, false},
    43  		{1, 20, 15, 20, 15, false},
    44  		{1, 20, 20, 20, 20, false},
    45  	}
    46  
    47  	for i, c := range cases {
    48  		caseString := fmt.Sprintf("test %d failed", i)
    49  		min, max, err := filterMinMax(c.height, c.min, c.max, c.limit)
    50  		if c.wantErr {
    51  			require.Error(t, err, caseString)
    52  		} else {
    53  			require.NoError(t, err, caseString)
    54  			require.Equal(t, 1+max-min, c.resultLength, caseString)
    55  		}
    56  	}
    57  
    58  }