diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-15 15:50:31 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-15 15:50:31 +0800 |
commit | bcf41797cacac35879d6bc153d3e4ce3cd9896f0 (patch) | |
tree | f3b377dac41c47e1f854fe3a8ffa4f16a577137e /whisper/peer_test.go | |
parent | 4fb7ab5d090a49837ca50318fab468b056f2ec9f (diff) | |
download | dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.gz dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.bz2 dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.lz dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.xz dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.tar.zst dexon-bcf41797cacac35879d6bc153d3e4ce3cd9896f0.zip |
whisper: global message expiration tests, polishes
Diffstat (limited to 'whisper/peer_test.go')
-rw-r--r-- | whisper/peer_test.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/whisper/peer_test.go b/whisper/peer_test.go index c9092dd23..5f24504da 100644 --- a/whisper/peer_test.go +++ b/whisper/peer_test.go @@ -38,6 +38,20 @@ func startTestPeer() *testPeer { } } +func startTestPeerInited() (*testPeer, error) { + peer := startTestPeer() + + if err := p2p.ExpectMsg(peer.stream, statusCode, []uint64{protocolVersion}); err != nil { + peer.stream.Close() + return nil, err + } + if err := p2p.SendItems(peer.stream, statusCode, protocolVersion); err != nil { + peer.stream.Close() + return nil, err + } + return peer, nil +} + func TestPeerStatusMessage(t *testing.T) { tester := startTestPeer() @@ -102,15 +116,12 @@ func TestPeerHandshakeSuccess(t *testing.T) { func TestPeerSend(t *testing.T) { // Start a tester and execute the handshake - tester := startTestPeer() + tester, err := startTestPeerInited() + if err != nil { + t.Fatalf("failed to start initialized peer: %v", err) + } defer tester.stream.Close() - if err := p2p.ExpectMsg(tester.stream, statusCode, []uint64{protocolVersion}); err != nil { - t.Fatalf("status message mismatch: %v", err) - } - if err := p2p.SendItems(tester.stream, statusCode, protocolVersion); err != nil { - t.Fatalf("failed to send status: %v", err) - } // Construct a message and inject into the tester message := NewMessage([]byte("peer broadcast test message")) envelope, err := message.Wrap(DefaultPoW, Options{ @@ -138,15 +149,12 @@ func TestPeerSend(t *testing.T) { func TestPeerDeliver(t *testing.T) { // Start a tester and execute the handshake - tester := startTestPeer() + tester, err := startTestPeerInited() + if err != nil { + t.Fatalf("failed to start initialized peer: %v", err) + } defer tester.stream.Close() - if err := p2p.ExpectMsg(tester.stream, statusCode, []uint64{protocolVersion}); err != nil { - t.Fatalf("status message mismatch: %v", err) - } - if err := p2p.SendItems(tester.stream, statusCode, protocolVersion); err != nil { - t.Fatalf("failed to send status: %v", err) - } // Watch for all inbound messages arrived := make(chan struct{}, 1) tester.client.Watch(Filter{ |