mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-20 16:36:31 +00:00
Updated lite tests to set ConsensusHash in header
This commit is contained in:
committed by
Ethan Buchman
parent
d151e36ea8
commit
45bc106de7
@ -46,7 +46,7 @@ func TestDynamicCert(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
check := tc.keys.GenCommit(chainID, tc.height, nil, tc.vals,
|
check := tc.keys.GenCommit(chainID, tc.height, nil, tc.vals,
|
||||||
[]byte("bar"), tc.first, tc.last)
|
[]byte("bar"), []byte("params"), tc.first, tc.last)
|
||||||
err := cert.Certify(check)
|
err := cert.Certify(check)
|
||||||
if tc.proper {
|
if tc.proper {
|
||||||
assert.Nil(err, "%+v", err)
|
assert.Nil(err, "%+v", err)
|
||||||
@ -71,7 +71,7 @@ func TestDynamicUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// one valid block to give us a sense of time
|
// one valid block to give us a sense of time
|
||||||
h := int64(100)
|
h := int64(100)
|
||||||
good := keys.GenCommit(chainID, h, nil, vals, []byte("foo"), 0, len(keys))
|
good := keys.GenCommit(chainID, h, nil, vals, []byte("foo"), []byte("params"), 0, len(keys))
|
||||||
err := cert.Certify(good)
|
err := cert.Certify(good)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ func TestDynamicUpdate(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
fc := tc.keys.GenFullCommit(chainID, tc.height, nil, tc.vals,
|
fc := tc.keys.GenFullCommit(chainID, tc.height, nil, tc.vals,
|
||||||
[]byte("bar"), tc.first, tc.last)
|
[]byte("bar"), []byte("params"), tc.first, tc.last)
|
||||||
err := cert.Update(fc)
|
err := cert.Update(fc)
|
||||||
if tc.proper {
|
if tc.proper {
|
||||||
assert.Nil(err, "%d: %+v", tc.height, err)
|
assert.Nil(err, "%d: %+v", tc.height, err)
|
||||||
|
@ -29,7 +29,7 @@ func TestSerializeFullCommits(t *testing.T) {
|
|||||||
// build a fc
|
// build a fc
|
||||||
keys := lite.GenValKeys(5)
|
keys := lite.GenValKeys(5)
|
||||||
vals := keys.ToValidators(10, 0)
|
vals := keys.ToValidators(10, 0)
|
||||||
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5)
|
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, []byte("params"), 0, 5)
|
||||||
|
|
||||||
require.Equal(h, fc.Height())
|
require.Equal(h, fc.Height())
|
||||||
require.Equal(vals.Hash(), fc.ValidatorsHash())
|
require.Equal(vals.Hash(), fc.ValidatorsHash())
|
||||||
|
@ -46,7 +46,7 @@ func TestFileProvider(t *testing.T) {
|
|||||||
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
|
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
|
||||||
vals := keys.ToValidators(10, int64(count/2))
|
vals := keys.ToValidators(10, int64(count/2))
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
check := keys.GenCommit(chainID, h, nil, vals, appHash, 0, 5)
|
check := keys.GenCommit(chainID, h, nil, vals, appHash, []byte("params"), 0, 5)
|
||||||
seeds[i] = lite.NewFullCommit(check, vals)
|
seeds[i] = lite.NewFullCommit(check, vals)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func makeVote(header *types.Header, vals *types.ValidatorSet, key crypto.PrivKey
|
|||||||
// Silences warning that vals can also be merkle.Hashable
|
// Silences warning that vals can also be merkle.Hashable
|
||||||
// nolint: interfacer
|
// nolint: interfacer
|
||||||
func genHeader(chainID string, height int64, txs types.Txs,
|
func genHeader(chainID string, height int64, txs types.Txs,
|
||||||
vals *types.ValidatorSet, appHash []byte) *types.Header {
|
vals *types.ValidatorSet, appHash, consHash []byte) *types.Header {
|
||||||
|
|
||||||
return &types.Header{
|
return &types.Header{
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
@ -123,14 +123,15 @@ func genHeader(chainID string, height int64, txs types.Txs,
|
|||||||
ValidatorsHash: vals.Hash(),
|
ValidatorsHash: vals.Hash(),
|
||||||
DataHash: txs.Hash(),
|
DataHash: txs.Hash(),
|
||||||
AppHash: appHash,
|
AppHash: appHash,
|
||||||
|
ConsensusHash: consHash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenCommit calls genHeader and signHeader and combines them into a Commit.
|
// GenCommit calls genHeader and signHeader and combines them into a Commit.
|
||||||
func (v ValKeys) GenCommit(chainID string, height int64, txs types.Txs,
|
func (v ValKeys) GenCommit(chainID string, height int64, txs types.Txs,
|
||||||
vals *types.ValidatorSet, appHash []byte, first, last int) Commit {
|
vals *types.ValidatorSet, appHash, consHash []byte, first, last int) Commit {
|
||||||
|
|
||||||
header := genHeader(chainID, height, txs, vals, appHash)
|
header := genHeader(chainID, height, txs, vals, appHash, consHash)
|
||||||
check := Commit{
|
check := Commit{
|
||||||
Header: header,
|
Header: header,
|
||||||
Commit: v.signHeader(header, first, last),
|
Commit: v.signHeader(header, first, last),
|
||||||
@ -140,9 +141,9 @@ func (v ValKeys) GenCommit(chainID string, height int64, txs types.Txs,
|
|||||||
|
|
||||||
// GenFullCommit calls genHeader and signHeader and combines them into a Commit.
|
// GenFullCommit calls genHeader and signHeader and combines them into a Commit.
|
||||||
func (v ValKeys) GenFullCommit(chainID string, height int64, txs types.Txs,
|
func (v ValKeys) GenFullCommit(chainID string, height int64, txs types.Txs,
|
||||||
vals *types.ValidatorSet, appHash []byte, first, last int) FullCommit {
|
vals *types.ValidatorSet, appHash, consHash []byte, first, last int) FullCommit {
|
||||||
|
|
||||||
header := genHeader(chainID, height, txs, vals, appHash)
|
header := genHeader(chainID, height, txs, vals, appHash, consHash)
|
||||||
commit := Commit{
|
commit := Commit{
|
||||||
Header: header,
|
Header: header,
|
||||||
Commit: v.signHeader(header, first, last),
|
Commit: v.signHeader(header, first, last),
|
||||||
|
@ -22,6 +22,7 @@ func TestInquirerValidPath(t *testing.T) {
|
|||||||
|
|
||||||
// construct a bunch of commits, each with one more height than the last
|
// construct a bunch of commits, each with one more height than the last
|
||||||
chainID := "inquiry-test"
|
chainID := "inquiry-test"
|
||||||
|
consHash := []byte("params")
|
||||||
count := 50
|
count := 50
|
||||||
commits := make([]lite.FullCommit, count)
|
commits := make([]lite.FullCommit, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
@ -30,7 +31,7 @@ func TestInquirerValidPath(t *testing.T) {
|
|||||||
vals := keys.ToValidators(vote, 0)
|
vals := keys.ToValidators(vote, 0)
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, 0, len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
@ -69,6 +70,7 @@ func TestInquirerMinimalPath(t *testing.T) {
|
|||||||
|
|
||||||
// construct a bunch of commits, each with one more height than the last
|
// construct a bunch of commits, each with one more height than the last
|
||||||
chainID := "minimal-path"
|
chainID := "minimal-path"
|
||||||
|
consHash := []byte("other-params")
|
||||||
count := 12
|
count := 12
|
||||||
commits := make([]lite.FullCommit, count)
|
commits := make([]lite.FullCommit, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
@ -77,7 +79,7 @@ func TestInquirerMinimalPath(t *testing.T) {
|
|||||||
vals := keys.ToValidators(vote, 0)
|
vals := keys.ToValidators(vote, 0)
|
||||||
h := int64(5 + 10*i)
|
h := int64(5 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, 0, len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
@ -117,6 +119,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
|
|||||||
// construct a bunch of commits, each with one more height than the last
|
// construct a bunch of commits, each with one more height than the last
|
||||||
chainID := "inquiry-test"
|
chainID := "inquiry-test"
|
||||||
count := 10
|
count := 10
|
||||||
|
consHash := []byte("special-params")
|
||||||
commits := make([]lite.FullCommit, count)
|
commits := make([]lite.FullCommit, count)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
// extend the keys by 1 each time
|
// extend the keys by 1 each time
|
||||||
@ -124,7 +127,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
|
|||||||
vals := keys.ToValidators(vote, 0)
|
vals := keys.ToValidators(vote, 0)
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, 0, len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
|
@ -33,7 +33,7 @@ func benchmarkGenCommit(b *testing.B, keys lite.ValKeys) {
|
|||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h := int64(1 + i)
|
h := int64(1 + i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
keys.GenCommit(chainID, h, nil, vals, appHash, 0, len(keys))
|
keys.GenCommit(chainID, h, nil, vals, appHash, []byte("params"), 0, len(keys))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ func benchmarkCertifyCommit(b *testing.B, keys lite.ValKeys) {
|
|||||||
chainID := "bench-certify"
|
chainID := "bench-certify"
|
||||||
vals := keys.ToValidators(20, 10)
|
vals := keys.ToValidators(20, 10)
|
||||||
cert := lite.NewStatic(chainID, vals)
|
cert := lite.NewStatic(chainID, vals)
|
||||||
check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), 0, len(keys))
|
check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), []byte("params"), 0, len(keys))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
err := cert.Certify(check)
|
err := cert.Certify(check)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,7 +58,7 @@ func checkProvider(t *testing.T, p lite.Provider, chainID, app string) {
|
|||||||
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
|
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
|
||||||
vals := keys.ToValidators(10, int64(count/2))
|
vals := keys.ToValidators(10, int64(count/2))
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5)
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, []byte("params"), 0, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check provider is empty
|
// check provider is empty
|
||||||
@ -129,7 +129,7 @@ func TestCacheGetsBestHeight(t *testing.T) {
|
|||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
vals := keys.ToValidators(10, int64(count/2))
|
vals := keys.ToValidators(10, int64(count/2))
|
||||||
h := int64(10 * (i + 1))
|
h := int64(10 * (i + 1))
|
||||||
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5)
|
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, []byte("params"), 0, 5)
|
||||||
err := p2.StoreCommit(fc)
|
err := p2.StoreCommit(fc)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func TestStaticCert(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
check := tc.keys.GenCommit(chainID, tc.height, nil, tc.vals,
|
check := tc.keys.GenCommit(chainID, tc.height, nil, tc.vals,
|
||||||
[]byte("foo"), tc.first, tc.last)
|
[]byte("foo"), []byte("params"), tc.first, tc.last)
|
||||||
err := cert.Certify(check)
|
err := cert.Certify(check)
|
||||||
if tc.proper {
|
if tc.proper {
|
||||||
assert.Nil(err, "%+v", err)
|
assert.Nil(err, "%+v", err)
|
||||||
|
Reference in New Issue
Block a user