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

fix: pinning nim-eth dependency #77

Merged
merged 3 commits into from
Oct 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
nimble.develop
nimble.paths
.idea
.nimble
2 changes: 1 addition & 1 deletion ethers.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions ethers/providers/jsonrpc/conversions.nim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +10,7 @@ import ../../transaction
import ../../blocktag
import ../../provider

export jsonmarshal
export jsonmarshal except toJson
export serde
export chronicles except fromJson, `%`, `%*`, toJson

Expand Down Expand Up @@ -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)
Expand Down
32 changes: 26 additions & 6 deletions testmodule/providers/jsonrpc/testConversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -107,7 +107,7 @@ suite "JSON Conversions":
}

without receipt =? TransactionReceipt.fromJson(json):
fail
unittest.fail
check receipt.blockHash.isNone

test "correctly deserializes PastTransaction":
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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\""
Loading