Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions tests/pubsub/testgossipinternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Copy link

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

Copy link
Author

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

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
Copy link
Contributor

@arnetheduck arnetheduck Oct 3, 2024

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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(
Copy link

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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())

Expand Down
Loading