mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 22:28:27 -05:00
test(gossipsub): block5 protobuf test cases (#1204)
Co-authored-by: Radoslaw Kaminski <radoslaw@status.im>
This commit is contained in:
@@ -842,3 +842,34 @@ suite "GossipSub Message Handling":
|
||||
publishResult == 0
|
||||
results[0].isPending()
|
||||
results[1].isPending()
|
||||
|
||||
# check correctly parsed ihave/iwant/graft/prune/idontwant messages
|
||||
# check value before & after decoding equal using protoc cmd tool for reference
|
||||
asyncTest "ControlMessage RPCMsg encoding and decoding":
|
||||
let id: seq[byte] = @[123]
|
||||
let message = RPCMsg(
|
||||
control: some(
|
||||
ControlMessage(
|
||||
ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])],
|
||||
iwant: @[ControlIWant(messageIDs: @[id])],
|
||||
graft: @[ControlGraft(topicID: "foobar")],
|
||||
prune: @[ControlPrune(topicID: "foobar", backoff: 10.uint64)],
|
||||
idontwant: @[ControlIWant(messageIDs: @[id])],
|
||||
)
|
||||
)
|
||||
)
|
||||
#data encoded using protoc cmd tool
|
||||
let expectedEncoded: seq[byte] =
|
||||
@[
|
||||
26, 45, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 123, 18, 3, 10, 1,
|
||||
123, 26, 8, 10, 6, 102, 111, 111, 98, 97, 114, 34, 10, 10, 6, 102, 111, 111, 98,
|
||||
97, 114, 24, 10, 42, 3, 10, 1, 123,
|
||||
]
|
||||
|
||||
let actualEncoded = encodeRpcMsg(message, true)
|
||||
check:
|
||||
actualEncoded == expectedEncoded
|
||||
|
||||
let actualDecoded = decodeRpcMsg(expectedEncoded).value
|
||||
check:
|
||||
actualDecoded == message
|
||||
|
||||
Reference in New Issue
Block a user