Browse Source

Updated lite tests to set ConsensusHash in header

pull/972/head
Ethan Frey 7 years ago
committed by Ethan Buchman
parent
commit
45bc106de7
8 changed files with 22 additions and 18 deletions
  1. +3
    -3
      lite/dynamic_test.go
  2. +1
    -1
      lite/files/commit_test.go
  3. +1
    -1
      lite/files/provider_test.go
  4. +6
    -5
      lite/helpers.go
  5. +6
    -3
      lite/inquirer_test.go
  6. +2
    -2
      lite/performance_test.go
  7. +2
    -2
      lite/provider_test.go
  8. +1
    -1
      lite/static_test.go

+ 3
- 3
lite/dynamic_test.go View File

@ -46,7 +46,7 @@ func TestDynamicCert(t *testing.T) {
for _, tc := range cases {
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)
if tc.proper {
assert.Nil(err, "%+v", err)
@ -71,7 +71,7 @@ func TestDynamicUpdate(t *testing.T) {
// one valid block to give us a sense of time
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)
require.Nil(err, "%+v", err)
@ -109,7 +109,7 @@ func TestDynamicUpdate(t *testing.T) {
for _, tc := range cases {
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)
if tc.proper {
assert.Nil(err, "%d: %+v", tc.height, err)


+ 1
- 1
lite/files/commit_test.go View File

@ -29,7 +29,7 @@ func TestSerializeFullCommits(t *testing.T) {
// build a fc
keys := lite.GenValKeys(5)
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(vals.Hash(), fc.ValidatorsHash())


+ 1
- 1
lite/files/provider_test.go View File

@ -46,7 +46,7 @@ func TestFileProvider(t *testing.T) {
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
vals := keys.ToValidators(10, int64(count/2))
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)
}


+ 6
- 5
lite/helpers.go View File

@ -110,7 +110,7 @@ func makeVote(header *types.Header, vals *types.ValidatorSet, key crypto.PrivKey
// Silences warning that vals can also be merkle.Hashable
// nolint: interfacer
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{
ChainID: chainID,
@ -123,14 +123,15 @@ func genHeader(chainID string, height int64, txs types.Txs,
ValidatorsHash: vals.Hash(),
DataHash: txs.Hash(),
AppHash: appHash,
ConsensusHash: consHash,
}
}
// GenCommit calls genHeader and signHeader and combines them into a Commit.
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{
Header: header,
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.
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{
Header: header,
Commit: v.signHeader(header, first, last),


+ 6
- 3
lite/inquirer_test.go View File

@ -22,6 +22,7 @@ func TestInquirerValidPath(t *testing.T) {
// construct a bunch of commits, each with one more height than the last
chainID := "inquiry-test"
consHash := []byte("params")
count := 50
commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ {
@ -30,7 +31,7 @@ func TestInquirerValidPath(t *testing.T) {
vals := keys.ToValidators(vote, 0)
h := int64(20 + 10*i)
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
@ -69,6 +70,7 @@ func TestInquirerMinimalPath(t *testing.T) {
// construct a bunch of commits, each with one more height than the last
chainID := "minimal-path"
consHash := []byte("other-params")
count := 12
commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ {
@ -77,7 +79,7 @@ func TestInquirerMinimalPath(t *testing.T) {
vals := keys.ToValidators(vote, 0)
h := int64(5 + 10*i)
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
@ -117,6 +119,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
// construct a bunch of commits, each with one more height than the last
chainID := "inquiry-test"
count := 10
consHash := []byte("special-params")
commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ {
// extend the keys by 1 each time
@ -124,7 +127,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
vals := keys.ToValidators(vote, 0)
h := int64(20 + 10*i)
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


+ 2
- 2
lite/performance_test.go View File

@ -33,7 +33,7 @@ func benchmarkGenCommit(b *testing.B, keys lite.ValKeys) {
for i := 0; i < b.N; i++ {
h := int64(1 + i)
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"
vals := keys.ToValidators(20, 10)
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++ {
err := cert.Certify(check)
if err != nil {


+ 2
- 2
lite/provider_test.go View File

@ -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), ...
vals := keys.ToValidators(10, int64(count/2))
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
@ -129,7 +129,7 @@ func TestCacheGetsBestHeight(t *testing.T) {
for i := 0; i < count; i++ {
vals := keys.ToValidators(10, int64(count/2))
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)
require.NoError(err)
}


+ 1
- 1
lite/static_test.go View File

@ -44,7 +44,7 @@ func TestStaticCert(t *testing.T) {
for _, tc := range cases {
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)
if tc.proper {
assert.Nil(err, "%+v", err)


Loading…
Cancel
Save