From 882bcf85124470f95e9f79f57ba599b855249368 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 10 May 2018 08:58:00 +0200 Subject: [PATCH 1/3] Handle BECH addresses in test of logged socket.io --- server/socketio_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/socketio_test.go b/server/socketio_test.go index a6fc5330..dbb0e859 100644 --- a/server/socketio_test.go +++ b/server/socketio_test.go @@ -246,13 +246,18 @@ func verifyGetDetailedTransaction(t *testing.T, id int, lrs *logRequestResponse, bbi.Satoshis != li.Satoshis { return errors.Errorf("mismatch input %v %v, %v %v, %v %v", bbi.OutputIndex, li.OutputIndex, bbi.Sequence, li.Sequence, bbi.Satoshis, li.Satoshis) } + // both must be null or both must not be null if bbi.Address != nil && li.Address != nil { if *bbi.Address != *li.Address { return errors.Errorf("mismatch input Address %v %v", *bbi.Address, *li.Address) } } else if bbi.Address != li.Address { + // bitcore does not parse bech P2WPKH and P2WSH addresses + if bbi.Address == nil || (*bbi.Address)[0:3] != "bc1" { return errors.Errorf("mismatch input Address %v %v", bbi.Address, li.Address) } + } + // both must be null or both must not be null if bbi.Script != nil && li.Script != nil { if *bbi.Script != *li.Script { return errors.Errorf("mismatch input Script %v %v", *bbi.Script, *li.Script) @@ -272,21 +277,26 @@ func verifyGetDetailedTransaction(t *testing.T, id int, lrs *logRequestResponse, if bbo.Satoshis != lo.Satoshis { return errors.Errorf("mismatch output Satoshis %v %v", bbo.Satoshis, lo.Satoshis) } + // both must be null or both must not be null if bbo.Script != nil && lo.Script != nil { if *bbo.Script != *lo.Script { return errors.Errorf("mismatch output Script %v %v", *bbo.Script, *lo.Script) } - } else { + } else if bbo.Script != lo.Script { return errors.Errorf("mismatch output Script %v %v", bbo.Script, lo.Script) } + // both must be null or both must not be null if bbo.Address != nil && lo.Address != nil { if *bbo.Address != *lo.Address { return errors.Errorf("mismatch output Address %v %v", *bbo.Address, *lo.Address) } - } else { + } else if bbo.Address != lo.Address { + // bitcore does not parse bech P2WPKH and P2WSH addresses + if bbo.Address == nil || (*bbo.Address)[0:3] != "bc1" { return errors.Errorf("mismatch output Address %v %v", bbo.Address, lo.Address) } } + } return nil } // the tx in the log could have been still in mempool with Height -1 From 1cb233858764a8d3465b0605d7936b789f02fa11 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 10 May 2018 10:02:25 +0200 Subject: [PATCH 2/3] Add option to create new connection for each request to socket.io test --- server/socketio_test.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/server/socketio_test.go b/server/socketio_test.go index dbb0e859..26ade7f7 100644 --- a/server/socketio_test.go +++ b/server/socketio_test.go @@ -19,8 +19,7 @@ import ( var ( // verifier functionality - verifylog = flag.String("verifylog", "", "path to logfile containing socket.io requests/responses") - wsurl = flag.String("wsurl", "", "URL of socket.io interface to verify") + newSocket = flag.Bool("newsocket", false, "Create new socket.io connection for each request") ) type verifyStats struct { @@ -374,11 +373,7 @@ func verifyMessage(t *testing.T, ws *gosocketio.Client, id int, lrs *logRequestR } } -func Test_VerifyLog(t *testing.T) { - if *verifylog == "" || *wsurl == "" { - t.Skip("skipping test, flags verifylog or wsurl not specified") - } - t.Log("Verifying log", *verifylog, "against service", *wsurl) +func connectSocketIO(t *testing.T) *gosocketio.Client { tr := transport.GetDefaultWebsocketTransport() tr.WebsocketDialer = websocket.Dialer{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -386,9 +381,21 @@ func Test_VerifyLog(t *testing.T) { ws, err := gosocketio.Dial(*wsurl, tr) if err != nil { t.Fatal("Dial error ", err) - return + return nil } + return ws +} + +func Test_VerifyLog(t *testing.T) { + if *verifylog == "" || *wsurl == "" { + t.Skip("skipping test, flags verifylog or wsurl not specified") + } + t.Log("Verifying log", *verifylog, "against service", *wsurl) + var ws *gosocketio.Client + if !*newSocket { + ws = connectSocketIO(t) defer ws.Close() + } file, err := os.Open(*verifylog) if err != nil { t.Fatal("File read error", err) @@ -430,7 +437,13 @@ func Test_VerifyLog(t *testing.T) { lrs.LogElapsedTime = msg.Et } if lrs.Request != nil && lrs.Response != nil { + if *newSocket { + ws = connectSocketIO(t) + } verifyMessage(t, ws, msg.ID, lrs, stats) + if *newSocket { + ws.Close() + } delete(pairs, msg.ID) } } From 8d422dabaa69fc2699c4ee14dcaf95552bc4238d Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 10 May 2018 10:05:55 +0200 Subject: [PATCH 3/3] Fix commit screw up --- server/socketio_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/socketio_test.go b/server/socketio_test.go index 26ade7f7..21b38465 100644 --- a/server/socketio_test.go +++ b/server/socketio_test.go @@ -19,6 +19,8 @@ import ( var ( // verifier functionality + verifylog = flag.String("verifylog", "", "path to logfile containing socket.io requests/responses") + wsurl = flag.String("wsurl", "", "URL of socket.io interface to verify") newSocket = flag.Bool("newsocket", false, "Create new socket.io connection for each request") ) @@ -253,8 +255,8 @@ func verifyGetDetailedTransaction(t *testing.T, id int, lrs *logRequestResponse, } else if bbi.Address != li.Address { // bitcore does not parse bech P2WPKH and P2WSH addresses if bbi.Address == nil || (*bbi.Address)[0:3] != "bc1" { - return errors.Errorf("mismatch input Address %v %v", bbi.Address, li.Address) - } + return errors.Errorf("mismatch input Address %v %v", bbi.Address, li.Address) + } } // both must be null or both must not be null if bbi.Script != nil && li.Script != nil { @@ -292,10 +294,10 @@ func verifyGetDetailedTransaction(t *testing.T, id int, lrs *logRequestResponse, } else if bbo.Address != lo.Address { // bitcore does not parse bech P2WPKH and P2WSH addresses if bbo.Address == nil || (*bbo.Address)[0:3] != "bc1" { - return errors.Errorf("mismatch output Address %v %v", bbo.Address, lo.Address) + return errors.Errorf("mismatch output Address %v %v", bbo.Address, lo.Address) + } } } - } return nil } // the tx in the log could have been still in mempool with Height -1 @@ -394,7 +396,7 @@ func Test_VerifyLog(t *testing.T) { var ws *gosocketio.Client if !*newSocket { ws = connectSocketIO(t) - defer ws.Close() + defer ws.Close() } file, err := os.Open(*verifylog) if err != nil {