You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
666 B
27 lines
666 B
7 years ago
|
package blockchain
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestBlockSerialize(t *testing.T) {
|
||
|
cbtx := NewCoinbaseTX("minh", genesisCoinbaseData)
|
||
|
block := NewGenesisBlock(cbtx)
|
||
|
|
||
|
serializedValue := block.Serialize()
|
||
|
deserializedBlock := DeserializeBlock(serializedValue)
|
||
|
|
||
|
if block.Timestamp != deserializedBlock.Timestamp {
|
||
|
t.Errorf("Serialize or Deserialize incorrect at TimeStamp.")
|
||
|
}
|
||
|
|
||
|
if bytes.Compare(block.PrevBlockHash, deserializedBlock.PrevBlockHash) != 0 {
|
||
|
t.Errorf("Serialize or Deserialize incorrect at PrevBlockHash.")
|
||
|
}
|
||
|
|
||
|
if bytes.Compare(block.Hash, deserializedBlock.Hash) != 0 {
|
||
|
t.Errorf("Serialize or Deserialize incorrect at Hash.")
|
||
|
}
|
||
|
}
|