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

Conversation

AYAHASSAN287
Copy link

@AYAHASSAN287 AYAHASSAN287 commented Sep 30, 2024

Note the 2 tests failed and issue #1208 is opened accordingly
Note: PR ready for review
test cases written according to test plan here

Test "Check RPCMsg encoding"

  1. create rpcMessage and encode it using encodeRpcMsg
  2. compare encoded message to encoded message generated from protoc cmd tool version "libprotoc 3.21.12"

Test "Check RPCMsg decoding"

  1. Use RPC message & encoded version of it generated from protoc cmd tool version "libprotoc 3.21.12" as a reference
  2. Check that decodeRpcMsg will decode the refernce RPC message successfully to the original version

@diegomrsantos
Copy link
Contributor

Could you please write a more descriptive description, like the one on #1201 ?

let topic = "dummytopic"

let msgID = @[0'u8, 1, 2, 3]
let msg = ControlIHave(topicID: topic, messageIDs: @[msgID])
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these tests for? they're effectively testing that nim object initialization works, and nothing beyond that since they don't exercise any actual logic such as encoding to and from protobuf. As such, they add maintenance and code volume without providing any value.

Copy link
Author

Choose a reason for hiding this comment

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

if I add the checks of objects parameters to an already existing test case to reduce code volume would it be acceptable ?

the reason of these checks is to verify that message objects are defined with respect to protobuf schema

Copy link
Contributor

@arnetheduck arnetheduck Sep 30, 2024

Choose a reason for hiding this comment

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

to test schema conformance, you need to create encoded byte streams and decode these messages into the nim types that we use. You can create such messages using https://www.tutorialspoint.com/protobuf/protobuf_command_line_usage.htm as long as it's possible to regenerate the tests in a reasonable way - ie the aim of such a test is to ensure that encoding and decoding of the nim types results in the expected protobuf bytes (and that the test remain maintainable, ie if someone comes across the code in 5 months and wants to add a test, this is reasonably simple)

Copy link
Contributor

Choose a reason for hiding this comment

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

One way to structure such tests can be seen in https://github.com/status-im/nim-eth/blob/master/tests/common/test_common.nim - this tests RLP (a different encoding) but premise is the same - there, you can see how example content is loaded and cross-verified against a "decoded" version of the same message.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we create the instances, encode, decode, and check the decoded instance is the same as the original instance?

Copy link
Contributor

Choose a reason for hiding this comment

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

that's called a roundtrip test, which broadly are less valuable / useful - it tests that the encoder is compatible with the decoder, with the risk that they both share the same bug and therefore remain incompatible with the schema.

When testing conformance to specifications, it's better to work with canonical examples based on the spec that have been generated independently using a reference implementation.

Copy link
Author

Choose a reason for hiding this comment

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

I have a question then what is the proper max time for the encoding/decoding as I couldn't find it in the specs

@diegomrsantos
Copy link
Contributor

We follow conventional commits for the PR title. In this case, it will start with test(gossipsub):

@AYAHASSAN287 AYAHASSAN287 changed the title adding block5 protobuf 1-4 test cases test(gossipsub):block5 protobuf test cases Sep 30, 2024
@AYAHASSAN287 AYAHASSAN287 changed the title test(gossipsub):block5 protobuf test cases test(gossipsub): block5 protobuf test cases Sep 30, 2024
@vacp2p vacp2p deleted a comment from AYAHASSAN287 Sep 30, 2024
Copy link

@fbarbu15 fbarbu15 left a comment

Choose a reason for hiding this comment

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

Thanks, added minor comments

@@ -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

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: "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

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

Copy link

@fbarbu15 fbarbu15 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@AYAHASSAN287 AYAHASSAN287 marked this pull request as ready for review October 3, 2024 15:33
@diegomrsantos
Copy link
Contributor

diegomrsantos commented Oct 10, 2024

What schema was used to generate the expected encoding? The one specified here - as mentioned in #1208 - doesn't have idontwant. This update should be considered.

@AYAHASSAN287
Copy link
Author

What schema was used to generate the expected encoding? The one specified here - as mentioned in #1208 - doesn't have idontwant. This update should be considered.

I added idontwant to the schema used to generate the expected .
Note: the issue of not matching the expected exists even without adding the "IDontWant"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: backlog
Development

Successfully merging this pull request may close these issues.

5 participants