-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(gossipsub): block5 protobuf test cases #1204
base: master
Are you sure you want to change the base?
Changes from 4 commits
7477059
4f96d1b
f545a87
96459cc
1d5baca
422c4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,6 +662,67 @@ suite "GossipSub internal": | |
await allFuturesThrowing(conns.mapIt(it.close())) | ||
await gossipSub.switch.stop() | ||
|
||
# test cases for block 5 gossibsub test plan | ||
# check correctly parsed ihave/iwant/graft/prune/idontwant messages | ||
# check value before & after decoding equal using protoc cmd tool for reference | ||
# check encoding / decoding time less than 1 millisecond | ||
asyncTest "Check RPCMsg encoding": | ||
let backofftime = 10.uint64 | ||
var id: seq[byte] = @[123] | ||
let rpcMsg = RPCMsg( | ||
control: some( | ||
ControlMessage( | ||
ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], | ||
iwant: @[ControlIWant(messageIDs: @[id])], | ||
graft: @[ControlGraft(topicID: "foobar")], | ||
prune: @[ControlPrune(topicID: "foobar", backoff: backofftime)], | ||
idontwant: @[ControlIWant(messageIDs: @[id])], | ||
) | ||
) | ||
) | ||
let encodedExpected: seq[byte] = | ||
@[ | ||
26, 51, 10, 10, 6, 102, 111, 111, 98, 97, 114, 18, 3, 49, 50, 51, 18, 5, 10, 3, | ||
49, 50, 51, 26, 8, 10, 6, 102, 111, 111, 98, 97, 114, 34, 10, 10, 6, 102, 111, | ||
111, 98, 97, 114, 16, 10, 42, 5, 10, 3, 49, 50, 51, | ||
] #encoded using protoc cmd tool | ||
|
||
let encodeTimeout = Moment.now() + 1.milliseconds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests for functionality that is deterministic should never have timing-based components - this is testing whether the clock on the computer is working and the speed of the cpu, which is irrelevant for the given functionality There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. timing check removed |
||
let encodedMsg = encodeRpcMsg(rpcMsg, true) | ||
let timeout2 = Moment.now() | ||
check: | ||
encodeTimeout > timeout2 | ||
encodedExpected == encodedMsg | ||
|
||
asyncTest "Check RPCMsg decoding": | ||
let backofftime = 12.uint64 | ||
let id: seq[byte] = @[1] | ||
let originMessage = RPCMsg( | ||
control: some( | ||
ControlMessage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since you used all message types in the encoding, does it make sense to use all of them in the decoding as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])], | ||
iwant: @[ControlIWant(messageIDs: @[id])], | ||
graft: @[ControlGraft(topicID: "topic")], | ||
prune: @[ControlPrune(topicID: "new", backoff: backofftime)], | ||
idontwant: @[ControlIWant(messageIDs: @[id])], | ||
) | ||
) | ||
) | ||
#data encoded using protoc cmd tool | ||
let encodedMsg: seq[byte] = | ||
@[ | ||
26, 41, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 49, 18, 3, 10, 1, 49, | ||
26, 7, 10, 5, 116, 111, 112, 105, 99, 34, 7, 10, 3, 110, 101, 119, 16, 12, 42, | ||
3, 10, 1, 49, | ||
] | ||
|
||
let decodeTimeout = Moment.now() + 1.milliseconds | ||
var rpcMsg = decodeRpcMsg(encodedMsg).value | ||
let timeout2 = Moment.now() | ||
check: | ||
decodeTimeout > timeout2 | ||
rpcMsg == originMessage | ||
|
||
asyncTest "handleIHave/Iwant tests": | ||
let gossipSub = TestGossipSub.init(newStandardSwitch()) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that TC5.9 was not in the original scope of this task but maybe we should add it here as well if it makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idontwant added in the latest commit