mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
pss: add testing for forwarding cache clearing.
This commit is contained in:
parent
83355516c3
commit
04367fc5ea
1 changed files with 29 additions and 1 deletions
|
|
@ -144,9 +144,11 @@ func TestCache(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ps := newTestPss(privkey, nil, nil)
|
ps := newTestPss(privkey, nil, nil)
|
||||||
|
|
||||||
pp := NewPssParams(privkey)
|
pp := NewPssParams(privkey)
|
||||||
data := []byte("foo")
|
data := []byte("foo")
|
||||||
datatwo := []byte("bar")
|
datatwo := []byte("bar")
|
||||||
|
datathree := []byte("baz")
|
||||||
wparams := &whisper.MessageParams{
|
wparams := &whisper.MessageParams{
|
||||||
TTL: defaultWhisperTTL,
|
TTL: defaultWhisperTTL,
|
||||||
Src: privkey,
|
Src: privkey,
|
||||||
|
|
@ -169,6 +171,13 @@ func TestCache(t *testing.T) {
|
||||||
Payload: envtwo,
|
Payload: envtwo,
|
||||||
To: to,
|
To: to,
|
||||||
}
|
}
|
||||||
|
wparams.Payload = datathree
|
||||||
|
woutmsg, err = whisper.NewSentMessage(wparams)
|
||||||
|
envthree, err := woutmsg.Wrap(wparams)
|
||||||
|
msgthree := &PssMsg{
|
||||||
|
Payload: envthree,
|
||||||
|
To: to,
|
||||||
|
}
|
||||||
|
|
||||||
digest := ps.digest(msg)
|
digest := ps.digest(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -178,6 +187,11 @@ func TestCache(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not store cache msgtwo: %v", err)
|
t.Fatalf("could not store cache msgtwo: %v", err)
|
||||||
}
|
}
|
||||||
|
digestthree := ps.digest(msgthree)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not store cache msgthree: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if digest == digesttwo {
|
if digest == digesttwo {
|
||||||
t.Fatalf("different msgs return same hash: %d", digesttwo)
|
t.Fatalf("different msgs return same hash: %d", digesttwo)
|
||||||
|
|
@ -197,10 +211,23 @@ func TestCache(t *testing.T) {
|
||||||
t.Fatalf("message %v should NOT have EXPIRE record in cache but checkCache returned true", msgtwo)
|
t.Fatalf("message %v should NOT have EXPIRE record in cache but checkCache returned true", msgtwo)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(pp.CacheTTL)
|
time.Sleep(pp.CacheTTL + 1*time.Second)
|
||||||
|
err = ps.addFwdCache(msgthree)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("write to pss expire cache failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if ps.checkFwdCache(msg) {
|
if ps.checkFwdCache(msg) {
|
||||||
t.Fatalf("message %v should have expired from cache but checkCache returned true", msg)
|
t.Fatalf("message %v should have expired from cache but checkCache returned true", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := ps.fwdCache[digestthree]; !ok {
|
||||||
|
t.Fatalf("unexpired message should be in the cache: %v", digestthree)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := ps.fwdCache[digesttwo]; ok {
|
||||||
|
t.Fatalf("expired message should have been cleared from the cache: %v", digesttwo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// matching of address hints; whether a message could be or is for the node
|
// matching of address hints; whether a message could be or is for the node
|
||||||
|
|
@ -1309,6 +1336,7 @@ func newTestPss(privkey *ecdsa.PrivateKey, overlay network.Overlay, ppextra *Pss
|
||||||
pp.SymKeyCacheCapacity = ppextra.SymKeyCacheCapacity
|
pp.SymKeyCacheCapacity = ppextra.SymKeyCacheCapacity
|
||||||
}
|
}
|
||||||
ps := NewPss(overlay, pp)
|
ps := NewPss(overlay, pp)
|
||||||
|
ps.Start(nil)
|
||||||
|
|
||||||
return ps
|
return ps
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue