mirror of https://github.com/status-im/nim-eth.git
waku 0 replace whisper waku
This commit is contained in:
parent
73fcfdbad1
commit
40cddc4eec
|
@ -11,14 +11,14 @@ import
|
|||
sequtils, options, unittest, times, tables,
|
||||
nimcrypto/hash,
|
||||
eth/[keys, rlp],
|
||||
eth/p2p/rlpx_protocols/whisper_protocol as whisper
|
||||
eth/p2p/rlpx_protocols/waku_protocol as waku
|
||||
|
||||
suite "Whisper payload":
|
||||
suite "Waku payload":
|
||||
test "should roundtrip without keys":
|
||||
let payload = Payload(payload: @[byte 0, 1, 2])
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -28,9 +28,9 @@ suite "Whisper payload":
|
|||
test "should roundtrip with symmetric encryption":
|
||||
var symKey: SymKey
|
||||
let payload = Payload(symKey: some(symKey), payload: @[byte 0, 1, 2])
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get(), symKey = some(symKey))
|
||||
let decoded = waku.decode(encoded.get(), symKey = some(symKey))
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -41,9 +41,9 @@ suite "Whisper payload":
|
|||
let privKey = keys.newPrivateKey()
|
||||
|
||||
let payload = Payload(src: some(privKey), payload: @[byte 0, 1, 2])
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -55,9 +55,9 @@ suite "Whisper payload":
|
|||
|
||||
let payload = Payload(dst: some(privKey.getPublicKey()),
|
||||
payload: @[byte 0, 1, 2])
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get(), dst = some(privKey))
|
||||
let decoded = waku.decode(encoded.get(), dst = some(privKey))
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -65,7 +65,7 @@ suite "Whisper payload":
|
|||
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
||||
|
||||
test "should return specified bloom":
|
||||
# Geth test: https://github.com/ethersphere/go-ethereum/blob/d3441ebb563439bac0837d70591f92e2c6080303/whisper/whisperv6/whisper_test.go#L834
|
||||
# Geth test: https://github.com/ethersphere/go-ethereum/blob/d3441ebb563439bac0837d70591f92e2c6080303/waku/wakuv6/waku_test.go#L834
|
||||
let top0 = [byte 0, 0, 255, 6]
|
||||
var x: Bloom
|
||||
x[0] = byte 1
|
||||
|
@ -73,12 +73,12 @@ suite "Whisper payload":
|
|||
x[^1] = byte 128
|
||||
check @(top0.topicBloom) == @x
|
||||
|
||||
suite "Whisper payload padding":
|
||||
suite "Waku payload padding":
|
||||
test "should do max padding":
|
||||
let payload = Payload(payload: repeat(byte 1, 254))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -89,9 +89,9 @@ suite "Whisper payload padding":
|
|||
let privKey = keys.newPrivateKey()
|
||||
|
||||
let payload = Payload(src: some(privKey), payload: repeat(byte 1, 189))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -101,9 +101,9 @@ suite "Whisper payload padding":
|
|||
|
||||
test "should do min padding":
|
||||
let payload = Payload(payload: repeat(byte 1, 253))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -114,9 +114,9 @@ suite "Whisper payload padding":
|
|||
let privKey = keys.newPrivateKey()
|
||||
|
||||
let payload = Payload(src: some(privKey), payload: repeat(byte 1, 188))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -127,9 +127,9 @@ suite "Whisper payload padding":
|
|||
test "should roundtrip custom padding":
|
||||
let payload = Payload(payload: repeat(byte 1, 10),
|
||||
padding: some(repeat(byte 2, 100)))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -140,9 +140,9 @@ suite "Whisper payload padding":
|
|||
let padding: seq[byte] = @[]
|
||||
let payload = Payload(payload: repeat(byte 1, 10),
|
||||
padding: some(padding))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -152,9 +152,9 @@ suite "Whisper payload padding":
|
|||
let privKey = keys.newPrivateKey()
|
||||
let payload = Payload(src: some(privKey), payload: repeat(byte 1, 10),
|
||||
padding: some(repeat(byte 2, 100)))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
|
@ -167,16 +167,16 @@ suite "Whisper payload padding":
|
|||
let privKey = keys.newPrivateKey()
|
||||
let payload = Payload(src: some(privKey), payload: repeat(byte 1, 10),
|
||||
padding: some(padding))
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
|
||||
let decoded = whisper.decode(encoded.get())
|
||||
let decoded = waku.decode(encoded.get())
|
||||
check:
|
||||
decoded.isSome()
|
||||
payload.payload == decoded.get().payload
|
||||
privKey.getPublicKey() == decoded.get().src.get()
|
||||
decoded.get().padding.isNone()
|
||||
|
||||
# example from https://github.com/paritytech/parity-ethereum/blob/93e1040d07e385d1219d00af71c46c720b0a1acf/whisper/src/message.rs#L439
|
||||
# example from https://github.com/paritytech/parity-ethereum/blob/93e1040d07e385d1219d00af71c46c720b0a1acf/waku/src/message.rs#L439
|
||||
let
|
||||
env0 = Envelope(
|
||||
expiry:100000, ttl: 30, topic: [byte 0, 0, 0, 0],
|
||||
|
@ -185,12 +185,12 @@ let
|
|||
expiry:100000, ttl: 30, topic: [byte 0, 0, 0, 0],
|
||||
data: repeat(byte 9, 256), nonce: 1010102)
|
||||
|
||||
suite "Whisper envelope":
|
||||
suite "Waku envelope":
|
||||
|
||||
proc hashAndPow(env: Envelope): (string, float64) =
|
||||
# This is the current implementation of go-ethereum
|
||||
let size = env.toShortRlp().len().uint32
|
||||
# This is our current implementation in `whisper_protocol.nim`
|
||||
# This is our current implementation in `waku_protocol.nim`
|
||||
# let size = env.len().uint32
|
||||
# This is the EIP-627 specification
|
||||
# let size = env.toRlp().len().uint32
|
||||
|
@ -214,7 +214,7 @@ suite "Whisper envelope":
|
|||
57896044618658100000000000000000000000000000000000000000000000000000000000000.0
|
||||
calcPow(1, 1, Hash.fromHex(testHashes[2])) == 1.0
|
||||
|
||||
# Test values from go-ethereum whisperv6 in envelope_test
|
||||
# Test values from go-ethereum wakuv6 in envelope_test
|
||||
var env = Envelope(ttl: 1, data: @[byte 0xde, 0xad, 0xbe, 0xef])
|
||||
# PoW calculation with no leading zeroes
|
||||
env.nonce = 100000
|
||||
|
@ -228,7 +228,7 @@ suite "Whisper envelope":
|
|||
test "should validate and allow envelope according to config":
|
||||
let ttl = 1'u32
|
||||
let topic = [byte 1, 2, 3, 4]
|
||||
let config = WhisperConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
let config = WakuConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
||||
|
||||
let env = Envelope(expiry:epochTime().uint32 + ttl, ttl: ttl, topic: topic,
|
||||
|
@ -241,7 +241,7 @@ suite "Whisper envelope":
|
|||
test "should invalidate envelope due to ttl 0":
|
||||
let ttl = 0'u32
|
||||
let topic = [byte 1, 2, 3, 4]
|
||||
let config = WhisperConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
let config = WakuConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
||||
|
||||
let env = Envelope(expiry:epochTime().uint32 + ttl, ttl: ttl, topic: topic,
|
||||
|
@ -251,7 +251,7 @@ suite "Whisper envelope":
|
|||
test "should invalidate envelope due to expired":
|
||||
let ttl = 1'u32
|
||||
let topic = [byte 1, 2, 3, 4]
|
||||
let config = WhisperConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
let config = WakuConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
||||
|
||||
let env = Envelope(expiry:epochTime().uint32, ttl: ttl, topic: topic,
|
||||
|
@ -261,7 +261,7 @@ suite "Whisper envelope":
|
|||
test "should invalidate envelope due to in the future":
|
||||
let ttl = 1'u32
|
||||
let topic = [byte 1, 2, 3, 4]
|
||||
let config = WhisperConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
let config = WakuConfig(powRequirement: 0, bloom: topic.topicBloom(),
|
||||
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
||||
|
||||
# there is currently a 2 second tolerance, hence the + 3
|
||||
|
@ -272,7 +272,7 @@ suite "Whisper envelope":
|
|||
test "should not allow envelope due to bloom filter":
|
||||
let topic = [byte 1, 2, 3, 4]
|
||||
let wrongTopic = [byte 9, 8, 7, 6]
|
||||
let config = WhisperConfig(powRequirement: 0, bloom: wrongTopic.topicBloom(),
|
||||
let config = WakuConfig(powRequirement: 0, bloom: wrongTopic.topicBloom(),
|
||||
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
||||
|
||||
let env = Envelope(expiry:100000 , ttl: 30, topic: topic,
|
||||
|
@ -282,7 +282,7 @@ suite "Whisper envelope":
|
|||
check msg.allowed(config) == false
|
||||
|
||||
|
||||
suite "Whisper queue":
|
||||
suite "Waku queue":
|
||||
test "should throw out lower proof-of-work item when full":
|
||||
var queue = initQueue(1)
|
||||
|
||||
|
@ -316,12 +316,12 @@ proc prepFilterTestMsg(pubKey = none[PublicKey](), symKey = none[SymKey](),
|
|||
padding = none[seq[byte]]()): Message =
|
||||
let payload = Payload(dst: pubKey, symKey: symKey, src: src,
|
||||
payload: @[byte 0, 1, 2], padding: padding)
|
||||
let encoded = whisper.encode(payload)
|
||||
let encoded = waku.encode(payload)
|
||||
let env = Envelope(expiry: 1, ttl: 1, topic: topic, data: encoded.get(),
|
||||
nonce: 0)
|
||||
result = initMessage(env)
|
||||
|
||||
suite "Whisper filter":
|
||||
suite "Waku filter":
|
||||
test "should notify filter on message with symmetric encryption":
|
||||
var symKey: SymKey
|
||||
let topic = [byte 0, 0, 0, 0]
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import
|
||||
sequtils, options, unittest, tables, chronos, eth/[keys, p2p],
|
||||
eth/p2p/rlpx_protocols/whisper_protocol, eth/p2p/peer_pool,
|
||||
eth/p2p/rlpx_protocols/waku_protocol, eth/p2p/peer_pool,
|
||||
./p2p_test_helper
|
||||
|
||||
proc resetMessageQueues(nodes: varargs[EthereumNode]) =
|
||||
|
@ -19,9 +19,9 @@ proc resetMessageQueues(nodes: varargs[EthereumNode]) =
|
|||
let safeTTL = 5'u32
|
||||
let waitInterval = messageInterval + 150.milliseconds
|
||||
|
||||
suite "Whisper connections":
|
||||
var node1 = setupTestNode(Whisper)
|
||||
var node2 = setupTestNode(Whisper)
|
||||
suite "Waku connections":
|
||||
var node1 = setupTestNode(Waku)
|
||||
var node2 = setupTestNode(Waku)
|
||||
node2.startListening()
|
||||
waitFor node1.peerPool.connectToNode(newNode(initENode(node2.keys.pubKey,
|
||||
node2.address)))
|
||||
|
@ -90,11 +90,11 @@ suite "Whisper connections":
|
|||
ttl = safeTTL, topic = topic,
|
||||
payload = payloads[3]) == true
|
||||
|
||||
node2.protocolState(Whisper).queue.items.len == 4
|
||||
node2.protocolState(Waku).queue.items.len == 4
|
||||
|
||||
check:
|
||||
await allFutures(futures).withTimeout(waitInterval)
|
||||
node1.protocolState(Whisper).queue.items.len == 4
|
||||
node1.protocolState(Waku).queue.items.len == 4
|
||||
|
||||
for filter in filters:
|
||||
check node1.unsubscribeFilter(filter) == true
|
||||
|
@ -121,10 +121,10 @@ suite "Whisper connections":
|
|||
payload = payloads[0]) == true
|
||||
node2.postMessage(ttl = safeTTL, topic = topic2,
|
||||
payload = payloads[1]) == true
|
||||
node2.protocolState(Whisper).queue.items.len == 2
|
||||
node2.protocolState(Waku).queue.items.len == 2
|
||||
|
||||
await allFutures(futures).withTimeout(waitInterval)
|
||||
node1.protocolState(Whisper).queue.items.len == 2
|
||||
node1.protocolState(Waku).queue.items.len == 2
|
||||
|
||||
node1.unsubscribeFilter(filter1) == true
|
||||
node1.unsubscribeFilter(filter2) == true
|
||||
|
@ -152,7 +152,7 @@ suite "Whisper connections":
|
|||
|
||||
(await futures[0].withTimeout(waitInterval)) == true
|
||||
(await futures[1].withTimeout(waitInterval)) == false
|
||||
node1.protocolState(Whisper).queue.items.len == 1
|
||||
node1.protocolState(Waku).queue.items.len == 1
|
||||
|
||||
node1.unsubscribeFilter(filter1) == true
|
||||
node1.unsubscribeFilter(filter2) == true
|
||||
|
@ -204,10 +204,10 @@ suite "Whisper connections":
|
|||
check:
|
||||
node2.postMessage(ttl = safeTTL, topic = sendTopic1,
|
||||
payload = payload) == true
|
||||
node2.protocolState(Whisper).queue.items.len == 1
|
||||
node2.protocolState(Waku).queue.items.len == 1
|
||||
|
||||
(await f.withTimeout(waitInterval)) == false
|
||||
node1.protocolState(Whisper).queue.items.len == 0
|
||||
node1.protocolState(Waku).queue.items.len == 0
|
||||
|
||||
resetMessageQueues(node1, node2)
|
||||
|
||||
|
@ -216,11 +216,11 @@ suite "Whisper connections":
|
|||
check:
|
||||
node2.postMessage(ttl = safeTTL, topic = sendTopic2,
|
||||
payload = payload) == true
|
||||
node2.protocolState(Whisper).queue.items.len == 1
|
||||
node2.protocolState(Waku).queue.items.len == 1
|
||||
|
||||
await f.withTimeout(waitInterval)
|
||||
f.read() == 1
|
||||
node1.protocolState(Whisper).queue.items.len == 1
|
||||
node1.protocolState(Waku).queue.items.len == 1
|
||||
|
||||
node1.unsubscribeFilter(filter) == true
|
||||
|
||||
|
@ -235,20 +235,20 @@ suite "Whisper connections":
|
|||
await node1.setPowRequirement(1_000_000)
|
||||
check:
|
||||
node2.postMessage(ttl = safeTTL, topic = topic, payload = payload) == true
|
||||
node2.protocolState(Whisper).queue.items.len == 1
|
||||
node2.protocolState(Waku).queue.items.len == 1
|
||||
await sleepAsync(waitInterval)
|
||||
check:
|
||||
node1.protocolState(Whisper).queue.items.len == 0
|
||||
node1.protocolState(Waku).queue.items.len == 0
|
||||
|
||||
resetMessageQueues(node1, node2)
|
||||
|
||||
await node1.setPowRequirement(0.0)
|
||||
check:
|
||||
node2.postMessage(ttl = safeTTL, topic = topic, payload = payload) == true
|
||||
node2.protocolState(Whisper).queue.items.len == 1
|
||||
node2.protocolState(Waku).queue.items.len == 1
|
||||
await sleepAsync(waitInterval)
|
||||
check:
|
||||
node1.protocolState(Whisper).queue.items.len == 1
|
||||
node1.protocolState(Waku).queue.items.len == 1
|
||||
|
||||
resetMessageQueues(node1, node2)
|
||||
|
||||
|
@ -261,14 +261,14 @@ suite "Whisper connections":
|
|||
let lowerTTL = 2'u32 # Lower TTL as we need to wait for messages to expire
|
||||
for i in countdown(10, 1):
|
||||
check node2.postMessage(ttl = lowerTTL, topic = topic, payload = payload) == true
|
||||
check node2.protocolState(Whisper).queue.items.len == 10
|
||||
check node2.protocolState(Waku).queue.items.len == 10
|
||||
|
||||
await sleepAsync(waitInterval)
|
||||
check node1.protocolState(Whisper).queue.items.len == 10
|
||||
check node1.protocolState(Waku).queue.items.len == 10
|
||||
|
||||
await sleepAsync(milliseconds((lowerTTL+1)*1000))
|
||||
check node1.protocolState(Whisper).queue.items.len == 0
|
||||
check node2.protocolState(Whisper).queue.items.len == 0
|
||||
check node1.protocolState(Waku).queue.items.len == 0
|
||||
check node2.protocolState(Waku).queue.items.len == 0
|
||||
|
||||
resetMessageQueues(node1, node2)
|
||||
|
||||
|
@ -289,13 +289,13 @@ suite "Whisper connections":
|
|||
|
||||
await f.withTimeout(waitInterval)
|
||||
f.read() == 1
|
||||
node1.protocolState(Whisper).queue.items.len == 0
|
||||
node2.protocolState(Whisper).queue.items.len == 0
|
||||
node1.protocolState(Waku).queue.items.len == 0
|
||||
node2.protocolState(Waku).queue.items.len == 0
|
||||
|
||||
node1.unsubscribeFilter(filter) == true
|
||||
|
||||
asyncTest "Light node posting":
|
||||
var ln1 = setupTestNode(Whisper)
|
||||
var ln1 = setupTestNode(Waku)
|
||||
ln1.setLightNode(true)
|
||||
|
||||
await ln1.peerPool.connectToNode(newNode(initENode(node2.keys.pubKey,
|
||||
|
@ -307,16 +307,16 @@ suite "Whisper connections":
|
|||
# normal post
|
||||
ln1.postMessage(ttl = safeTTL, topic = topic,
|
||||
payload = repeat(byte 0, 10)) == false
|
||||
ln1.protocolState(Whisper).queue.items.len == 0
|
||||
ln1.protocolState(Waku).queue.items.len == 0
|
||||
# P2P post
|
||||
ln1.postMessage(ttl = safeTTL, topic = topic,
|
||||
payload = repeat(byte 0, 10),
|
||||
targetPeer = some(toNodeId(node2.keys.pubkey))) == true
|
||||
ln1.protocolState(Whisper).queue.items.len == 0
|
||||
ln1.protocolState(Waku).queue.items.len == 0
|
||||
|
||||
asyncTest "Connect two light nodes":
|
||||
var ln1 = setupTestNode(Whisper)
|
||||
var ln2 = setupTestNode(Whisper)
|
||||
var ln1 = setupTestNode(Waku)
|
||||
var ln2 = setupTestNode(Waku)
|
||||
|
||||
ln1.setLightNode(true)
|
||||
ln2.setLightNode(true)
|
||||
|
|
Loading…
Reference in New Issue