Browse Source

lite/proxy: consolidate some common test headers into a variable

Addressing some feedback from @ebuchman in regards to
consolidating some common test headers into a variable.

I've added that for simple cases, trying to meet in the middle
instead of creating helpers that obscure readibility and easy
comparison of test cases.
pull/1300/head
Emmanuel T Odeke 7 years ago
parent
commit
8813684040
No known key found for this signature in database GPG Key ID: 410DDC670CF9BFD7
1 changed files with 15 additions and 44 deletions
  1. +15
    -44
      lite/proxy/validate_test.go

+ 15
- 44
lite/proxy/validate_test.go View File

@ -12,10 +12,17 @@ import (
) )
var ( var (
deadBeefTxs = types.Txs{[]byte("DE"), []byte("AD"), []byte("BE"), []byte("EF")}
deadBeefTxs = types.Txs{[]byte("DE"), []byte("AD"), []byte("BE"), []byte("EF")}
deadBeefRipEmd160Hash = deadBeefTxs.Hash() deadBeefRipEmd160Hash = deadBeefTxs.Hash()
) )
var hdrHeight11Tendermint = &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
}
func TestValidateBlock(t *testing.T) { func TestValidateBlock(t *testing.T) {
tests := []struct { tests := []struct {
block *types.Block block *types.Block
@ -47,32 +54,14 @@ func TestValidateBlock(t *testing.T) {
// Start Header.Hash mismatch test // Start Header.Hash mismatch test
{ {
block: &types.Block{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
block: &types.Block{Header: hdrHeight11Tendermint},
commit: lite.Commit{Header: &types.Header{Height: 11}}, commit: lite.Commit{Header: &types.Header{Height: 11}},
wantErr: "Headers don't match", wantErr: "Headers don't match",
}, },
{ {
block: &types.Block{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
commit: lite.Commit{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
block: &types.Block{Header: hdrHeight11Tendermint},
commit: lite.Commit{Header: hdrHeight11Tendermint},
}, },
// End Header.Hash mismatch test // End Header.Hash mismatch test
@ -147,32 +136,14 @@ func TestValidateBlockMeta(t *testing.T) {
// Start Headers don't match test // Start Headers don't match test
{ {
meta: &types.BlockMeta{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
meta: &types.BlockMeta{Header: hdrHeight11Tendermint},
commit: lite.Commit{Header: &types.Header{Height: 11}}, commit: lite.Commit{Header: &types.Header{Height: 11}},
wantErr: "Headers don't match", wantErr: "Headers don't match",
}, },
{ {
meta: &types.BlockMeta{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
commit: lite.Commit{
Header: &types.Header{
Height: 11,
Time: time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC),
ValidatorsHash: []byte("Tendermint"),
},
},
meta: &types.BlockMeta{Header: hdrHeight11Tendermint},
commit: lite.Commit{Header: hdrHeight11Tendermint},
}, },
{ {
@ -208,7 +179,7 @@ func TestValidateBlockMeta(t *testing.T) {
Header: &types.Header{ Header: &types.Header{
Height: 11, DataHash: deadBeefRipEmd160Hash, Height: 11, DataHash: deadBeefRipEmd160Hash,
ValidatorsHash: []byte("Tendermint"), ValidatorsHash: []byte("Tendermint"),
Time: time.Date(2017, 1, 2, 2, 1, 1, 1, time.UTC),
Time: time.Date(2018, 1, 2, 1, 1, 1, 1, time.UTC),
}, },
Commit: &types.Commit{BlockID: types.BlockID{Hash: []byte("DEADBEEF")}}, Commit: &types.Commit{BlockID: types.BlockID{Hash: []byte("DEADBEEF")}},
}, },


Loading…
Cancel
Save