mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
whisper: padding test updated
This commit is contained in:
parent
75909a1694
commit
a96ba2af42
2 changed files with 17 additions and 9 deletions
|
|
@ -56,7 +56,7 @@ const (
|
||||||
keyIdSize = 32
|
keyIdSize = 32
|
||||||
|
|
||||||
DefaultMaxMessageLength = 1024 * 1024
|
DefaultMaxMessageLength = 1024 * 1024
|
||||||
DefaultMinimumPoW = 1.0 // todo: review after testing.
|
DefaultMinimumPoW = 1.0
|
||||||
|
|
||||||
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24)
|
padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol (must not exceed 2^24)
|
||||||
messageQueueLimit = 1024
|
messageQueueLimit = 1024
|
||||||
|
|
|
||||||
|
|
@ -367,16 +367,17 @@ func singlePaddingTest(t *testing.T, padSize int) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed generateMessageParams with seed %d and sz=%d: %s.", seed, padSize, err)
|
t.Fatalf("failed generateMessageParams with seed %d and sz=%d: %s.", seed, padSize, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
params.Padding = make([]byte, padSize)
|
params.Padding = make([]byte, padSize)
|
||||||
params.PoW = 0.0000000001
|
params.PoW = 0.0000000001
|
||||||
pad := make([]byte, padSize)
|
pad := make([]byte, padSize)
|
||||||
mrand.Read(pad)
|
_, err = mrand.Read(pad)
|
||||||
copy(params.Padding, pad)
|
if err != nil {
|
||||||
if !bytes.Equal(pad, params.Padding) {
|
t.Fatalf("padding is not generated (seed %d): %s", seed, err)
|
||||||
t.Fatalf("padding is not copied as expected with seed %d and sz=%d:\n[%x]\n[%x].", seed, padSize, pad, params.Padding)
|
}
|
||||||
|
n := copy(params.Padding, pad)
|
||||||
|
if n != padSize {
|
||||||
|
t.Fatalf("padding is not copied (seed %d): %s", seed, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := NewSentMessage(params)
|
msg, err := NewSentMessage(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
||||||
|
|
@ -385,7 +386,6 @@ func singlePaddingTest(t *testing.T, padSize int) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to wrap, seed: %d and sz=%d.", seed, padSize)
|
t.Fatalf("failed to wrap, seed: %d and sz=%d.", seed, padSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
f := Filter{KeySym: params.KeySym}
|
f := Filter{KeySym: params.KeySym}
|
||||||
decrypted := env.Open(&f)
|
decrypted := env.Open(&f)
|
||||||
if decrypted == nil {
|
if decrypted == nil {
|
||||||
|
|
@ -408,5 +408,13 @@ func TestPadding(t *testing.T) {
|
||||||
singlePaddingTest(t, i)
|
singlePaddingTest(t, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: add several in interval 256 < i < 256*256, and another several with i > 256*256
|
for i := 0; i < 256; i++ {
|
||||||
|
n := mrand.Intn(256*254) + 256
|
||||||
|
singlePaddingTest(t, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 256; i++ {
|
||||||
|
n := mrand.Intn(256*1024) + 256*256
|
||||||
|
singlePaddingTest(t, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue