Skip to content

Commit

Permalink
Reduce compiler warnings when using Nim v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jan 2, 2024
1 parent 23c06ca commit be1bb30
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 0 additions & 3 deletions tests/helpers/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import
../../web3/primitives

proc deployContract*(web3: Web3, code: string, gasPrice = 0): Future[ReceiptObject] {.async.} =
let provider = web3.provider
let accounts = await provider.eth_accounts()

var code = code
var tr: EthSend
tr.`from` = web3.defaultAccount
Expand Down
11 changes: 7 additions & 4 deletions tests/test_contracts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ suite "Contracts":
fromAddr, toAddr: Address, value: UInt256)
{.raises: [], gcsafe.}:
try:
echo "onTransfer: ", fromAddr, " transferred ", value, " to ", toAddr
echo "onTransfer: ", fromAddr, " transferred ", value.toHex, " to ", toAddr
inc notificationsReceived
assert(fromAddr == web3.defaultAccount)
assert((notificationsReceived == 1 and value == 50.u256) or
Expand All @@ -222,12 +222,15 @@ suite "Contracts":
# chronos still raises exceptions which inherit directly from Exception
doAssert false, err.msg

echo "getbalance (now): ", await ns.getBalance(web3.defaultAccount).call()
echo "getbalance (after creation): ", await ns.getBalance(web3.defaultAccount).call(blockNumber = deployedAtBlock)
let balNow = await ns.getBalance(web3.defaultAccount).call()
echo "getbalance (now): ", balNow.toHex
let balNew = await ns.getBalance(web3.defaultAccount).call(blockNumber = deployedAtBlock)
echo "getbalance (after creation): ", balNew.toHex

# Let's try to get the balance at a point in time where the contract was not deployed yet:
try:
echo "getbalance (first block): ", await ns.getBalance(web3.defaultAccount).call(blockNumber = 1'u64)
let balFirst = await ns.getBalance(web3.defaultAccount).call(blockNumber = 1'u64)
echo "getbalance (first block): ", balFirst.toHex
except CatchableError as err:
echo "getbalance (first block): ", err.msg

Expand Down
2 changes: 1 addition & 1 deletion tests/test_logs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ suite "Logs":
sender: Address, value: UInt256)
{.raises: [], gcsafe.}:
try:
echo "onEvent: ", sender, " value ", value
echo "onEvent: ", sender, " value ", value.toHex
inc notificationsReceived

if notificationsReceived == invocationsBefore + invocationsAfter:
Expand Down
4 changes: 2 additions & 2 deletions web3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ proc unsubscribe*(s: Subscription): Future[void] {.async.} =
discard await s.web3.provider.eth_unsubscribe(s.id)

proc getJsonLogs(s: Web3SenderImpl, topic: openarray[byte],
fromBlock, toBlock = none(RtBlockIdentifier),
fromBlock = none(RtBlockIdentifier), toBlock = none(RtBlockIdentifier),
blockHash = none(BlockHash)): Future[JsonNode] =
var options = newJObject()
options["address"] = %s.contractAddress
Expand All @@ -216,7 +216,7 @@ proc getJsonLogs(s: Web3SenderImpl, topic: openarray[byte],

proc getJsonLogs*[TContract](s: Sender[TContract],
EventName: type,
fromBlock, toBlock = none(RtBlockIdentifier),
fromBlock= none(RtBlockIdentifier), toBlock = none(RtBlockIdentifier),
blockHash = none(BlockHash)): Future[JsonNode] {.inline.} =
mixin eventTopic
getJsonLogs(s.sender, eventTopic(EventName))
Expand Down
3 changes: 2 additions & 1 deletion web3.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ license = "MIT or Apache License 2.0"
### Dependencies
requires "nim >= 1.6.0"
requires "chronicles"
requires "chronos"
requires "chronos#head"
requires "bearssl#head"
requires "eth"
requires "faststreams"
requires "json_rpc"
Expand Down
4 changes: 2 additions & 2 deletions web3/contract_dsl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ macro contract*(cname: untyped, body: untyped): untyped =
options: JsonNode,
`callbackIdent`: `procTy`,
errorHandler: SubscriptionErrorHandler,
withHistoricEvents = true): Future[Subscription] =
withHistoricEvents = true): Future[Subscription] {.used.} =
proc eventHandler(`jsonIdent`: JsonNode) {.gcsafe, raises: [].} =
try:
`argParseBody`
Expand All @@ -310,7 +310,7 @@ macro contract*(cname: untyped, body: untyped): untyped =
options: JsonNode,
`callbackIdent`: `procTyWithRawData`,
errorHandler: SubscriptionErrorHandler,
withHistoricEvents = true): Future[Subscription] =
withHistoricEvents = true): Future[Subscription] {.used.} =
proc eventHandler(`jsonIdent`: JsonNode) {.gcsafe, raises: [].} =
try:
`argParseBody`
Expand Down

0 comments on commit be1bb30

Please sign in to comment.