Skip to content

Commit 0150f68

Browse files
authored
Fixes nim v2.2.0 compilation errors (#80)
1 parent 46d17d2 commit 0150f68

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

ethers/providers/jsonrpc/conversions.nim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std/strformat
22
import std/strutils
33
import pkg/chronicles except fromJson, `%`, `%*`, toJson
4-
import pkg/json_rpc/jsonmarshal
4+
import pkg/json_rpc/jsonmarshal except toJson
55
import pkg/questionable/results
66
import pkg/serde
77
import pkg/stew/byteutils
@@ -10,7 +10,7 @@ import ../../transaction
1010
import ../../blocktag
1111
import ../../provider
1212

13-
export jsonmarshal
13+
export jsonmarshal except toJson
1414
export serde
1515
export chronicles except fromJson, `%`, `%*`, toJson
1616

@@ -90,12 +90,13 @@ func fromJson*(_: type BlockTag, json: JsonNode): ?!BlockTag =
9090
"' to BlockTag: must be one of 'earliest', 'latest', 'pending'")
9191

9292
# TransactionStatus | TransactionType
93+
type TransactionEnums = TransactionStatus | TransactionType
9394

94-
func `%`*(e: TransactionStatus | TransactionType): JsonNode =
95+
func `%`*(e: TransactionEnums): JsonNode =
9596
% ("0x" & e.int8.toHex(1))
9697

97-
proc fromJson*[E: TransactionStatus | TransactionType](
98-
T: type E,
98+
proc fromJson*(
99+
T: type TransactionEnums,
99100
json: JsonNode
100101
): ?!T =
101102
expectJsonKind(string, JString, json)

testmodule/providers/jsonrpc/testConversions.nim

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ suite "JSON Conversions":
4040
}
4141

4242
without blk =? Block.fromJson(blkJson["result"]):
43-
fail
43+
unittest.fail
4444
check blk.hash.isNone
4545

4646
test "missing block number in TransactionReceipt isNone":
@@ -71,12 +71,12 @@ suite "JSON Conversions":
7171
}
7272

7373
without receipt1 =? TransactionReceipt.fromJson(json):
74-
fail
74+
unittest.fail
7575
check receipt1.blockNumber.isNone
7676

7777
json["blockNumber"] = newJString("")
7878
without receipt2 =? TransactionReceipt.fromJson(json):
79-
fail
79+
unittest.fail
8080
check receipt2.blockNumber.isNone
8181

8282
test "missing block hash in TransactionReceipt isNone":
@@ -107,7 +107,7 @@ suite "JSON Conversions":
107107
}
108108

109109
without receipt =? TransactionReceipt.fromJson(json):
110-
fail
110+
unittest.fail
111111
check receipt.blockHash.isNone
112112

113113
test "correctly deserializes PastTransaction":
@@ -131,7 +131,7 @@ suite "JSON Conversions":
131131
}
132132

133133
without tx =? PastTransaction.fromJson(json):
134-
fail
134+
unittest.fail
135135
check tx.blockHash == BlockHash.fromHex("0x595bffbe897e025ea2df3213c4cc52c3f3d69bc04b49011d558f1b0e70038922")
136136
check tx.blockNumber == 0x22e.u256
137137
check tx.sender == Address.init("0xe00b677c29ff8d8fe6068530e2bc36158c54dd34").get
@@ -210,7 +210,7 @@ suite "JSON Conversions":
210210
}
211211

212212
without past =? PastTransaction.fromJson(json):
213-
fail
213+
unittest.fail
214214
check %past.toTransaction == %*{
215215
"to": !Address.init("0x92f09aa59dccb892a9f5406ddd9c0b98f02ea57e"),
216216
"data": hexToSeqByte("0x6368a471d26ff5c7f835c1a8203235e88846ce1a196d6e79df0eaedd1b8ed3deec2ae5c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000012a00000000000000000000000000000000000000000000000000000000000000"),
@@ -232,3 +232,23 @@ suite "JSON Conversions":
232232
let res = BlockTag.fromJson(newJString(""))
233233
check res.error of SerializationError
234234
check res.error.msg == "Failed to convert '\"\"' to BlockTag: must be one of 'earliest', 'latest', 'pending'"
235+
236+
test "correctly deserializes TransactionType":
237+
check !TransactionType.fromJson(newJString("0x0")) == TransactionType.Legacy
238+
check !TransactionType.fromJson(newJString("0x1")) == TransactionType.AccessList
239+
check !TransactionType.fromJson(newJString("0x2")) == TransactionType.Dynamic
240+
241+
test "correctly serializes TransactionType":
242+
check TransactionType.Legacy.toJson == "\"0x0\""
243+
check TransactionType.AccessList.toJson == "\"0x1\""
244+
check TransactionType.Dynamic.toJson == "\"0x2\""
245+
246+
test "correctly deserializes TransactionStatus":
247+
check !TransactionStatus.fromJson(newJString("0x0")) == TransactionStatus.Failure
248+
check !TransactionStatus.fromJson(newJString("0x1")) == TransactionStatus.Success
249+
check !TransactionStatus.fromJson(newJString("0x2")) == TransactionStatus.Invalid
250+
251+
test "correctly serializes TransactionStatus":
252+
check TransactionStatus.Failure.toJson == "\"0x0\""
253+
check TransactionStatus.Success.toJson == "\"0x1\""
254+
check TransactionStatus.Invalid.toJson == "\"0x2\""

0 commit comments

Comments
 (0)