Add tests for MsgBlock transaction location decode.

This commit is contained in:
Dave Collins 2013-05-12 11:50:31 -05:00
parent c9d2dfea3d
commit 4e16030fe8
2 changed files with 37 additions and 7 deletions

View file

@ -124,16 +124,18 @@ func TestBlockSha(t *testing.T) {
// of transaction inputs and outputs and protocol versions.
func TestBlockWire(t *testing.T) {
tests := []struct {
in *btcwire.MsgBlock // Message to encode
out *btcwire.MsgBlock // Expected decoded message
buf []byte // Wire encoding
pver uint32 // Protocol version for wire encoding
in *btcwire.MsgBlock // Message to encode
out *btcwire.MsgBlock // Expected decoded message
buf []byte // Wire encoding
txLocs []btcwire.TxLoc // Expected transaction locations
pver uint32 // Protocol version for wire encoding
}{
// Latest protocol version.
{
&blockOne,
&blockOne,
blockOneBytes,
blockOneTxLocs,
btcwire.ProtocolVersion,
},
@ -142,6 +144,7 @@ func TestBlockWire(t *testing.T) {
&blockOne,
&blockOne,
blockOneBytes,
blockOneTxLocs,
btcwire.BIP0035Version,
},
@ -150,6 +153,7 @@ func TestBlockWire(t *testing.T) {
&blockOne,
&blockOne,
blockOneBytes,
blockOneTxLocs,
btcwire.BIP0031Version,
},
@ -158,6 +162,7 @@ func TestBlockWire(t *testing.T) {
&blockOne,
&blockOne,
blockOneBytes,
blockOneTxLocs,
btcwire.NetAddressTimeVersion,
},
@ -166,6 +171,7 @@ func TestBlockWire(t *testing.T) {
&blockOne,
&blockOne,
blockOneBytes,
blockOneTxLocs,
btcwire.MultipleAddressVersion,
},
}
@ -198,6 +204,24 @@ func TestBlockWire(t *testing.T) {
spew.Sdump(&msg), spew.Sdump(test.out))
continue
}
var txLocMsg btcwire.MsgBlock
rbuf = bytes.NewBuffer(test.buf)
txLocs, err := txLocMsg.BtcDecodeTxLoc(rbuf, test.pver)
if err != nil {
t.Errorf("BtcDecodeTxLoc #%d error %v", i, err)
continue
}
if !reflect.DeepEqual(&txLocMsg, test.out) {
t.Errorf("BtcDecodeTxLoc #%d\n got: %s want: %s", i,
spew.Sdump(&txLocMsg), spew.Sdump(test.out))
continue
}
if !reflect.DeepEqual(txLocs, test.txLocs) {
t.Errorf("BtcDecodeTxLoc #%d\n got: %s want: %s", i,
spew.Sdump(txLocs), spew.Sdump(test.txLocs))
continue
}
}
}
@ -318,7 +342,7 @@ var blockOne btcwire.MsgBlock = btcwire.MsgBlock{
},
}
// Bytes encoded with protocol version 60002.
// Block one bytes encoded with protocol version 60002.
var blockOneBytes = []byte{
0x01, 0x00, 0x00, 0x00, // Version 1
0x6f, 0xe2, 0x8c, 0x0a, 0xb6, 0xf1, 0xb3, 0x72,
@ -359,3 +383,9 @@ var blockOneBytes = []byte{
0xac, // OP_CHECKSIG
0x00, 0x00, 0x00, 0x00, // Lock time
}
// Transaction location information for block one trasnactions as encoded with
// protocol version 60002.
var blockOneTxLocs = []btcwire.TxLoc{
btcwire.TxLoc{TxStart: 81, TxLen: 134},
}

View file

@ -135,6 +135,7 @@ github.com/conformal/btcwire/msgversion.go MsgVersion.MaxPayloadLength 100.00
github.com/conformal/btcwire/msgversion.go NewMsgVersion 100.00% (1/1)
github.com/conformal/btcwire/netaddress.go NetAddress.AddService 100.00% (1/1)
github.com/conformal/btcwire/shahash.go ShaHash.IsEqual 100.00% (1/1)
github.com/conformal/btcwire/msgblock.go MsgBlock.BtcDecodeTxLoc 87.50% (14/16)
github.com/conformal/btcwire/msgblock.go MsgBlock.TxShas 85.71% (6/7)
github.com/conformal/btcwire/msgtx.go MsgTx.TxSha 85.71% (6/7)
github.com/conformal/btcwire/msgtx.go MsgTx.BtcDecode 80.00% (20/25)
@ -148,6 +149,5 @@ github.com/conformal/btcwire/msgtx.go writeTxIn 73.33% (11/15)
github.com/conformal/btcwire/msgtx.go writeTxOut 72.73% (8/11)
github.com/conformal/btcwire/msgversion.go MsgVersion.BtcDecode 68.00% (17/25)
github.com/conformal/btcwire/msgversion.go MsgVersion.BtcEncode 63.64% (14/22)
github.com/conformal/btcwire/msgblock.go MsgBlock.BtcDecodeTxLoc 0.00% (0/16)
github.com/conformal/btcwire --------------------------------- 93.33% (868/930)
github.com/conformal/btcwire --------------------------------- 94.84% (882/930)