mirror of https://github.com/status-im/nim-eth.git
Fix decoded dst bug + add tests
This commit is contained in:
parent
c3add58128
commit
ac766bf7b3
|
@ -607,6 +607,8 @@ proc notify*(filters: var Filters, msg: Message) {.gcsafe.} =
|
||||||
if decoded.isNone():
|
if decoded.isNone():
|
||||||
decoded = decode(msg.env.data, dst = filter.privateKey,
|
decoded = decode(msg.env.data, dst = filter.privateKey,
|
||||||
symKey = filter.symKey)
|
symKey = filter.symKey)
|
||||||
|
if decoded.isNone():
|
||||||
|
continue
|
||||||
if filter.privateKey.isSome():
|
if filter.privateKey.isSome():
|
||||||
keyHash = keccak256.digest(filter.privateKey.get().data)
|
keyHash = keccak256.digest(filter.privateKey.get().data)
|
||||||
# TODO: Get rid of the hash and just use pubkey to compare?
|
# TODO: Get rid of the hash and just use pubkey to compare?
|
||||||
|
@ -615,8 +617,6 @@ proc notify*(filters: var Filters, msg: Message) {.gcsafe.} =
|
||||||
keyHash = keccak256.digest(filter.symKey.get())
|
keyHash = keccak256.digest(filter.symKey.get())
|
||||||
# else:
|
# else:
|
||||||
# NOTE: should we error on messages without encryption?
|
# NOTE: should we error on messages without encryption?
|
||||||
if decoded.isNone():
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
if filter.privateKey.isSome():
|
if filter.privateKey.isSome():
|
||||||
if keyHash != keccak256.digest(filter.privateKey.get().data):
|
if keyHash != keccak256.digest(filter.privateKey.get().data):
|
||||||
|
|
|
@ -22,6 +22,7 @@ suite "Whisper payload":
|
||||||
check:
|
check:
|
||||||
decoded.isSome()
|
decoded.isSome()
|
||||||
payload.payload == decoded.get().payload
|
payload.payload == decoded.get().payload
|
||||||
|
decoded.get().src.isNone()
|
||||||
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
||||||
|
|
||||||
test "should roundtrip with symmetric encryption":
|
test "should roundtrip with symmetric encryption":
|
||||||
|
@ -33,6 +34,7 @@ suite "Whisper payload":
|
||||||
check:
|
check:
|
||||||
decoded.isSome()
|
decoded.isSome()
|
||||||
payload.payload == decoded.get().payload
|
payload.payload == decoded.get().payload
|
||||||
|
decoded.get().src.isNone()
|
||||||
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
||||||
|
|
||||||
test "should roundtrip with signature":
|
test "should roundtrip with signature":
|
||||||
|
@ -59,6 +61,7 @@ suite "Whisper payload":
|
||||||
check:
|
check:
|
||||||
decoded.isSome()
|
decoded.isSome()
|
||||||
payload.payload == decoded.get().payload
|
payload.payload == decoded.get().payload
|
||||||
|
decoded.get().src.isNone()
|
||||||
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
decoded.get().padding.get().len == 251 # 256 -1 -1 -3
|
||||||
|
|
||||||
test "should return specified bloom":
|
test "should return specified bloom":
|
||||||
|
@ -299,7 +302,10 @@ suite "Whisper filter":
|
||||||
notify(filters, msg)
|
notify(filters, msg)
|
||||||
|
|
||||||
let messages = filters.getFilterMessages(filterId)
|
let messages = filters.getFilterMessages(filterId)
|
||||||
check messages.len == 1
|
check:
|
||||||
|
messages.len == 1
|
||||||
|
messages[0].decoded.src.isNone()
|
||||||
|
messages[0].dst.isNone()
|
||||||
|
|
||||||
test "should notify filter on message with asymmetric encryption":
|
test "should notify filter on message with asymmetric encryption":
|
||||||
let privKey = keys.newPrivateKey()
|
let privKey = keys.newPrivateKey()
|
||||||
|
@ -314,7 +320,10 @@ suite "Whisper filter":
|
||||||
notify(filters, msg)
|
notify(filters, msg)
|
||||||
|
|
||||||
let messages = filters.getFilterMessages(filterId)
|
let messages = filters.getFilterMessages(filterId)
|
||||||
check messages.len == 1
|
check:
|
||||||
|
messages.len == 1
|
||||||
|
messages[0].decoded.src.isNone()
|
||||||
|
messages[0].dst.isSome()
|
||||||
|
|
||||||
test "should notify filter on message with signature":
|
test "should notify filter on message with signature":
|
||||||
let privKey = keys.newPrivateKey()
|
let privKey = keys.newPrivateKey()
|
||||||
|
@ -329,7 +338,10 @@ suite "Whisper filter":
|
||||||
notify(filters, msg)
|
notify(filters, msg)
|
||||||
|
|
||||||
let messages = filters.getFilterMessages(filterId)
|
let messages = filters.getFilterMessages(filterId)
|
||||||
check messages.len == 1
|
check:
|
||||||
|
messages.len == 1
|
||||||
|
messages[0].decoded.src.isSome()
|
||||||
|
messages[0].dst.isNone()
|
||||||
|
|
||||||
test "test notify of filter against PoW requirement":
|
test "test notify of filter against PoW requirement":
|
||||||
let topic = [byte 0, 0, 0, 0]
|
let topic = [byte 0, 0, 0, 0]
|
||||||
|
|
Loading…
Reference in New Issue