From 135552cd728c4c49d7e32f6c78201b91448c5a13 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 9 May 2013 23:47:12 -0500 Subject: [PATCH] Improve MsgBlock tests. This commit corrects the tests so that the main API functions are tested against the latest protocol version, but the TxSha and BlockSha functions are run against the specific protocol version used to encode the test data. This will help future proof the tests against protocol changes. --- msgblock_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/msgblock_test.go b/msgblock_test.go index 5693153e1..5a55bdffc 100644 --- a/msgblock_test.go +++ b/msgblock_test.go @@ -15,7 +15,7 @@ import ( // TestBlock tests the MsgBlock API. func TestBlock(t *testing.T) { - pver := uint32(60002) + pver := btcwire.ProtocolVersion // Block 1 header. prevHash := &blockOne.Header.PrevBlock @@ -67,8 +67,13 @@ func TestBlock(t *testing.T) { return } +// TestBlockTxShas tests the ability to generate a slice of all transaction +// hashes from a block accurately. func TestBlockTxShas(t *testing.T) { - pver := btcwire.ProtocolVersion + // Use protocol version 60002 specifically here instead of the latest + // because the test data is using bytes encoded with that protocol + // version. + pver := uint32(60002) // Block 1, transaction 1 hash. hashStr := "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098" @@ -89,8 +94,12 @@ func TestBlockTxShas(t *testing.T) { } } +// TestBlockSha tests the ability to generate the hash of a block accurately. func TestBlockSha(t *testing.T) { - pver := btcwire.ProtocolVersion + // Use protocol version 60002 specifically here instead of the latest + // because the test data is using bytes encoded with that protocol + // version. + pver := uint32(60002) // Block 1 hash. hashStr := "839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048" @@ -250,6 +259,7 @@ var blockOne btcwire.MsgBlock = btcwire.MsgBlock{ }, } +// Bytes encoded with protocol version 60002. var blockOneBytes = []byte{ 0x01, 0x00, 0x00, 0x00, // Version 1 0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,