-
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.
- Loading branch information
Showing
34 changed files
with
1,536 additions
and
692 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
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,4 @@ | ||
# begin Nimble config (version 1) | ||
when fileExists("nimble.paths"): | ||
include "nimble.paths" | ||
# end Nimble config |
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
# web3 | ||
# Copyright (c) 2018-2022 Status Research & Development GmbH | ||
# Licensed and distributed under either of | ||
# * MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT | ||
# * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
# at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
# nim-web3 | ||
# Copyright (c) 2018-2023 Status Research & Development GmbH | ||
# Licensed under either of | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
# * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
# at your option. | ||
# This file may not be copied, modified, or distributed except according to | ||
# those terms. | ||
|
||
{. warning[UnusedImport]:off .} | ||
|
||
import | ||
test, | ||
test_primitives, | ||
test_contracts, | ||
test_deposit_contract, | ||
test_ethhexstrings, | ||
test_logs, | ||
test_json_marshalling, | ||
test_signed_tx | ||
test_signed_tx, | ||
test_execution_types |
File renamed without changes.
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,47 @@ | ||
import | ||
std/options, | ||
chronos, stint, | ||
stew/byteutils, | ||
../../web3, | ||
../../web3/primitives | ||
|
||
proc deployContract*(web3: Web3, code: string, gasPrice = 0): Future[ReceiptObject] {.async.} = | ||
let provider = web3.provider | ||
let accounts = await provider.eth_accounts() | ||
|
||
var code = code | ||
var tr: EthSend | ||
tr.`from` = web3.defaultAccount | ||
tr.data = hexToSeqByte(code) | ||
tr.gas = Quantity(3000000).some | ||
if gasPrice != 0: | ||
tr.gasPrice = some(gasPrice.Quantity) | ||
|
||
let r = await web3.send(tr) | ||
return await web3.getMinedTransactionReceipt(r) | ||
|
||
func ethToWei*(eth: UInt256): UInt256 = | ||
eth * 1000000000000000000.u256 | ||
|
||
type | ||
BlobData* = DynamicBytes[0, 512] | ||
|
||
func conv*(T: type, x: int): T = | ||
type BaseType = distinctBase T | ||
var res: BaseType | ||
when BaseType is seq: | ||
res.setLen(1) | ||
res[^1] = x.byte | ||
T(res) | ||
|
||
func address*(x: int): Address = | ||
conv(typeof result, x) | ||
|
||
func txhash*(x: int): TxHash = | ||
conv(typeof result, x) | ||
|
||
func blob*(x: int): BlobData = | ||
conv(typeof result, x) | ||
|
||
func h256*(x: int): Hash256 = | ||
conv(typeof result, x) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# nim-web3 | ||
# Copyright (c) 2018-2023 Status Research & Development GmbH | ||
# Licensed under either of | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
# * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
# at your option. | ||
# This file may not be copied, modified, or distributed except according to | ||
# those terms. | ||
|
||
import | ||
std/typetraits, | ||
pkg/unittest2, | ||
stew/byteutils, | ||
../web3/execution_types, | ||
./helpers/utils | ||
|
||
suite "Execution types tests": | ||
let | ||
wd = WithdrawalV1( | ||
index: 1.Quantity, | ||
validatorIndex: 2.Quantity, | ||
address: address(3), | ||
amount: 4.Quantity, | ||
) | ||
|
||
payload = ExecutionPayload( | ||
parentHash: h256(1), | ||
feeRecipient: address(2), | ||
stateRoot: h256(3), | ||
receiptsRoot: h256(4), | ||
logsBloom: FixedBytes[256].conv(5), | ||
prevRandao: h256(6), | ||
blockNumber: 7.Quantity, | ||
gasLimit: 8.Quantity, | ||
gasUsed: 9.Quantity, | ||
timestamp: 10.Quantity, | ||
extraData: DynamicBytes[0, 32].conv(11), | ||
baseFeePerGas: 12.u256, | ||
blockHash: h256(13), | ||
transactions: @[TypedTransaction.conv(14)], | ||
withdrawals: some(@[wd]), | ||
blobGasUsed: some(15.Quantity), | ||
excessBlobGas: some(16.Quantity), | ||
) | ||
|
||
attr = PayloadAttributes( | ||
timestamp: 1.Quantity, | ||
prevRandao: h256(2), | ||
suggestedFeeRecipient: address(3), | ||
withdrawals: some(@[wd]), | ||
parentBeaconBlockRoot: some(h256(4)), | ||
) | ||
|
||
blobs = BlobsBundleV1( | ||
commitments: @[KZGCommitment.conv(1)], | ||
proofs: @[KZGProof.conv(2)], | ||
blobs: @[Blob.conv(3)], | ||
) | ||
|
||
response = GetPayloadResponse( | ||
executionPayload: payload, | ||
blockValue: some(1.u256), | ||
blobsBundle: some(blobs), | ||
shouldOverrideBuilder: some(false), | ||
) | ||
|
||
test "payload version": | ||
var badv31 = payload | ||
badv31.excessBlobGas = none(Quantity) | ||
var badv32 = payload | ||
badv32.blobGasUsed = none(Quantity) | ||
var v2 = payload | ||
v2.excessBlobGas = none(Quantity) | ||
v2.blobGasUsed = none(Quantity) | ||
var v1 = v2 | ||
v1.withdrawals = none(seq[WithdrawalV1]) | ||
check badv31.version == Version.V2 | ||
check badv32.version == Version.V2 | ||
check v2.version == Version.V2 | ||
check v1.version == Version.V1 | ||
check payload.version == Version.V3 | ||
|
||
test "attr version": | ||
var v2 = attr | ||
v2.parentBeaconBlockRoot = none(Hash256) | ||
var v1 = v2 | ||
v1.withdrawals = none(seq[WithdrawalV1]) | ||
check attr.version == Version.V3 | ||
check v2.version == Version.V2 | ||
check v1.version == Version.V1 | ||
|
||
test "response version": | ||
var badv31 = response | ||
badv31.blobsBundle = none(BlobsBundleV1) | ||
var badv32 = response | ||
badv32.shouldOverrideBuilder = none(bool) | ||
var v2 = response | ||
v2.blobsBundle = none(BlobsBundleV1) | ||
v2.shouldOverrideBuilder = none(bool) | ||
var v1 = v2 | ||
v1.blockValue = none(UInt256) | ||
check badv31.version == Version.V2 | ||
check badv32.version == Version.V2 | ||
check v2.version == Version.V2 | ||
check v1.version == Version.V1 | ||
check response.version == Version.V3 | ||
|
||
test "ExecutionPayload roundtrip": | ||
let v3 = payload.V3 | ||
check v3 == v3.executionPayload.V3 | ||
|
||
let v2 = payload.V2 | ||
check v2 == v2.executionPayload.V2 | ||
|
||
let v1 = payload.V1 | ||
check v1 == v1.executionPayload.V1 | ||
|
||
test "PayloadAttributes roundtrip": | ||
let v3 = attr.V3 | ||
check v3 == v3.payloadAttributes.V3 | ||
|
||
let v2 = attr.V2 | ||
check v2 == v2.payloadAttributes.V2 | ||
|
||
let v1 = attr.V1 | ||
check v1 == v1.payloadAttributes.V1 | ||
|
||
test "GetPayloadResponse roundtrip": | ||
let v3 = response.V3 | ||
check v3 == v3.getPayloadResponse.V3 | ||
|
||
let v2 = response.V2 | ||
check v2 == v2.getPayloadResponse.V2 | ||
|
||
let v1 = response.V1 | ||
check v1 == v1.getPayloadResponse.V1 | ||
|
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
Oops, something went wrong.