From 2e3d22b9e28d2e26b0ffb6462e5a63dd3856decb Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 8 Apr 2022 10:25:41 +0200 Subject: [PATCH] enable `styleCheck:usages` (#135) --- json_rpc.nimble | 8 +++++++- json_rpc/client.nim | 2 +- json_rpc/clients/websocketclient.nim | 2 +- json_rpc/jsonmarshal.nim | 4 ++-- tests/ethprocs.nim | 2 +- tests/ethtypes.nim | 10 +++++----- tests/testethcalls.nim | 2 +- tests/testrpcmacro.nim | 22 +++++++++++----------- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/json_rpc.nimble b/json_rpc.nimble index 4488987..432d4c6 100644 --- a/json_rpc.nimble +++ b/json_rpc.nimble @@ -20,7 +20,13 @@ requires "nim >= 1.2.0", proc buildBinary(name: string, srcDir = "./", params = "", cmdParams = "") = if not dirExists "build": mkDir "build" - exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " -r -f --skipUserCfg:on --skipParentCfg:on --verbosity:0 --hints:off --debuginfo --path:'.' --threads:on -d:chronicles_log_level=ERROR --out:./build/" & name & " " & params & " " & srcDir & name & ".nim" & " " & cmdParams + exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & + " -r -f --skipUserCfg:on --skipParentCfg:on --verbosity:0" & + " --debuginfo --path:'.' --threads:on -d:chronicles_log_level=ERROR" & + " --styleCheck:usages --styleCheck:hint" & + " --hint[XDeclaredButNotUsed]:off --hint[Processing]:off " & + " --out:./build/" & name & " " & params & " " & srcDir & name & ".nim" & + " " & cmdParams task test, "run tests": buildBinary "all", "tests/", diff --git a/json_rpc/client.nim b/json_rpc/client.nim index 575a5fd..54246ff 100644 --- a/json_rpc/client.nim +++ b/json_rpc/client.nim @@ -87,7 +87,7 @@ proc createRpcProc(procName, parameters, callBody: NimNode): NimNode = # make proc async result.addPragma ident"async" # export this proc - result[0] = nnkPostFix.newTree(ident"*", newIdentNode($procName)) + result[0] = nnkPostfix.newTree(ident"*", newIdentNode($procName)) proc toJsonArray(parameters: NimNode): NimNode = # outputs an array of jsonified parameters diff --git a/json_rpc/clients/websocketclient.nim b/json_rpc/clients/websocketclient.nim index 34539cf..9cbecc0 100644 --- a/json_rpc/clients/websocketclient.nim +++ b/json_rpc/clients/websocketclient.nim @@ -79,7 +79,7 @@ proc processData(client: RpcWebSocketClient) {.async.} = else: let ws = client.transport try: - while ws.readystate != ReadyState.Closed: + while ws.readyState != ReadyState.Closed: var value = await ws.recvMsg() if value.len == 0: diff --git a/json_rpc/jsonmarshal.nim b/json_rpc/jsonmarshal.nim index 5e602d6..28a7cbb 100644 --- a/json_rpc/jsonmarshal.nim +++ b/json_rpc/jsonmarshal.nim @@ -69,7 +69,7 @@ proc fromJson*(n: JsonNode, argName: string, result: var int) = proc fromJson*[T: ref object](n: JsonNode, argName: string, result: var T) = n.kind.expect(JObject, argName) result = new T - for k, v in fieldpairs(result[]): + for k, v in fieldPairs(result[]): fromJson(n[k], k, v) proc fromJson*(n: JsonNode, argName: string, result: var int64) = @@ -165,7 +165,7 @@ iterator paramsIter(params: NimNode): tuple[name, ntype: NimNode] = yield (arg[j], argType) iterator paramsRevIter(params: NimNode): tuple[name, ntype: NimNode] = - for i in countDown(params.len-1,1): + for i in countdown(params.len-1,1): let arg = params[i] let argType = arg[^2] for j in 0 ..< arg.len-2: diff --git a/tests/ethprocs.nim b/tests/ethprocs.nim index 7817da1..8202b91 100644 --- a/tests/ethprocs.nim +++ b/tests/ethprocs.nim @@ -43,7 +43,7 @@ proc addEthRpcs*(server: RpcServer) = var rawData: seq[byte] rawData = nimcrypto.fromHex(data.string) # data will have 0x prefix - result = hexDataStr "0x" & $keccak_256.digest(rawData) + result = hexDataStr "0x" & $keccak256.digest(rawData) server.rpc("net_version") do() -> string: ## Returns string of the current network id: diff --git a/tests/ethtypes.nim b/tests/ethtypes.nim index beabdce..303ddcc 100644 --- a/tests/ethtypes.nim +++ b/tests/ethtypes.nim @@ -13,9 +13,9 @@ type gasPrice*: int # (optional, default: To-Be-Determined) integer of the gasPrice used for each paid gas. value*: int # (optional) integer of the value sent with this transaction. data*: int # the compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Ethereum Contract ABI. - nonce*: int # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce + nonce*: int # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce - EthCall* = object + EthCall* = object source*: array[20, byte] # (optional) The address the transaction is send from. to*: array[20, byte] # The address the transaction is directed to. gas*: int # (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions. @@ -42,8 +42,8 @@ type gasLimit*: int # the maximum gas allowed in this block. gasUsed*: int # the total used gas by all transactions in this block. timestamp*: int # the unix timestamp for when the block was collated. - transactions*: seq[Uint256] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. - uncles*: seq[Uint256] # list of uncle hashes. + transactions*: seq[UInt256] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. + uncles*: seq[UInt256] # list of uncle hashes. TransactionObject* = object # A transaction object, or null when no transaction was found: hash*: UInt256 # hash of the transaction. @@ -70,7 +70,7 @@ type contractAddress*: array[20, byte] # the contract address created, if the transaction was a contract creation, otherwise null. logs*: seq[string] # TODO: See Wiki for details. list of log objects, which this transaction generated. logsBloom*: array[256, byte] # bloom filter for light clients to quickly retrieve related logs. - # TODO: + # TODO: #case kind*: ReceiptKind #of rkRoot: root*: UInt256 # post-transaction stateroot (pre Byzantium). #of rkStatus: status*: int # 1 = success, 0 = failure. diff --git a/tests/testethcalls.nim b/tests/testethcalls.nim index f68c49a..ed9acd6 100644 --- a/tests/testethcalls.nim +++ b/tests/testethcalls.nim @@ -22,7 +22,7 @@ func rpcDynamicName(name: string): string = ## Create custom RPC with StUint input parameter server.rpc(rpcDynamicName "uint256Param") do(i: UInt256): - let r = i + 1.stUint(256) + let r = i + 1.stuint(256) return %r ## Create custom RPC with StUInt return parameter diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index 543a906..b77c625 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -153,39 +153,39 @@ suite "Server types": check r == inp test "Array parameters": - let r1 = waitfor s.executeMethod("rpc.arrayParam", %[%[1, 2, 3], %"hello"]) + let r1 = waitFor s.executeMethod("rpc.arrayParam", %[%[1, 2, 3], %"hello"]) var ckR1 = %[1, 2, 3, 0, 0, 0] ckR1.elems.add %"hello" check r1 == ckR1 test "Seq parameters": - let r2 = waitfor s.executeMethod("rpc.seqParam", %[%"abc", %[1, 2, 3, 4, 5]]) + let r2 = waitFor s.executeMethod("rpc.seqParam", %[%"abc", %[1, 2, 3, 4, 5]]) var ckR2 = %["abc"] for i in 0..4: ckR2.add %(i + 1) check r2 == ckR2 test "Object parameters": - let r = waitfor s.executeMethod("rpc.objParam", %[%"abc", testObj]) + let r = waitFor s.executeMethod("rpc.objParam", %[%"abc", testObj]) check r == testObj test "Simple return types": let inp = %99 - r1 = waitfor s.executeMethod("rpc.returnTypeSimple", %[%inp]) + r1 = waitFor s.executeMethod("rpc.returnTypeSimple", %[%inp]) check r1 == inp test "Complex return types": let inp = 99 - r1 = waitfor s.executeMethod("rpc.returnTypeComplex", %[%inp]) + r1 = waitFor s.executeMethod("rpc.returnTypeComplex", %[%inp]) check r1 == %*{"x": %[1, inp, 3], "y": "test"} test "Option types": let inp1 = MyOptional(maybeInt: some(75)) inp2 = MyOptional() - r1 = waitfor s.executeMethod("rpc.optional", %[%inp1]) - r2 = waitfor s.executeMethod("rpc.optional", %[%inp2]) + r1 = waitFor s.executeMethod("rpc.optional", %[%inp1]) + r2 = waitFor s.executeMethod("rpc.optional", %[%inp2]) check r1 == %inp1 check r2 == %inp2 @@ -196,19 +196,19 @@ suite "Server types": test "Runtime errors": expect ValueError: # root param not array - discard waitfor s.executeMethod("rpc.arrayParam", %"test") + discard waitFor s.executeMethod("rpc.arrayParam", %"test") expect ValueError: # too big for array - discard waitfor s.executeMethod("rpc.arrayParam", %[%[0, 1, 2, 3, 4, 5, 6], %"hello"]) + discard waitFor s.executeMethod("rpc.arrayParam", %[%[0, 1, 2, 3, 4, 5, 6], %"hello"]) expect ValueError: # wrong sub parameter type - discard waitfor s.executeMethod("rpc.arrayParam", %[%"test", %"hello"]) + discard waitFor s.executeMethod("rpc.arrayParam", %[%"test", %"hello"]) expect ValueError: # wrong param type discard waitFor s.executeMethod("rpc.differentParams", %[%"abc", %1]) test "Multiple variables of one type": - let r = waitfor s.executeMethod("rpc.multiVarsOfOneType", %[%"hello", %"world"]) + let r = waitFor s.executeMethod("rpc.multiVarsOfOneType", %[%"hello", %"world"]) check r == %"hello world" test "Optional arg":