From 53e596e75a0f79fb1971847cb73a3be90b909733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Tue, 22 Oct 2024 10:39:11 +0200 Subject: [PATCH] fix: pinning nim-eth dependency (#77) Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- .gitignore | 1 + ethers.nimble | 2 +- ethers/providers/jsonrpc/conversions.nim | 11 ++++--- .../providers/jsonrpc/testConversions.nim | 32 +++++++++++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6d279d..9020fc4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - nim: [1.6.16, stable] + nim: [1.6.20, stable] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 37a40a8..57dfc22 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ nimble.develop nimble.paths .idea +.nimble diff --git a/ethers.nimble b/ethers.nimble index 819577c..8e2be56 100644 --- a/ethers.nimble +++ b/ethers.nimble @@ -12,7 +12,7 @@ requires "json_rpc >= 0.4.0 & < 0.5.0" requires "serde >= 1.2.1 & < 1.3.0" requires "stint" requires "stew" -requires "eth" +requires "eth#c482b4c5b658a77cc96b49d4a397aa6d98472ac7" task test, "Run the test suite": exec "nimble install -d -y" diff --git a/ethers/providers/jsonrpc/conversions.nim b/ethers/providers/jsonrpc/conversions.nim index f1476fb..e8ad484 100644 --- a/ethers/providers/jsonrpc/conversions.nim +++ b/ethers/providers/jsonrpc/conversions.nim @@ -1,7 +1,7 @@ import std/strformat import std/strutils import pkg/chronicles except fromJson, `%`, `%*`, toJson -import pkg/json_rpc/jsonmarshal +import pkg/json_rpc/jsonmarshal except toJson import pkg/questionable/results import pkg/serde import pkg/stew/byteutils @@ -10,7 +10,7 @@ import ../../transaction import ../../blocktag import ../../provider -export jsonmarshal +export jsonmarshal except toJson export serde export chronicles except fromJson, `%`, `%*`, toJson @@ -90,12 +90,13 @@ func fromJson*(_: type BlockTag, json: JsonNode): ?!BlockTag = "' to BlockTag: must be one of 'earliest', 'latest', 'pending'") # TransactionStatus | TransactionType +type TransactionEnums = TransactionStatus | TransactionType -func `%`*(e: TransactionStatus | TransactionType): JsonNode = +func `%`*(e: TransactionEnums): JsonNode = % ("0x" & e.int8.toHex(1)) -proc fromJson*[E: TransactionStatus | TransactionType]( - T: type E, +proc fromJson*( + T: type TransactionEnums, json: JsonNode ): ?!T = expectJsonKind(string, JString, json) diff --git a/testmodule/providers/jsonrpc/testConversions.nim b/testmodule/providers/jsonrpc/testConversions.nim index 6017e04..b47c42c 100644 --- a/testmodule/providers/jsonrpc/testConversions.nim +++ b/testmodule/providers/jsonrpc/testConversions.nim @@ -40,7 +40,7 @@ suite "JSON Conversions": } without blk =? Block.fromJson(blkJson["result"]): - fail + unittest.fail check blk.hash.isNone test "missing block number in TransactionReceipt isNone": @@ -71,12 +71,12 @@ suite "JSON Conversions": } without receipt1 =? TransactionReceipt.fromJson(json): - fail + unittest.fail check receipt1.blockNumber.isNone json["blockNumber"] = newJString("") without receipt2 =? TransactionReceipt.fromJson(json): - fail + unittest.fail check receipt2.blockNumber.isNone test "missing block hash in TransactionReceipt isNone": @@ -107,7 +107,7 @@ suite "JSON Conversions": } without receipt =? TransactionReceipt.fromJson(json): - fail + unittest.fail check receipt.blockHash.isNone test "correctly deserializes PastTransaction": @@ -131,7 +131,7 @@ suite "JSON Conversions": } without tx =? PastTransaction.fromJson(json): - fail + unittest.fail check tx.blockHash == BlockHash.fromHex("0x595bffbe897e025ea2df3213c4cc52c3f3d69bc04b49011d558f1b0e70038922") check tx.blockNumber == 0x22e.u256 check tx.sender == Address.init("0xe00b677c29ff8d8fe6068530e2bc36158c54dd34").get @@ -210,7 +210,7 @@ suite "JSON Conversions": } without past =? PastTransaction.fromJson(json): - fail + unittest.fail check %past.toTransaction == %*{ "to": !Address.init("0x92f09aa59dccb892a9f5406ddd9c0b98f02ea57e"), "data": hexToSeqByte("0x6368a471d26ff5c7f835c1a8203235e88846ce1a196d6e79df0eaedd1b8ed3deec2ae5c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000012a00000000000000000000000000000000000000000000000000000000000000"), @@ -232,3 +232,23 @@ suite "JSON Conversions": let res = BlockTag.fromJson(newJString("")) check res.error of SerializationError check res.error.msg == "Failed to convert '\"\"' to BlockTag: must be one of 'earliest', 'latest', 'pending'" + + test "correctly deserializes TransactionType": + check !TransactionType.fromJson(newJString("0x0")) == TransactionType.Legacy + check !TransactionType.fromJson(newJString("0x1")) == TransactionType.AccessList + check !TransactionType.fromJson(newJString("0x2")) == TransactionType.Dynamic + + test "correctly serializes TransactionType": + check TransactionType.Legacy.toJson == "\"0x0\"" + check TransactionType.AccessList.toJson == "\"0x1\"" + check TransactionType.Dynamic.toJson == "\"0x2\"" + + test "correctly deserializes TransactionStatus": + check !TransactionStatus.fromJson(newJString("0x0")) == TransactionStatus.Failure + check !TransactionStatus.fromJson(newJString("0x1")) == TransactionStatus.Success + check !TransactionStatus.fromJson(newJString("0x2")) == TransactionStatus.Invalid + + test "correctly serializes TransactionStatus": + check TransactionStatus.Failure.toJson == "\"0x0\"" + check TransactionStatus.Success.toJson == "\"0x1\"" + check TransactionStatus.Invalid.toJson == "\"0x2\""