Improve MsgGetBlocks tests.

This commit corrects the MsgGetBlocks tests so that the protocol version
in the multiLocators data matches the wire encoded test data.  This will
help future proof the tests against protocol changes.  Also, while here
modify the casing of the local vars to be consistent.
This commit is contained in:
Dave Collins 2013-05-10 00:36:49 -05:00
parent 135552cd72
commit e026f50486

View file

@ -108,9 +108,9 @@ func TestGetBlocksWire(t *testing.T) {
} }
// MsgGetBlocks message with no block locators or stop hash. // MsgGetBlocks message with no block locators or stop hash.
NoLocators := btcwire.NewMsgGetBlocks(&btcwire.ShaHash{}) noLocators := btcwire.NewMsgGetBlocks(&btcwire.ShaHash{})
NoLocators.ProtocolVersion = pver noLocators.ProtocolVersion = pver
NoLocatorsEncoded := []byte{ noLocatorsEncoded := []byte{
0x62, 0xea, 0x00, 0x00, // Protocol version 60002 0x62, 0xea, 0x00, 0x00, // Protocol version 60002
0x00, // Varint for number of block locator hashes 0x00, // Varint for number of block locator hashes
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -120,10 +120,11 @@ func TestGetBlocksWire(t *testing.T) {
} }
// MsgGetBlocks message with multiple block locators and a stop hash. // MsgGetBlocks message with multiple block locators and a stop hash.
MultiLocators := btcwire.NewMsgGetBlocks(hashStop) multiLocators := btcwire.NewMsgGetBlocks(hashStop)
MultiLocators.AddBlockLocatorHash(hashLocator2) multiLocators.AddBlockLocatorHash(hashLocator2)
MultiLocators.AddBlockLocatorHash(hashLocator) multiLocators.AddBlockLocatorHash(hashLocator)
MultiLocatorsEncoded := []byte{ multiLocators.ProtocolVersion = pver
multiLocatorsEncoded := []byte{
0x62, 0xea, 0x00, 0x00, // Protocol version 60002 0x62, 0xea, 0x00, 0x00, // Protocol version 60002
0x02, // Varint for number of block locator hashes 0x02, // Varint for number of block locator hashes
0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63, 0xe0, 0xde, 0x06, 0x44, 0x68, 0x13, 0x2c, 0x63,
@ -148,81 +149,81 @@ func TestGetBlocksWire(t *testing.T) {
}{ }{
// Latest protocol version with no block locators. // Latest protocol version with no block locators.
{ {
NoLocators, noLocators,
NoLocators, noLocators,
NoLocatorsEncoded, noLocatorsEncoded,
btcwire.ProtocolVersion, btcwire.ProtocolVersion,
}, },
// Latest protocol version with multiple block locators. // Latest protocol version with multiple block locators.
{ {
MultiLocators, multiLocators,
MultiLocators, multiLocators,
MultiLocatorsEncoded, multiLocatorsEncoded,
btcwire.ProtocolVersion, btcwire.ProtocolVersion,
}, },
// Protocol version BIP0035Version with no block locators. // Protocol version BIP0035Version with no block locators.
{ {
NoLocators, noLocators,
NoLocators, noLocators,
NoLocatorsEncoded, noLocatorsEncoded,
btcwire.BIP0035Version, btcwire.BIP0035Version,
}, },
// Protocol version BIP0035Version with multiple block locators. // Protocol version BIP0035Version with multiple block locators.
{ {
MultiLocators, multiLocators,
MultiLocators, multiLocators,
MultiLocatorsEncoded, multiLocatorsEncoded,
btcwire.BIP0035Version, btcwire.BIP0035Version,
}, },
// Protocol version BIP0031Version with no block locators. // Protocol version BIP0031Version with no block locators.
{ {
NoLocators, noLocators,
NoLocators, noLocators,
NoLocatorsEncoded, noLocatorsEncoded,
btcwire.BIP0031Version, btcwire.BIP0031Version,
}, },
// Protocol version BIP0031Versionwith multiple block locators. // Protocol version BIP0031Versionwith multiple block locators.
{ {
MultiLocators, multiLocators,
MultiLocators, multiLocators,
MultiLocatorsEncoded, multiLocatorsEncoded,
btcwire.BIP0031Version, btcwire.BIP0031Version,
}, },
// Protocol version NetAddressTimeVersion with no block locators. // Protocol version NetAddressTimeVersion with no block locators.
{ {
NoLocators, noLocators,
NoLocators, noLocators,
NoLocatorsEncoded, noLocatorsEncoded,
btcwire.NetAddressTimeVersion, btcwire.NetAddressTimeVersion,
}, },
// Protocol version NetAddressTimeVersion multiple block locators. // Protocol version NetAddressTimeVersion multiple block locators.
{ {
MultiLocators, multiLocators,
MultiLocators, multiLocators,
MultiLocatorsEncoded, multiLocatorsEncoded,
btcwire.NetAddressTimeVersion, btcwire.NetAddressTimeVersion,
}, },
// Protocol version MultipleAddressVersion with no block locators. // Protocol version MultipleAddressVersion with no block locators.
{ {
NoLocators, noLocators,
NoLocators, noLocators,
NoLocatorsEncoded, noLocatorsEncoded,
btcwire.MultipleAddressVersion, btcwire.MultipleAddressVersion,
}, },
// Protocol version MultipleAddressVersion multiple block locators. // Protocol version MultipleAddressVersion multiple block locators.
{ {
MultiLocators, multiLocators,
MultiLocators, multiLocators,
MultiLocatorsEncoded, multiLocatorsEncoded,
btcwire.MultipleAddressVersion, btcwire.MultipleAddressVersion,
}, },
} }