@@ -11,35 +11,47 @@ import
11
11
confutils
12
12
import
13
13
../../ waku/ factory/ external_config,
14
- ../../ waku/ factory/ internal_config,
15
14
../../ waku/ factory/ networks_config,
16
- ../../ waku/ common/ logging
15
+ ../../ waku/ factory/ waku_conf,
16
+ ../../ waku/ common/ logging,
17
+ ../../ waku/ common/ utils/ parse_size_units
17
18
18
19
suite " Waku config - apply preset" :
19
20
test " Default preset is TWN" :
20
21
# # Setup
21
22
let expectedConf = ClusterConf .TheWakuNetworkConf ()
22
23
23
24
# # Given
24
- let preConfig = WakuNodeConf (cmd: noCommand, preset: " twn" )
25
+ let preConfig = WakuNodeConf (
26
+ cmd: noCommand,
27
+ preset: " twn" ,
28
+ relay: true ,
29
+ rlnRelayEthClientAddress: " http://someaddress" .EthRpcUrl ,
30
+ rlnRelayTreePath: " /tmp/sometreepath" ,
31
+ )
25
32
26
33
# # When
27
- let res = applyPresetConfiguration ( preConfig)
34
+ let res = preConfig. toWakuConf ( )
28
35
assert res.isOk (), $ res.error
29
36
30
37
# # Then
31
38
let conf = res.get ()
32
- assert conf.maxMessageSize == expectedConf.maxMessageSize
33
- assert conf.clusterId == expectedConf.clusterId
34
- assert conf.rlnRelay == expectedConf.rlnRelay
35
- assert conf.rlnRelayEthContractAddress == expectedConf.rlnRelayEthContractAddress
36
- assert conf.rlnRelayDynamic == expectedConf.rlnRelayDynamic
37
- assert conf.rlnRelayChainId == expectedConf.rlnRelayChainId
38
- assert conf.rlnRelayBandwidthThreshold == expectedConf.rlnRelayBandwidthThreshold
39
- assert conf.rlnEpochSizeSec == expectedConf.rlnEpochSizeSec
40
- assert conf.rlnRelayUserMessageLimit == expectedConf.rlnRelayUserMessageLimit
41
- assert conf.numShardsInNetwork == expectedConf.numShardsInNetwork
42
- assert conf.discv5BootstrapNodes == expectedConf.discv5BootstrapNodes
39
+ check conf.maxMessageSizeBytes ==
40
+ uint64 (parseCorrectMsgSize (expectedConf.maxMessageSize))
41
+ check conf.clusterId == expectedConf.clusterId
42
+ check conf.rlnRelayConf.isSome () == expectedConf.rlnRelay
43
+ if conf.rlnRelayConf.isSome ():
44
+ let rlnRelayConf = conf.rlnRelayConf.get ()
45
+ check rlnRelayConf.ethContractAddress == expectedConf.rlnRelayEthContractAddress
46
+ check rlnRelayConf.dynamic == expectedConf.rlnRelayDynamic
47
+ check rlnRelayConf.chainId == expectedConf.rlnRelayChainId
48
+ check rlnRelayConf.epochSizeSec == expectedConf.rlnEpochSizeSec
49
+ check rlnRelayConf.userMessageLimit == expectedConf.rlnRelayUserMessageLimit
50
+ check conf.numShardsInNetwork == expectedConf.numShardsInNetwork
51
+ check conf.discv5Conf.isSome () == expectedConf.discv5Discovery
52
+ if expectedConf.discv5Discovery:
53
+ let discv5Conf = conf.discv5Conf.get ()
54
+ check discv5Conf.bootstrapNodes == expectedConf.discv5BootstrapNodes
43
55
44
56
test " Subscribes to all valid shards in twn" :
45
57
# # Setup
@@ -50,12 +62,12 @@ suite "Waku config - apply preset":
50
62
let preConfig = WakuNodeConf (cmd: noCommand, preset: " twn" , shards: shards)
51
63
52
64
# # When
53
- let res = applyPresetConfiguration ( preConfig)
65
+ let res = preConfig. toWakuConf ( )
54
66
assert res.isOk (), $ res.error
55
67
56
68
# # Then
57
69
let conf = res.get ()
58
- assert conf.shards.len == expectedConf.numShardsInNetwork.int
70
+ check conf.shards.len == expectedConf.numShardsInNetwork.int
59
71
60
72
test " Subscribes to some valid shards in twn" :
61
73
# # Setup
@@ -66,9 +78,8 @@ suite "Waku config - apply preset":
66
78
let preConfig = WakuNodeConf (cmd: noCommand, preset: " twn" , shards: shards)
67
79
68
80
# # When
69
- let resConf = applyPresetConfiguration (preConfig)
70
- let res = validateShards (resConf.get ())
71
- assert res.isOk (), $ res.error
81
+ let resConf = preConfig.toWakuConf ()
82
+ assert resConf.isOk (), $ resConf.error
72
83
73
84
# # Then
74
85
let conf = resConf.get ()
@@ -82,10 +93,9 @@ suite "Waku config - apply preset":
82
93
# # Given
83
94
let shards: seq [uint16 ] = @ [0 , 4 , 7 , 10 ]
84
95
let preConfig = WakuNodeConf (cmd: noCommand, preset: " twn" , shards: shards)
85
- let postConfig = applyPresetConfiguration (preConfig)
86
96
87
97
# # When
88
- let res = validateShards (postConfig. get () )
98
+ let res = preConfig. toWakuConf ( )
89
99
90
100
# # Then
91
101
assert res.isErr (), " Invalid shard was accepted"
@@ -103,11 +113,11 @@ suite "Waku config - node key":
103
113
let config = WakuNodeConf .load (version = " " , cmdLine = @ [" --nodekey=" & nodeKeyStr])
104
114
105
115
# # When
106
- let res = getNodeKey ( config)
116
+ let res = config. toWakuConf ( )
107
117
assert res.isOk (), $ res.error
108
118
109
119
# # Then
110
- let resKey = res.get ()
120
+ let resKey = res.get ().nodeKey
111
121
assert utils.toHex (resKey.getRawBytes ().get ()) ==
112
122
utils.toHex (nodekey.getRawBytes ().get ())
113
123
@@ -118,28 +128,31 @@ suite "Waku config - Shards":
118
128
# # Given
119
129
let shards: seq [uint16 ] = @ [0 , 2 , 4 ]
120
130
let numShardsInNetwork = 5 .uint32
121
- let config = WakuNodeConf (
131
+ let wakuNodeConf = WakuNodeConf (
122
132
cmd: noCommand, shards: shards, numShardsInNetwork: numShardsInNetwork
123
133
)
124
134
125
135
# # When
126
- let res = validateShards (config)
136
+ let res = wakuNodeConf.toWakuConf ()
137
+ assert res.isOk (), $ res.error
127
138
128
139
# # Then
129
- assert res.isOk (), $ res.error
140
+ let wakuConf = res.get ()
141
+ let vRes = wakuConf.validate ()
142
+ assert vRes.isOk (), $ vRes.error
130
143
131
144
test " Shards are not in range" :
132
145
# # Setup
133
146
134
147
# # Given
135
148
let shards: seq [uint16 ] = @ [0 , 2 , 5 ]
136
149
let numShardsInNetwork = 5 .uint32
137
- let config = WakuNodeConf (
150
+ let wakuNodeConf = WakuNodeConf (
138
151
cmd: noCommand, shards: shards, numShardsInNetwork: numShardsInNetwork
139
152
)
140
153
141
154
# # When
142
- let res = validateShards (config )
155
+ let res = wakuNodeConf. toWakuConf ( )
143
156
144
157
# # Then
145
158
assert res.isErr (), " Invalid shard was accepted"
@@ -148,10 +161,12 @@ suite "Waku config - Shards":
148
161
# # Setup
149
162
150
163
# # Given
151
- let config = WakuNodeConf .load (version = " " , cmdLine = @ [" --shard=32" ])
164
+ let wakuNodeConf = WakuNodeConf .load (version = " " , cmdLine = @ [" --shard=32" ])
152
165
153
166
# # When
154
- let res = validateShards (config )
167
+ let res = wakuNodeConf. toWakuConf ( )
155
168
156
169
# # Then
157
- assert res.isOk (), $ res.error
170
+ let wakuConf = res.get ()
171
+ let vRes = wakuConf.validate ()
172
+ assert vRes.isOk (), $ vRes.error
0 commit comments