Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce compiler warnings when using Nim v2 #111

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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