2021-12-06 19:51:37 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import std/[options, sequtils], stew/results, testutils/unittests
|
2024-10-24 12:31:04 +00:00
|
|
|
import waku/waku_core, waku/waku_enr, ./testlib/wakucore, waku/waku_core/codecs
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
suite "Waku ENR - Capabilities bitfield":
|
|
|
|
test "check capabilities support":
|
|
|
|
## Given
|
2024-03-15 23:08:47 +00:00
|
|
|
let bitfield: CapabilitiesBitfield = 0b0000_1101u8 # Lightpush, Filter, Relay
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
bitfield.supportsCapability(Capabilities.Relay)
|
|
|
|
not bitfield.supportsCapability(Capabilities.Store)
|
|
|
|
bitfield.supportsCapability(Capabilities.Filter)
|
|
|
|
bitfield.supportsCapability(Capabilities.Lightpush)
|
|
|
|
|
|
|
|
test "bitfield to capabilities list":
|
|
|
|
## Given
|
|
|
|
let bitfield = CapabilitiesBitfield.init(
|
2024-03-15 23:08:47 +00:00
|
|
|
relay = true, store = false, lightpush = true, filter = true
|
|
|
|
)
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let caps = bitfield.toCapabilities()
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
caps == @[Capabilities.Relay, Capabilities.Filter, Capabilities.Lightpush]
|
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
test "encode and decode record with capabilities field (EnrBuilder ext)":
|
2023-03-10 10:49:41 +00:00
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
## When
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
|
|
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)
|
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
2023-03-22 15:01:02 +00:00
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
2023-03-10 10:49:41 +00:00
|
|
|
|
2023-03-22 15:01:02 +00:00
|
|
|
let bitfieldOpt = typedRecord.value.waku2
|
|
|
|
check bitfieldOpt.isSome()
|
|
|
|
|
|
|
|
let bitfield = bitfieldOpt.get()
|
2023-03-10 10:49:41 +00:00
|
|
|
check:
|
|
|
|
bitfield.toCapabilities() == @[Capabilities.Relay, Capabilities.Store]
|
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
test "cannot decode capabilities from record":
|
2023-03-08 14:44:10 +00:00
|
|
|
## Given
|
2023-03-10 10:49:41 +00:00
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## When
|
2023-03-22 15:01:02 +00:00
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
2023-03-08 14:44:10 +00:00
|
|
|
|
2023-03-22 15:01:02 +00:00
|
|
|
let bitfieldOpt = typedRecord.value.waku2
|
2023-03-08 14:44:10 +00:00
|
|
|
|
2023-03-22 15:01:02 +00:00
|
|
|
## Then
|
|
|
|
check bitfieldOpt.isNone()
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
test "check capabilities on a waku node record":
|
|
|
|
## Given
|
2024-03-15 23:08:47 +00:00
|
|
|
let wakuRecord =
|
|
|
|
"-Hy4QC73_E3B_FkZhsOakaD4pHe-U--UoGASdG9N0F3SFFUDY_jdQbud8" &
|
|
|
|
"EXVyrlOZ5pZ7VYFBDPMRCENwy87Lh74dFIBgmlkgnY0iXNlY3AyNTZrMaECvNt1jIWbWGp" &
|
|
|
|
"AWWdlLGYm1E1OjlkQk3ONoxDC5sfw8oOFd2FrdTID"
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
var record: Record
|
|
|
|
require waku_enr.fromBase64(record, wakuRecord)
|
|
|
|
|
|
|
|
## Then
|
2023-03-22 15:01:02 +00:00
|
|
|
let typedRecordRes = record.toTyped()
|
|
|
|
require typedRecordRes.isOk()
|
|
|
|
|
|
|
|
let bitfieldOpt = typedRecordRes.value.waku2
|
|
|
|
require bitfieldOpt.isSome()
|
|
|
|
|
|
|
|
let bitfield = bitfieldOpt.get()
|
2023-03-08 14:44:10 +00:00
|
|
|
check:
|
2023-03-22 15:01:02 +00:00
|
|
|
bitfield.supportsCapability(Capabilities.Relay) == true
|
|
|
|
bitfield.supportsCapability(Capabilities.Store) == true
|
|
|
|
bitfield.supportsCapability(Capabilities.Filter) == false
|
|
|
|
bitfield.supportsCapability(Capabilities.Lightpush) == false
|
|
|
|
bitfield.toCapabilities() == @[Capabilities.Relay, Capabilities.Store]
|
2023-03-08 14:44:10 +00:00
|
|
|
|
2024-10-24 12:31:04 +00:00
|
|
|
test "get capabilities codecs from record":
|
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
## When
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
|
|
builder.withWakuCapabilities(Capabilities.Relay, Capabilities.Store)
|
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
|
|
|
|
## Then
|
|
|
|
assert recordRes.isOk(), $recordRes.error
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
|
|
|
let codecs = record.getCapabilitiesCodecs()
|
|
|
|
check:
|
|
|
|
codecs.len == 2
|
|
|
|
codecs.contains(WakuRelayCodec)
|
|
|
|
codecs.contains(WakuStoreCodec)
|
|
|
|
|
2023-03-08 14:44:10 +00:00
|
|
|
test "check capabilities on a non-waku node record":
|
|
|
|
## Given
|
|
|
|
# non waku enr, i.e. Ethereum one
|
2024-03-15 23:08:47 +00:00
|
|
|
let nonWakuEnr =
|
|
|
|
"enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2G" &
|
|
|
|
"xb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNl" &
|
|
|
|
"Y3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA"
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## When
|
2023-03-22 15:01:02 +00:00
|
|
|
var record: Record
|
|
|
|
require waku_enr.fromURI(record, nonWakuEnr)
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
## Then
|
2023-03-22 15:01:02 +00:00
|
|
|
let typedRecordRes = record.toTyped()
|
|
|
|
require typedRecordRes.isOk()
|
|
|
|
|
|
|
|
let bitfieldOpt = typedRecordRes.value.waku2
|
|
|
|
check bitfieldOpt.isNone()
|
|
|
|
|
2023-03-08 14:44:10 +00:00
|
|
|
check:
|
2023-03-22 15:01:02 +00:00
|
|
|
record.getCapabilities() == []
|
|
|
|
record.supportsCapability(Capabilities.Relay) == false
|
|
|
|
record.supportsCapability(Capabilities.Store) == false
|
|
|
|
record.supportsCapability(Capabilities.Filter) == false
|
|
|
|
record.supportsCapability(Capabilities.Lightpush) == false
|
2023-03-08 14:44:10 +00:00
|
|
|
|
|
|
|
suite "Waku ENR - Multiaddresses":
|
2023-03-30 07:35:13 +00:00
|
|
|
test "decode record with multiaddrs field":
|
|
|
|
## Given
|
2024-03-15 23:08:47 +00:00
|
|
|
let enrUri =
|
2024-08-05 10:57:43 +00:00
|
|
|
"enr:-QEMuEAs8JmmyUI3b9v_ADqYtELHUYAsAMS21lA2BMtrzF86tVmyy9cCrhmzfHGH" &
|
|
|
|
"x_g3nybn7jIRybzXTGNj3C2KzrriAYJpZIJ2NIJpcISf3_Jeim11bHRpYWRkcnO4XAAr" &
|
|
|
|
"NiZzdG9yZS0wMS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1cy5pbQZ2XwAtNiZzdG9y" &
|
|
|
|
"ZS0wMS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1cy5pbQYBu94DgnJzjQAQBQABACAA" &
|
|
|
|
"QACAAQCJc2VjcDI1NmsxoQLfoaQH3oSYW59yxEBfeAZbltmUnC4BzYkHqer2VQMTyoN0" &
|
|
|
|
"Y3CCdl-DdWRwgiMohXdha3UyAw"
|
2023-03-30 07:35:13 +00:00
|
|
|
|
|
|
|
var record: Record
|
|
|
|
require record.fromURI(enrUri)
|
|
|
|
|
2024-03-11 13:48:20 +00:00
|
|
|
# TODO: get rid of wakuv2 here too. Needt to generate a ne ENR record
|
2021-12-06 19:51:37 +00:00
|
|
|
let
|
2024-03-15 23:08:47 +00:00
|
|
|
expectedAddr1 = MultiAddress
|
2024-08-05 10:57:43 +00:00
|
|
|
.init("/dns4/store-01.do-ams3.status.prod.status.im/tcp/30303")
|
2024-03-15 23:08:47 +00:00
|
|
|
.get()
|
|
|
|
expectedAddr2 = MultiAddress
|
2024-08-05 10:57:43 +00:00
|
|
|
.init("/dns4/store-01.do-ams3.status.prod.status.im/tcp/443/wss")
|
2024-03-15 23:08:47 +00:00
|
|
|
.get()
|
2023-03-30 07:35:13 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check multiaddrsOpt.isSome()
|
|
|
|
let multiaddrs = multiaddrsOpt.get()
|
2024-08-05 10:57:43 +00:00
|
|
|
|
2021-12-06 19:51:37 +00:00
|
|
|
check:
|
2024-08-05 10:57:43 +00:00
|
|
|
multiaddrs.len == 2
|
2023-03-30 07:35:13 +00:00
|
|
|
multiaddrs.contains(expectedAddr1)
|
|
|
|
multiaddrs.contains(expectedAddr2)
|
|
|
|
|
|
|
|
test "encode and decode record with multiaddrs field (EnrBuilder ext)":
|
|
|
|
## Given
|
2021-12-06 19:51:37 +00:00
|
|
|
let
|
2023-03-30 07:35:13 +00:00
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
2021-12-06 19:51:37 +00:00
|
|
|
|
|
|
|
let
|
2023-03-30 07:35:13 +00:00
|
|
|
addr1 = MultiAddress.init("/ip4/127.0.0.1/tcp/80/ws").get()
|
|
|
|
addr2 = MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss").get()
|
|
|
|
|
|
|
|
## When
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
|
|
builder.withMultiaddrs(addr1, addr2)
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
let recordRes = builder.build()
|
|
|
|
|
|
|
|
require recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check multiaddrsOpt.isSome()
|
|
|
|
|
|
|
|
let multiaddrs = multiaddrsOpt.get()
|
2021-12-06 19:51:37 +00:00
|
|
|
check:
|
2023-03-30 07:35:13 +00:00
|
|
|
multiaddrs.len == 2
|
|
|
|
multiaddrs.contains(addr1)
|
|
|
|
multiaddrs.contains(addr2)
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
test "cannot decode multiaddresses from record":
|
|
|
|
## Given
|
2021-12-06 19:51:37 +00:00
|
|
|
let
|
2023-03-30 07:35:13 +00:00
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
|
|
|
|
|
|
|
## When
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let fieldOpt = typedRecord.value.multiaddrs
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check fieldOpt.isNone()
|
2021-12-06 19:51:37 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
test "encode and decode record with multiaddresses field - strip peer ID":
|
|
|
|
## Given
|
2021-12-06 19:51:37 +00:00
|
|
|
let
|
2023-03-30 07:35:13 +00:00
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
2021-12-06 19:51:37 +00:00
|
|
|
|
|
|
|
let
|
2024-03-15 23:08:47 +00:00
|
|
|
addr1 = MultiAddress
|
|
|
|
.init(
|
|
|
|
"/ip4/127.0.0.1/tcp/80/ws/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr31iDQpSN5Qa882BCjjwgrD"
|
|
|
|
)
|
|
|
|
.get()
|
2023-03-30 07:35:13 +00:00
|
|
|
addr2 = MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss").get()
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
let expectedAddr1 = MultiAddress.init("/ip4/127.0.0.1/tcp/80/ws").get()
|
2021-12-06 19:51:37 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
## When
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
|
|
|
builder.withMultiaddrs(addr1, addr2)
|
|
|
|
|
|
|
|
let recordRes = builder.build()
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
require recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
2021-12-06 19:51:37 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
let multiaddrsOpt = typedRecord.value.multiaddrs
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check multiaddrsOpt.isSome()
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-03-30 07:35:13 +00:00
|
|
|
let multiaddrs = multiaddrsOpt.get()
|
|
|
|
check:
|
|
|
|
multiaddrs.contains(expectedAddr1)
|
|
|
|
multiaddrs.contains(addr2)
|
2022-11-10 09:29:34 +00:00
|
|
|
|
2023-04-17 13:21:20 +00:00
|
|
|
suite "Waku ENR - Relay static sharding":
|
2023-10-05 12:37:05 +00:00
|
|
|
test "new relay shards object with single invalid shard id":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shard: uint16 = 1024
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## When
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shard)
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
## Then
|
2023-10-05 12:37:05 +00:00
|
|
|
assert shardsTopics.isErr(), $shardsTopics.get()
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
test "new relay shards object with single invalid shard id in list":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardIds: seq[uint16] = @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16, 1024u16]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## When
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds)
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
## Then
|
2023-10-05 12:37:05 +00:00
|
|
|
assert shardsTopics.isErr(), $shardsTopics.get()
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
test "new relay shards object with single valid shard id":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardId: uint16 = 1
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2024-09-10 21:07:12 +00:00
|
|
|
let shard = RelayShard(clusterId: clusterId, shardId: shardId)
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## When
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardId).expect("Valid Shards")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsTopics.clusterId == clusterId
|
|
|
|
shardsTopics.shardIds == @[1u16]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2024-08-19 09:29:35 +00:00
|
|
|
let shards = shardsTopics.topics.mapIt($it)
|
2023-04-17 13:21:20 +00:00
|
|
|
check:
|
2024-08-19 09:29:35 +00:00
|
|
|
shards == @[$shard]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
check:
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsTopics.contains(clusterId, shardId)
|
|
|
|
not shardsTopics.contains(clusterId, 33u16)
|
|
|
|
not shardsTopics.contains(20u16, 33u16)
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2024-08-19 09:29:35 +00:00
|
|
|
shardsTopics.contains(shard)
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsTopics.contains("/waku/2/rs/22/1")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
test "new relay shards object with repeated but valid shard ids":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardIds: seq[uint16] = @[1u16, 2u16, 2u16, 3u16, 3u16, 3u16]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## When
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid Shards")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsTopics.clusterId == clusterId
|
|
|
|
shardsTopics.shardIds == @[1u16, 2u16, 3u16]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
test "cannot decode relay shards from record if not present":
|
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let record = EnrBuilder.init(enrPrivKey, enrSeqNum).build().tryGet()
|
|
|
|
|
|
|
|
## When
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let fieldOpt = typedRecord.value.relaySharding
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check fieldOpt.isNone()
|
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
test "encode and decode record with relay shards field (EnrBuilder ext - shardIds list)":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardIds: seq[uint16] = @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16]
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid Shards")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check recordRes.isOk()
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
|
|
check:
|
|
|
|
shardsOpt.isSome()
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsOpt.get() == shardsTopics
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
test "encode and decode record with relay shards field (EnrBuilder ext - bit vector)":
|
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let shardsTopics =
|
|
|
|
RelayShards.init(33, toSeq(0u16 ..< 64u16)).expect("Valid Shards")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
|
|
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
|
|
|
## When
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
shardsOpt.isSome()
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsOpt.get() == shardsTopics
|
2023-04-17 13:21:20 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
test "decode record with relay shards shard list and bit vector fields":
|
2023-04-17 13:21:20 +00:00
|
|
|
## Given
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let
|
2024-03-15 23:08:47 +00:00
|
|
|
relayShardsIndicesList = RelayShards
|
|
|
|
.init(22, @[1u16, 1u16, 2u16, 3u16, 5u16, 8u16])
|
|
|
|
.expect("Valid Shards")
|
|
|
|
relayShardsBitVector = RelayShards
|
|
|
|
.init(33, @[13u16, 24u16, 37u16, 61u16, 98u16, 159u16])
|
|
|
|
.expect("Valid Shards")
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelayShardingIndicesList(relayShardsIndicesList).isOk()
|
|
|
|
require builder.withWakuRelayShardingBitVector(relayShardsBitVector).isOk()
|
2023-04-17 13:21:20 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
|
|
|
|
|
|
let record = recordRes.tryGet()
|
|
|
|
|
|
|
|
## When
|
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
require typedRecord.isOk()
|
|
|
|
|
|
|
|
let shardsOpt = typedRecord.value.relaySharding
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
shardsOpt.isSome()
|
2023-10-05 12:37:05 +00:00
|
|
|
shardsOpt.get() == relayShardsIndicesList
|