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 3 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
55 changes: 55 additions & 0 deletions tests/pubsub/testgossipinternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,61 @@ 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 messages
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment need updating:

  • small missallignment
  • Graft and Prune is also checked in the test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# 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

)
)
)
let encodedExpected: seq[byte] =
@[
26, 44, 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,
] #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 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])],
graft: @[ControlGraft(topicID: "foobar")],
)
)
)
#data encoded using protoc cmd tool
let encodedMsg: seq[byte] =
@[
26, 23, 10, 11, 10, 6, 102, 111, 111, 98, 97, 114, 18, 1, 49, 26, 8, 10, 6, 102,
111, 111, 98, 97, 114,
]

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