aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5/whisper_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/whisperv5/whisper_test.go')
-rw-r--r--whisper/whisperv5/whisper_test.go204
1 files changed, 69 insertions, 135 deletions
diff --git a/whisper/whisperv5/whisper_test.go b/whisper/whisperv5/whisper_test.go
index 1db26265a..3f79a72c8 100644
--- a/whisper/whisperv5/whisper_test.go
+++ b/whisper/whisperv5/whisper_test.go
@@ -24,123 +24,101 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
-func TestWhisperBasic(x *testing.T) {
+func TestWhisperBasic(t *testing.T) {
w := NewWhisper(nil)
p := w.Protocols()
shh := p[0]
if shh.Name != ProtocolName {
- x.Errorf("failed Protocol Name: %v.", shh.Name)
- return
+ t.Fatalf("failed Protocol Name: %v.", shh.Name)
}
if uint64(shh.Version) != ProtocolVersion {
- x.Errorf("failed Protocol Version: %v.", shh.Version)
- return
+ t.Fatalf("failed Protocol Version: %v.", shh.Version)
}
if shh.Length != NumberOfMessageCodes {
- x.Errorf("failed Protocol Length: %v.", shh.Length)
- return
+ t.Fatalf("failed Protocol Length: %v.", shh.Length)
}
if shh.Run == nil {
- x.Errorf("failed shh.Run.")
- return
+ t.Fatalf("failed shh.Run.")
}
if uint64(w.Version()) != ProtocolVersion {
- x.Errorf("failed whisper Version: %v.", shh.Version)
- return
+ t.Fatalf("failed whisper Version: %v.", shh.Version)
}
if w.GetFilter(0) != nil {
- x.Errorf("failed GetFilter.")
- return
+ t.Fatalf("failed GetFilter.")
}
peerID := make([]byte, 64)
randomize(peerID)
peer, err := w.getPeer(peerID)
if peer != nil {
- x.Errorf("failed GetPeer.")
- return
+ t.Fatalf("failed GetPeer.")
}
err = w.MarkPeerTrusted(peerID)
if err == nil {
- x.Errorf("failed MarkPeerTrusted.")
- return
+ t.Fatalf("failed MarkPeerTrusted.")
}
err = w.RequestHistoricMessages(peerID, peerID)
if err == nil {
- x.Errorf("failed RequestHistoricMessages.")
- return
+ t.Fatalf("failed RequestHistoricMessages.")
}
err = w.SendP2PMessage(peerID, nil)
if err == nil {
- x.Errorf("failed SendP2PMessage.")
- return
+ t.Fatalf("failed SendP2PMessage.")
}
exist := w.HasSymKey("non-existing")
if exist {
- x.Errorf("failed HasSymKey.")
- return
+ t.Fatalf("failed HasSymKey.")
}
key := w.GetSymKey("non-existing")
if key != nil {
- x.Errorf("failed GetSymKey.")
- return
+ t.Fatalf("failed GetSymKey.")
}
mail := w.Envelopes()
if len(mail) != 0 {
- x.Errorf("failed w.Envelopes().")
- return
+ t.Fatalf("failed w.Envelopes().")
}
m := w.Messages(0)
if len(m) != 0 {
- x.Errorf("failed w.Messages.")
- return
+ t.Fatalf("failed w.Messages.")
}
var derived []byte
ver := uint64(0xDEADBEEF)
derived, err = deriveKeyMaterial(peerID, ver)
if err != unknownVersionError(ver) {
- x.Errorf("failed deriveKeyMaterial 1 with param = %v: %s.", peerID, err)
- return
+ t.Fatalf("failed deriveKeyMaterial with param = %v: %s.", peerID, err)
}
derived, err = deriveKeyMaterial(peerID, 0)
if err != nil {
- x.Errorf("failed deriveKeyMaterial 2 with param = %v: %s.", peerID, err)
- return
+ t.Fatalf("failed second deriveKeyMaterial with param = %v: %s.", peerID, err)
}
if !validateSymmetricKey(derived) {
- x.Errorf("failed validateSymmetricKey with param = %v.", derived)
- return
+ t.Fatalf("failed validateSymmetricKey with param = %v.", derived)
}
if containsOnlyZeros(derived) {
- x.Errorf("failed containsOnlyZeros with param = %v.", derived)
- return
+ t.Fatalf("failed containsOnlyZeros with param = %v.", derived)
}
buf := []byte{0xFF, 0xE5, 0x80, 0x2, 0}
le := bytesToIntLittleEndian(buf)
be := BytesToIntBigEndian(buf)
if le != uint64(0x280e5ff) {
- x.Errorf("failed bytesToIntLittleEndian: %d.", le)
- return
+ t.Fatalf("failed bytesToIntLittleEndian: %d.", le)
}
if be != uint64(0xffe5800200) {
- x.Errorf("failed BytesToIntBigEndian: %d.", be)
- return
+ t.Fatalf("failed BytesToIntBigEndian: %d.", be)
}
pk := w.NewIdentity()
if !validatePrivateKey(pk) {
- x.Errorf("failed validatePrivateKey: %v.", pk)
- return
+ t.Fatalf("failed validatePrivateKey: %v.", pk)
}
if !ValidatePublicKey(&pk.PublicKey) {
- x.Errorf("failed ValidatePublicKey: %v.", pk)
- return
+ t.Fatalf("failed ValidatePublicKey: %v.", pk)
}
}
-func TestWhisperIdentityManagement(x *testing.T) {
+func TestWhisperIdentityManagement(t *testing.T) {
w := NewWhisper(nil)
id1 := w.NewIdentity()
id2 := w.NewIdentity()
@@ -149,20 +127,16 @@ func TestWhisperIdentityManagement(x *testing.T) {
pk1 := w.GetIdentity(pub1)
pk2 := w.GetIdentity(pub2)
if !w.HasIdentity(pub1) {
- x.Errorf("failed HasIdentity 1.")
- return
+ t.Fatalf("failed HasIdentity(pub1).")
}
if !w.HasIdentity(pub2) {
- x.Errorf("failed HasIdentity 2.")
- return
+ t.Fatalf("failed HasIdentity(pub2).")
}
if pk1 != id1 {
- x.Errorf("failed GetIdentity 3.")
- return
+ t.Fatalf("failed GetIdentity(pub1).")
}
if pk2 != id2 {
- x.Errorf("failed GetIdentity 4.")
- return
+ t.Fatalf("failed GetIdentity(pub2).")
}
// Delete one identity
@@ -170,20 +144,16 @@ func TestWhisperIdentityManagement(x *testing.T) {
pk1 = w.GetIdentity(pub1)
pk2 = w.GetIdentity(pub2)
if w.HasIdentity(pub1) {
- x.Errorf("failed HasIdentity 11.")
- return
+ t.Fatalf("failed DeleteIdentity(pub1): still exist.")
}
if !w.HasIdentity(pub2) {
- x.Errorf("failed HasIdentity 12.")
- return
+ t.Fatalf("failed DeleteIdentity(pub1): pub2 does not exist.")
}
if pk1 != nil {
- x.Errorf("failed GetIdentity 13.")
- return
+ t.Fatalf("failed DeleteIdentity(pub1): first key still exist.")
}
if pk2 != id2 {
- x.Errorf("failed GetIdentity 14.")
- return
+ t.Fatalf("failed DeleteIdentity(pub1): second key does not exist.")
}
// Delete again non-existing identity
@@ -191,20 +161,16 @@ func TestWhisperIdentityManagement(x *testing.T) {
pk1 = w.GetIdentity(pub1)
pk2 = w.GetIdentity(pub2)
if w.HasIdentity(pub1) {
- x.Errorf("failed HasIdentity 21.")
- return
+ t.Fatalf("failed delete non-existing identity: exist.")
}
if !w.HasIdentity(pub2) {
- x.Errorf("failed HasIdentity 22.")
- return
+ t.Fatalf("failed delete non-existing identity: pub2 does not exist.")
}
if pk1 != nil {
- x.Errorf("failed GetIdentity 23.")
- return
+ t.Fatalf("failed delete non-existing identity: first key exist.")
}
if pk2 != id2 {
- x.Errorf("failed GetIdentity 24.")
- return
+ t.Fatalf("failed delete non-existing identity: second key does not exist.")
}
// Delete second identity
@@ -212,24 +178,20 @@ func TestWhisperIdentityManagement(x *testing.T) {
pk1 = w.GetIdentity(pub1)
pk2 = w.GetIdentity(pub2)
if w.HasIdentity(pub1) {
- x.Errorf("failed HasIdentity 31.")
- return
+ t.Fatalf("failed delete second identity: first identity exist.")
}
if w.HasIdentity(pub2) {
- x.Errorf("failed HasIdentity 32.")
- return
+ t.Fatalf("failed delete second identity: still exist.")
}
if pk1 != nil {
- x.Errorf("failed GetIdentity 33.")
- return
+ t.Fatalf("failed delete second identity: first key exist.")
}
if pk2 != nil {
- x.Errorf("failed GetIdentity 34.")
- return
+ t.Fatalf("failed delete second identity: second key exist.")
}
}
-func TestWhisperSymKeyManagement(x *testing.T) {
+func TestWhisperSymKeyManagement(t *testing.T) {
InitSingleTest()
var k1, k2 []byte
@@ -239,27 +201,22 @@ func TestWhisperSymKeyManagement(x *testing.T) {
err := w.GenerateSymKey(id1)
if err != nil {
- x.Errorf("failed test case 1 with seed %d: %s.", seed, err)
- return
+ t.Fatalf("failed GenerateSymKey with seed %d: %s.", seed, err)
}
k1 = w.GetSymKey(id1)
k2 = w.GetSymKey(id2)
if !w.HasSymKey(id1) {
- x.Errorf("failed HasIdentity 2.")
- return
+ t.Fatalf("failed HasSymKey(id1).")
}
if w.HasSymKey(id2) {
- x.Errorf("failed HasIdentity 3.")
- return
+ t.Fatalf("failed HasSymKey(id2).")
}
if k1 == nil {
- x.Errorf("failed GetIdentity 4.")
- return
+ t.Fatalf("first key does not exist.")
}
if k2 != nil {
- x.Errorf("failed GetIdentity 5.")
- return
+ t.Fatalf("second key still exist.")
}
// add existing id, nothing should change
@@ -267,91 +224,72 @@ func TestWhisperSymKeyManagement(x *testing.T) {
randomize(randomKey)
err = w.AddSymKey(id1, randomKey)
if err == nil {
- x.Errorf("failed test case 10 with seed %d.", seed)
- return
+ t.Fatalf("failed AddSymKey with seed %d.", seed)
}
k1 = w.GetSymKey(id1)
k2 = w.GetSymKey(id2)
if !w.HasSymKey(id1) {
- x.Errorf("failed HasIdentity 12.")
- return
+ t.Fatalf("failed w.HasSymKey(id1).")
}
if w.HasSymKey(id2) {
- x.Errorf("failed HasIdentity 13.")
- return
+ t.Fatalf("failed w.HasSymKey(id2).")
}
if k1 == nil {
- x.Errorf("failed GetIdentity 14.")
- return
+ t.Fatalf("first key does not exist.")
}
if bytes.Compare(k1, randomKey) == 0 {
- x.Errorf("failed GetIdentity 15: k1 == randomKey.")
- return
+ t.Fatalf("k1 == randomKey.")
}
if k2 != nil {
- x.Errorf("failed GetIdentity 16.")
- return
+ t.Fatalf("second key already exist.")
}
err = w.AddSymKey(id2, randomKey) // add non-existing (yet)
if err != nil {
- x.Errorf("failed test case 21 with seed %d: %s.", seed, err)
- return
+ t.Fatalf("failed AddSymKey(id2) with seed %d: %s.", seed, err)
}
k1 = w.GetSymKey(id1)
k2 = w.GetSymKey(id2)
if !w.HasSymKey(id1) {
- x.Errorf("failed HasIdentity 22.")
- return
+ t.Fatalf("HasSymKey(id1) failed.")
}
if !w.HasSymKey(id2) {
- x.Errorf("failed HasIdentity 23.")
- return
+ t.Fatalf("HasSymKey(id2) failed.")
}
if k1 == nil {
- x.Errorf("failed GetIdentity 24.")
- return
+ t.Fatalf("k1 does not exist.")
}
if k2 == nil {
- x.Errorf("failed GetIdentity 25.")
- return
+ t.Fatalf("k2 does not exist.")
}
if bytes.Compare(k1, k2) == 0 {
- x.Errorf("failed GetIdentity 26.")
- return
+ t.Fatalf("k1 == k2.")
}
if bytes.Compare(k1, randomKey) == 0 {
- x.Errorf("failed GetIdentity 27.")
- return
+ t.Fatalf("k1 == randomKey.")
}
if len(k1) != aesKeyLength {
- x.Errorf("failed GetIdentity 28.")
- return
+ t.Fatalf("wrong length of k1.")
}
if len(k2) != aesKeyLength {
- x.Errorf("failed GetIdentity 29.")
- return
+ t.Fatalf("wrong length of k2.")
}
w.DeleteSymKey(id1)
k1 = w.GetSymKey(id1)
k2 = w.GetSymKey(id2)
if w.HasSymKey(id1) {
- x.Errorf("failed HasIdentity 31.")
- return
+ t.Fatalf("failed to delete first key: still exist.")
}
if !w.HasSymKey(id2) {
- x.Errorf("failed HasIdentity 32.")
- return
+ t.Fatalf("failed to delete first key: second key does not exist.")
}
if k1 != nil {
- x.Errorf("failed GetIdentity 33.")
- return
+ t.Fatalf("failed to delete first key.")
}
if k2 == nil {
- x.Errorf("failed GetIdentity 34.")
- return
+ t.Fatalf("failed to delete first key: second key is nil.")
}
w.DeleteSymKey(id1)
@@ -359,19 +297,15 @@ func TestWhisperSymKeyManagement(x *testing.T) {
k1 = w.GetSymKey(id1)
k2 = w.GetSymKey(id2)
if w.HasSymKey(id1) {
- x.Errorf("failed HasIdentity 41.")
- return
+ t.Fatalf("failed to delete second key: first key exist.")
}
if w.HasSymKey(id2) {
- x.Errorf("failed HasIdentity 42.")
- return
+ t.Fatalf("failed to delete second key: still exist.")
}
if k1 != nil {
- x.Errorf("failed GetIdentity 43.")
- return
+ t.Fatalf("failed to delete second key: first key is not nil.")
}
if k2 != nil {
- x.Errorf("failed GetIdentity 44.")
- return
+ t.Fatalf("failed to delete second key: second key is not nil.")
}
}