Skip to content

Commit

Permalink
Test cases of block5[1,2,7]
Browse files Browse the repository at this point in the history
  • Loading branch information
AYAHASSAN287 committed Oct 1, 2024
1 parent 7477059 commit 4f96d1b
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions tests/pubsub/testgossipinternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -663,49 +663,29 @@ suite "GossipSub internal":
await gossipSub.switch.stop()

# test cases for block 5 gossibsub test plan
# tests 1 -4 for checking the formatting of objects
# have - want - graft - prune

asyncTest "Check ControlIHave formatting":
let topic = "dummytopic"

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

asyncTest "Check ControlIWant formatting":
let msgID = @[0'u8, 1, 2, 3]
let msg = ControlIWant(messageIDs: @[msgID])
check:
msg.messageIDs == @[msgID]

asyncTest "Check ControGraft formatting":
let topic = "dummytopic"
let msg = ControlGraft(topicID: topic)
check:
msg.topicID == topic

asyncTest "Check ControPrune":
let topic = "foobar"
#var peerecord:seq[bytes]
var
peerecord: seq[byte] = @[1, 2, 3]
peerData: seq[byte] = @[4, 5]
backoff: uint64 = 123
peerInfo = PeerInfoMsg(
peerId: PeerId(data: @['e'.byte]), # 1 byte
signedPeerRecord: @['f'.byte, 'g'.byte] # 2 bytes
,
#check correctly parsed ihave/iwant messages
# check value before & after decoding equal " round trip testing
# check encoding / decoding time less than 1 millisecond
asyncTest "Check encoding/decoding roundtrip ":
let id = @[0'u8, 1, 2, 3]
let msg = Message(topic: "topic", data: id)
let rpcMsg = RPCMsg(
control: some(
ControlMessage(ihave: @[ControlIHave(topicID: "foobar", messageIDs: @[id])],
iwant: @[ControlIWant(messageIDs: @[@[0'u8,1,2]])])
)

let msg = ControlPrune(topicID: topic, peers: @[peerInfo], backoff: backoff)
)
let encodeTimeout = Moment.now() + 1.milliseconds
let encoded = encodeRpcMsg(rpcMsg, true)
let timeout2 = Moment.now()
let decoded = decodeRpcMsg(encoded)
echo encoded
let decodeTime = Moment.now()
check:
msg.topicID == topic
msg.peers.contains(peerInfo)
msg.backoff == backoff

rpcMsg == decoded.value
encodeTimeout > timeout2
timeout2+1.milliseconds > decodeTime
asyncTest "handleIHave/Iwant tests":
let gossipSub = TestGossipSub.init(newStandardSwitch())

Expand Down

0 comments on commit 4f96d1b

Please sign in to comment.