mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-05 23:23:08 +00:00
Merge branch 'main' into update-to-nim-2-x
This commit is contained in:
commit
1cfccb9695
@ -1,4 +1,5 @@
|
|||||||
import pkg/stint
|
import pkg/stint
|
||||||
|
import pkg/questionable
|
||||||
|
|
||||||
{.push raises:[].}
|
{.push raises:[].}
|
||||||
|
|
||||||
@ -41,3 +42,10 @@ func `==`*(a, b: BlockTag): bool =
|
|||||||
a.stringValue == b.stringValue
|
a.stringValue == b.stringValue
|
||||||
of numberBlockTag:
|
of numberBlockTag:
|
||||||
a.numberValue == b.numberValue
|
a.numberValue == b.numberValue
|
||||||
|
|
||||||
|
func number*(blockTag: BlockTag): ?UInt256 =
|
||||||
|
case blockTag.kind
|
||||||
|
of stringBlockTag:
|
||||||
|
UInt256.none
|
||||||
|
of numberBlockTag:
|
||||||
|
blockTag.numberValue.some
|
||||||
|
|||||||
@ -9,5 +9,6 @@ import ./testErc20
|
|||||||
import ./testGasEstimation
|
import ./testGasEstimation
|
||||||
import ./testErrorDecoding
|
import ./testErrorDecoding
|
||||||
import ./testCustomErrors
|
import ./testCustomErrors
|
||||||
|
import ./testBlockTag
|
||||||
|
|
||||||
{.warning[UnusedImport]:off.}
|
{.warning[UnusedImport]:off.}
|
||||||
|
|||||||
56
testmodule/testBlockTag.nim
Normal file
56
testmodule/testBlockTag.nim
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import std/unittest
|
||||||
|
import std/strformat
|
||||||
|
|
||||||
|
import pkg/stint
|
||||||
|
import pkg/questionable
|
||||||
|
|
||||||
|
import ethers/blocktag
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
PredefinedTags = enum earliest, latest, pending
|
||||||
|
|
||||||
|
suite "BlockTag":
|
||||||
|
for predefinedTag in PredefinedTags:
|
||||||
|
test fmt"can be created with predefined special type: {predefinedTag}":
|
||||||
|
var blockTag: BlockTag
|
||||||
|
case predefinedTag:
|
||||||
|
of earliest: blockTag = BlockTag.earliest
|
||||||
|
of latest: blockTag = BlockTag.latest
|
||||||
|
of pending: blockTag = BlockTag.pending
|
||||||
|
check $blockTag == $predefinedTag
|
||||||
|
|
||||||
|
test "can be created with a number":
|
||||||
|
let blockTag = BlockTag.init(42.u256)
|
||||||
|
check blockTag.number == 42.u256.some
|
||||||
|
|
||||||
|
test "can be converted to string in hex format for BlockTags with number":
|
||||||
|
let blockTag = BlockTag.init(42.u256)
|
||||||
|
check $blockTag == "0x2a"
|
||||||
|
|
||||||
|
test "can be compared for equality when BlockTag with number":
|
||||||
|
let blockTag1 = BlockTag.init(42.u256)
|
||||||
|
let blockTag2 = BlockTag.init(42.u256)
|
||||||
|
let blockTag3 = BlockTag.init(43.u256)
|
||||||
|
check blockTag1 == blockTag2
|
||||||
|
check blockTag1 != blockTag3
|
||||||
|
|
||||||
|
for predefinedTag in [BlockTag.earliest, BlockTag.latest, BlockTag.pending]:
|
||||||
|
test fmt"can be compared for equality when predefined tag: {predefinedTag}":
|
||||||
|
case $predefinedTag:
|
||||||
|
of "earliest":
|
||||||
|
check predefinedTag == BlockTag.earliest
|
||||||
|
check predefinedTag != BlockTag.latest
|
||||||
|
check predefinedTag != BlockTag.pending
|
||||||
|
of "latest":
|
||||||
|
check predefinedTag != BlockTag.earliest
|
||||||
|
check predefinedTag == BlockTag.latest
|
||||||
|
check predefinedTag != BlockTag.pending
|
||||||
|
of "pending":
|
||||||
|
check predefinedTag != BlockTag.earliest
|
||||||
|
check predefinedTag != BlockTag.latest
|
||||||
|
check predefinedTag == BlockTag.pending
|
||||||
|
|
||||||
|
for predefinedTag in [BlockTag.earliest, BlockTag.latest, BlockTag.pending]:
|
||||||
|
test fmt"number accessor returns None for BlockTags with string: {predefinedTag}":
|
||||||
|
check predefinedTag.number == UInt256.none
|
||||||
Loading…
x
Reference in New Issue
Block a user