From 70aa92bf0d822d2ad5265924ed474af6328510df Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Thu, 24 Oct 2013 14:39:40 -0400 Subject: [PATCH] Test some boundary conditions that exercise 'flaws' in the current btcwire protocol. --- common_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/common_test.go b/common_test.go index 8a191c34..a3d09209 100644 --- a/common_test.go +++ b/common_test.go @@ -193,6 +193,29 @@ func TestVarStringWire(t *testing.T) { continue } } + + invtests := []struct { + buf []byte // Wire encoding + pver uint32 // Protocol version for wire encoding + }{ + {append([]byte{0x02}, []byte("")...), pver}, + //{append([]byte{0xfe, 0x00, 0x00, 0x00, 0x80}, []byte("")...), pver}, + {append([]byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, []byte("")...), pver}, + //{append([]byte{0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, []byte("")...), pver}, + } + t.Logf("Running %d invalid tests", len(invtests)) + for i, test := range invtests { + // Decode from wire format. + rbuf := bytes.NewBuffer(test.buf) + val, err := btcwire.TstReadVarString(rbuf, test.pver) + if err != nil { + t.Logf("readVarString #%d error %v (error expected)", i, err) + continue + } + t.Errorf("readVarString #%d\n got: %d want error != nil: %d", i, + val) + continue + } } // TestVarStringWireErrors performs negative tests against wire encode and