github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/lite/base_verifier_test.go (about)

     1  package lite
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/tendermint/tendermint/crypto/tmhash"
     9  	lerr "github.com/tendermint/tendermint/lite/errors"
    10  	"github.com/tendermint/tendermint/types"
    11  )
    12  
    13  func TestBaseCert(t *testing.T) {
    14  	// TODO: Requires proposer address to be set in header.
    15  	t.SkipNow()
    16  
    17  	assert := assert.New(t)
    18  
    19  	keys := genPrivKeys(4)
    20  	// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
    21  	vals := keys.ToValidators(20, 10)
    22  	// and a Verifier based on our known set
    23  	chainID := "test-static"
    24  	cert := NewBaseVerifier(chainID, 2, vals)
    25  
    26  	cases := []struct {
    27  		keys        privKeys
    28  		vals        *types.ValidatorSet
    29  		height      int64
    30  		first, last int  // who actually signs
    31  		proper      bool // true -> expect no error
    32  		changed     bool // true -> expect validator change error
    33  	}{
    34  		// height regression
    35  		{keys, vals, 1, 0, len(keys), false, false},
    36  		// perfect, signed by everyone
    37  		{keys, vals, 2, 0, len(keys), true, false},
    38  		// skip little guy is okay
    39  		{keys, vals, 3, 1, len(keys), true, false},
    40  		// but not the big guy
    41  		{keys, vals, 4, 0, len(keys) - 1, false, false},
    42  		// Changing the power a little bit breaks the static validator.
    43  		// The sigs are enough, but the validator hash is unknown.
    44  		{keys, keys.ToValidators(20, 11), 5, 0, len(keys), false, true},
    45  	}
    46  
    47  	for _, tc := range cases {
    48  		sh := tc.keys.GenSignedHeader(
    49  			chainID, tc.height, nil, tc.vals, tc.vals,
    50  			tmhash.Sum([]byte("foo")),
    51  			tmhash.Sum([]byte("params")),
    52  			tmhash.Sum([]byte("results")),
    53  			tc.first, tc.last,
    54  		)
    55  
    56  		err := cert.Verify(sh)
    57  		if tc.proper {
    58  			assert.Nil(err, "%+v", err)
    59  		} else {
    60  			assert.NotNil(err)
    61  			if tc.changed {
    62  				assert.True(lerr.IsErrUnexpectedValidators(err), "%+v", err)
    63  			}
    64  		}
    65  	}
    66  }