Skip to content

Commit

Permalink
Use --styleCheck:error for Fluffy + fixes (#2247)
Browse files Browse the repository at this point in the history
* Use --styleCheck:error for Fluffy + fixes

There seems to be a clash between the names of an object field and
a proc here. As workaround names of the procs are changed.

* Fix case style for rpc client calls in test_portal_testnet

* Fix style case for utp test
  • Loading branch information
kdeme committed May 30, 2024
1 parent 919242c commit d814d84
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
8 changes: 4 additions & 4 deletions fluffy/network/beacon/beacon_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type
onFinalizedHeader*, onOptimisticHeader*: LightClientHeaderCallback
trustedBlockRoot*: Option[Eth2Digest]

func finalizedHeader*(lightClient: LightClient): ForkedLightClientHeader =
func getFinalizedHeader*(lightClient: LightClient): ForkedLightClientHeader =
withForkyStore(lightClient.store[]):
when lcDataFork > LightClientDataFork.None:
var header = ForkedLightClientHeader(kind: lcDataFork)
Expand All @@ -45,7 +45,7 @@ func finalizedHeader*(lightClient: LightClient): ForkedLightClientHeader =
else:
default(ForkedLightClientHeader)

func optimisticHeader*(lightClient: LightClient): ForkedLightClientHeader =
func getOptimisticHeader*(lightClient: LightClient): ForkedLightClientHeader =
withForkyStore(lightClient.store[]):
when lcDataFork > LightClientDataFork.None:
var header = ForkedLightClientHeader(kind: lcDataFork)
Expand Down Expand Up @@ -82,11 +82,11 @@ proc new*(

proc onFinalizedHeader() =
if lightClient.onFinalizedHeader != nil:
lightClient.onFinalizedHeader(lightClient, lightClient.finalizedHeader)
lightClient.onFinalizedHeader(lightClient, lightClient.getFinalizedHeader)

proc onOptimisticHeader() =
if lightClient.onOptimisticHeader != nil:
lightClient.onOptimisticHeader(lightClient, lightClient.optimisticHeader)
lightClient.onOptimisticHeader(lightClient, lightClient.getOptimisticHeader)

lightClient.processor = LightClientProcessor.new(
dumpEnabled, dumpDirInvalid, dumpDirIncoming, cfg, genesis_validators_root,
Expand Down
2 changes: 1 addition & 1 deletion fluffy/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
-d:PREFER_BLST_SHA256=false

--styleCheck:usages
--styleCheck:hint
--styleCheck:error
--hint[ConvFromXtoItselfNotNeeded]:off
--hint[Processing]:off
19 changes: 10 additions & 9 deletions fluffy/scripts/test_portal_testnet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ procSuite "Portal testnet tests":
let clients = await connectToRpcServers(config)

var nodeInfos: seq[NodeInfo]

for client in clients:
let nodeInfo = await client.portal_state_nodeInfo()
let nodeInfo = await client.portal_stateNodeInfo()
await client.close()
nodeInfos.add(nodeInfo)

for client in clients:
discard await client.portal_state_addEnrs(
discard await client.portal_stateAddEnrs(
nodeInfos.map(
proc(x: NodeInfo): Record =
x.enr
Expand All @@ -187,7 +188,7 @@ procSuite "Portal testnet tests":
await client.close()

for client in clients:
let routingTableInfo = await client.portal_state_routingTableInfo()
let routingTableInfo = await client.portal_stateRoutingTableInfo()
await client.close()
var start: seq[NodeId]
let nodes = foldl(routingTableInfo.buckets, a & b, start)
Expand All @@ -198,7 +199,7 @@ procSuite "Portal testnet tests":
for client in clients:
var enr: Record
try:
enr = await client.portal_state_lookupEnr(randomNodeInfo.nodeId)
enr = await client.portal_stateLookupEnr(randomNodeInfo.nodeId)
except CatchableError as e:
echo e.msg
# TODO: For state network this occasionally fails. It might be because the
Expand All @@ -214,12 +215,12 @@ procSuite "Portal testnet tests":

var nodeInfos: seq[NodeInfo]
for client in clients:
let nodeInfo = await client.portal_history_nodeInfo()
let nodeInfo = await client.portal_historyNodeInfo()
await client.close()
nodeInfos.add(nodeInfo)

for client in clients:
discard await client.portal_history_addEnrs(
discard await client.portal_historyAddEnrs(
nodeInfos.map(
proc(x: NodeInfo): Record =
x.enr
Expand All @@ -228,7 +229,7 @@ procSuite "Portal testnet tests":
await client.close()

for client in clients:
let routingTableInfo = await client.portal_history_routingTableInfo()
let routingTableInfo = await client.portal_historyRoutingTableInfo()
await client.close()
var start: seq[NodeId]
let nodes = foldl(routingTableInfo.buckets, a & b, start)
Expand All @@ -238,7 +239,7 @@ procSuite "Portal testnet tests":
let randomNodeInfo = sample(rng[], nodeInfos)
for client in clients:
var enr: Record
enr = await client.portal_history_lookupEnr(randomNodeInfo.nodeId)
enr = await client.portal_historyLookupEnr(randomNodeInfo.nodeId)
await client.close()
check enr == randomNodeInfo.enr

Expand Down Expand Up @@ -266,7 +267,7 @@ procSuite "Portal testnet tests":
# require them for validation.
for (content, contentKey) in blockHeadersWithProof:
discard
(await clients[0].portal_history_gossip(content.toHex(), contentKey.toHex()))
(await clients[0].portal_historyGossip(content.toHex(), contentKey.toHex()))

# This will fill the first node its db with blocks from the data file. Next,
# this node wil offer all these blocks their headers one by one.
Expand Down
8 changes: 4 additions & 4 deletions fluffy/tools/utp_testing/utp_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ procSuite "uTP network simulator tests":

proc findServerConnection(
connections: openArray[SKey], clientId: NodeId, clientConnectionId: uint16
): Option[Skey] =
): Option[SKey] =
let conns: seq[SKey] = connections.filter(
(key: Skey) => key.id == (clientConnectionId + 1) and key.nodeId == clientId
(key: SKey) => key.id == (clientConnectionId + 1) and key.nodeId == clientId
)
if len(conns) == 0:
none[Skey]()
none[SKey]()
else:
some[Skey](conns[0])
some[SKey](conns[0])

proc setupTest(): Future[(RpcHttpClient, NodeInfo, RpcHttpClient, NodeInfo)] {.async.} =
let client = newRpcHttpClient()
Expand Down
4 changes: 2 additions & 2 deletions fluffy/tools/utp_testing/utp_test_app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ proc installUtpHandlers(
let nodeAddress = NodeAddress.init(node).unsafeGet()
discard d.addNode(node)
let connResult = await s.connectTo(nodeAddress)
if (connresult.isOk()):
let socket = connresult.get()
if (connResult.isOk()):
let socket = connResult.get()
let sKey = socket.socketKey.toSKey()
t[sKey] = socket
return sKey
Expand Down

0 comments on commit d814d84

Please sign in to comment.