-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix problem with contract out of assets * Add nully value json test * Fix bug with passing null to a few functions * Typesafe U256 parsing * Update readme for the web3 to include runner info * Cleanup commits Strip out unused JSON Update comment Remove echo Added DynamicBytes test More correct naming Remove one extra double check * Add specific object tests * Ensure we cover different status types * Add header comments * Cleanup * Add more tests * Cleanup * Revert docs * Nimpretty file * Fix issue in base stew * v0.2.4 * Fix test --------- Co-authored-by: jangko <[email protected]>
- Loading branch information
Showing
14 changed files
with
162 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ node_modules | |
nohup.out | ||
hardhat.config.js | ||
package-lock.json | ||
test_null_conversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
# NOTE: Requires nodemon (https://github.com/remy/nodemon) | ||
# npm i -g nodemon | ||
|
||
# Watch all nim files for changes | ||
# When a file change is detected we will restart ganache-cli | ||
# This ensures that our deposit contracts have enough ETH as | ||
# it seems like some of the tests do not properly initialise | ||
# their contracts at this time. (state persists across runs) | ||
|
||
nodemon --ext '.nim' --watch tests --watch web3 --exec "ganache-cli" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import | ||
std/[json, strutils], | ||
pkg/unittest2, | ||
stint, | ||
json_rpc/jsonmarshal, | ||
../web3, | ||
../web3/[conversions, eth_api_types, engine_api_types] | ||
|
||
template should_be_value_error(input: string, value: untyped): void = | ||
expect ValueError: | ||
fromJson(%input, "", value) | ||
|
||
template should_not_error(input: string, value: untyped): void = | ||
fromJson(%input, "", value) | ||
|
||
suite "Null conversion": | ||
var resAddress: Address | ||
var resDynamicBytes: DynamicBytes[32] | ||
var resFixedBytes: FixedBytes[5] | ||
var resQuantity: Quantity | ||
var resRlpEncodedBytes: RlpEncodedBytes | ||
var resTypedTransaction: TypedTransaction | ||
var resUInt256: UInt256 | ||
var resUInt256Ref: ref UInt256 | ||
|
||
## Covers the converters which can be found in web3/conversions.nim | ||
## Ensure that when passing a nully value they respond with a ValueError | ||
test "passing null values to normal convertors": | ||
should_be_value_error("null", resAddress) | ||
should_be_value_error("null", resDynamicBytes) | ||
should_be_value_error("null", resFixedBytes) | ||
should_be_value_error("null", resQuantity) | ||
should_be_value_error("null", resRlpEncodedBytes) | ||
should_be_value_error("null", resTypedTransaction) | ||
should_be_value_error("null", resUInt256) | ||
should_be_value_error("null", resUInt256Ref) | ||
|
||
test "passing empty values to normal convertors": | ||
should_be_value_error("", resAddress) | ||
should_be_value_error("", resDynamicBytes) | ||
should_be_value_error("", resFixedBytes) | ||
should_be_value_error("", resQuantity) | ||
should_be_value_error("", resRlpEncodedBytes) | ||
should_be_value_error("", resTypedTransaction) | ||
should_be_value_error("", resUInt256) | ||
should_be_value_error("", resUInt256Ref) | ||
|
||
test "passing invalid hex (0x) values to normal convertors": | ||
should_be_value_error("0x", resAddress) | ||
should_be_value_error("0x", resDynamicBytes) | ||
should_be_value_error("0x", resFixedBytes) | ||
should_be_value_error("0x", resQuantity) | ||
should_be_value_error("0x", resUInt256) | ||
should_be_value_error("0x", resUInt256Ref) | ||
|
||
test "passing hex (0x) values to normal convertors": | ||
should_not_error("0x", resRlpEncodedBytes) | ||
should_not_error("0x", resTypedTransaction) | ||
|
||
test "passing malformed hex (0x_) values to normal convertors": | ||
should_be_value_error("0x_", resAddress) | ||
should_be_value_error("0x_", resDynamicBytes) | ||
should_be_value_error("0x_", resFixedBytes) | ||
should_be_value_error("0x_", resQuantity) | ||
should_be_value_error("0x_", resRlpEncodedBytes) | ||
should_be_value_error("0x_", resTypedTransaction) | ||
should_be_value_error("0x_", resUInt256) | ||
should_be_value_error("0x_", resUInt256Ref) | ||
|
||
## Covering the web3/engine_api_types | ||
## | ||
## NOTE: These will be transformed by the fromJson imported from | ||
## nim-json-rpc/json_rpc/jsonmarshal | ||
test "passing nully values to specific convertors": | ||
|
||
let payloadAttributesV1 = """{ "timestamp": {item}, "prevRandao": {item}, "suggestedFeeRecipient": {item} }""" | ||
let forkchoiceStateV1 = """{ "status": {item}, "safeBlockHash": {item}, "finalizedBlockHash": {item} }""" | ||
let forkchoiceUpdatedResponse = """{ "payloadStatus": {item}, "payloadId": {item} }""" | ||
let transitionConfigurationV1 = """{ "terminalTotalDifficulty": {item}, "terminalBlockHash": {item}, "terminalBlockNumber": {item} }""" | ||
|
||
var resPayloadAttributesV1: PayloadAttributesV1 | ||
var resForkchoiceStateV1: ForkchoiceStateV1 | ||
var resForkchoiceUpdatedResponse: ForkchoiceUpdatedResponse | ||
var resTransitionConfigurationV1: TransitionConfigurationV1 | ||
|
||
for item in @["null", "\"\"", "\"0x\"", "\"0x_\"", ""]: | ||
template format(str: string): string = | ||
str.replace("{item}", item) | ||
|
||
should_be_value_error(payloadAttributesV1.format(), resPayloadAttributesV1) | ||
should_be_value_error(forkchoiceStateV1.format(), resForkchoiceStateV1) | ||
should_be_value_error(forkchoiceUpdatedResponse.format(), resForkchoiceUpdatedResponse) | ||
should_be_value_error(transitionConfigurationV1.format(), resTransitionConfigurationV1) | ||
|
||
|
||
## If different status types can have branching logic | ||
## we should cover each status type with different null ops | ||
test "passing nully values to specific status types": | ||
|
||
var resPayloadStatusV1: PayloadStatusV1 | ||
|
||
for status_type in PayloadExecutionStatus: | ||
let payloadStatusV1 = """{ | ||
"status": "status_name", | ||
"latestValidHash": null, | ||
"validationError": null | ||
}""".replace("status_name", $status_type) | ||
|
||
should_be_value_error(payloadStatusV1, resPayloadStatusV1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters