aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/block_test.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-27 17:00:18 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2018-10-27 17:00:18 +0800
commitf4a9edfab58063f42526c08b27311a871f8b7207 (patch)
treebe7e194dd5aeb136f877111457cc1f60f94d44a7 /core/types/block_test.go
parent47c29f1bc537f2108755f943e190a9f9a58c1ac0 (diff)
downloaddexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar.gz
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar.bz2
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar.lz
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar.xz
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.tar.zst
dexon-consensus-f4a9edfab58063f42526c08b27311a871f8b7207.zip
core: Fix missing fields when cloning blocks. (#268)
Diffstat (limited to 'core/types/block_test.go')
-rw-r--r--core/types/block_test.go36
1 files changed, 32 insertions, 4 deletions
diff --git a/core/types/block_test.go b/core/types/block_test.go
index 7bf6a75..4b899e1 100644
--- a/core/types/block_test.go
+++ b/core/types/block_test.go
@@ -40,12 +40,33 @@ func (s *BlockTestSuite) randomBytes() []byte {
return h[:]
}
+func (s *BlockTestSuite) noZeroInStruct(v reflect.Value) {
+ t := v.Type()
+ for i := 0; i < t.NumField(); i++ {
+ tf := t.Field(i)
+ vf := v.FieldByName(tf.Name)
+ if vf.Type().Kind() == reflect.Struct {
+ s.noZeroInStruct(vf)
+ continue
+ }
+ if !vf.CanInterface() {
+ s.T().Log("unable to check private field", tf.Name)
+ continue
+ }
+ if reflect.DeepEqual(
+ vf.Interface(), reflect.Zero(vf.Type()).Interface()) {
+ s.Failf("", "should not be zero value %s", tf.Name)
+ }
+ }
+}
+
func (s *BlockTestSuite) createRandomBlock() *Block {
b := &Block{
ProposerID: NodeID{common.NewRandomHash()},
ParentHash: common.NewRandomHash(),
Hash: common.NewRandomHash(),
Position: Position{
+ Round: rand.Uint64(),
ChainID: rand.Uint32(),
Height: rand.Uint64(),
},
@@ -59,15 +80,22 @@ func (s *BlockTestSuite) createRandomBlock() *Block {
Data: s.randomBytes(),
},
Finalization: FinalizationResult{
+ ParentHash: common.NewRandomHash(),
Timestamp: time.Now().UTC(),
Height: rand.Uint64(),
Randomness: s.randomBytes(),
},
- Payload: s.randomBytes(),
- Signature: crypto.Signature{Signature: s.randomBytes()},
- CRSSignature: crypto.Signature{Signature: s.randomBytes()},
+ Payload: s.randomBytes(),
+ Signature: crypto.Signature{
+ Type: "some type",
+ Signature: s.randomBytes()},
+ CRSSignature: crypto.Signature{
+ Type: "some type",
+ Signature: s.randomBytes(),
+ },
}
-
+ // Check if all fields are initialized with non zero values.
+ s.noZeroInStruct(reflect.ValueOf(*b))
return b
}