From fd8b5de13ce4b3c7cdb9365e703296f1f92b97b2 Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 15 Jul 2020 09:20:24 +0700 Subject: [PATCH 1/4] fix test_signed_tx --- tests/test_rng.nim | 6 ++++++ tests/test_signed_tx.nim | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 tests/test_rng.nim diff --git a/tests/test_rng.nim b/tests/test_rng.nim new file mode 100644 index 0000000..0f522fb --- /dev/null +++ b/tests/test_rng.nim @@ -0,0 +1,6 @@ +import eth/keys + +# You should only create one instance of the RNG per application / library +# Ref is used so that it can be shared between components + +let theRNG* = newRng() diff --git a/tests/test_signed_tx.nim b/tests/test_signed_tx.nim index 0300ad6..4555f94 100644 --- a/tests/test_signed_tx.nim +++ b/tests/test_signed_tx.nim @@ -1,6 +1,6 @@ import ../web3 import chronos, options, json, stint, eth/keys -import test_utils +import test_utils, test_rng #[ Contract NumberStorage @@ -24,13 +24,12 @@ contract(NumberStorage): const NumberStorageCode = "6060604052341561000f57600080fd5b60bb8061001d6000396000f30060606040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fb5c1cb8114604d578063f2c9ecd8146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b60726089565b60405190815260200160405180910390f35b600055565b600054905600a165627a7a7230582023e722f35009f12d5698a4ab22fb9d55a6c0f479fc43875c65be46fbdd8db4310029" - proc test() {.async.} = let web3 = await newWeb3("ws://127.0.0.1:8545") let accounts = await web3.provider.eth_accounts() web3.defaultAccount = accounts[0] - let pk = PrivateKEy.random()[] + let pk = PrivateKey.random(theRNG[]) let acc = Address(toCanonicalAddress(pk.toPublicKey())) var tx: EthSend From b29311a9d08c87f873847b5be19c436cebc330f8 Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 15 Jul 2020 10:03:36 +0700 Subject: [PATCH 2/4] silence spurious warnings --- nim.cfg | 4 ++++ tests/all_tests.nim | 2 ++ tests/test_logs.nim | 8 ++++---- web3.nim | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 nim.cfg diff --git a/nim.cfg b/nim.cfg new file mode 100644 index 0000000..f8e9c30 --- /dev/null +++ b/nim.cfg @@ -0,0 +1,4 @@ +# nim.cfg +@if nimHasWarningObservableStores: + warning[ObservableStores]: off +@end diff --git a/tests/all_tests.nim b/tests/all_tests.nim index c06635d..8a6dc3f 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -5,6 +5,8 @@ # * 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. +{. warning[UnusedImport]:off .} + import test, test_deposit_contract, diff --git a/tests/test_logs.nim b/tests/test_logs.nim index 55185da..36b42d2 100644 --- a/tests/test_logs.nim +++ b/tests/test_logs.nim @@ -8,11 +8,11 @@ import random pragma solidity >=0.4.25 <0.6.0; contract LoggerContract { - + uint fNum; - + event MyEvent(address sender, uint value); - + function invoke(uint value) public { emit MyEvent(msg.sender, value); @@ -56,7 +56,7 @@ proc test() {.async.} = # Now that we have invoked the function `invocationsBefore` let's wait for the transactions to # settle and see if we receive the logs after subscription. Note in ganache transactions are # processed immediately. With a real eth client we would need to wait for transactions to settle - + await sleepAsync(3.seconds) let notifFut = newFuture[void]() diff --git a/web3.nim b/web3.nim index b9c7137..4365233 100644 --- a/web3.nim +++ b/web3.nim @@ -44,7 +44,7 @@ type historicalEventsProcessed: bool removed: bool - ContractCallBase = object {.pure, inheritable.} + ContractCallBase {.pure, inheritable.} = object web3: Web3 data: string to: Address @@ -220,10 +220,10 @@ func encode*[N](x: DynamicBytes[N]): EncodeResult {.inline.} = func decodeDynamic(input: string, offset: int, to: var openarray[byte]): int = var dataOffset, dataLen: UInt256 result = decode(input, offset, dataOffset) - discard decode(input, dataOffset.toInt * 2, dataLen) + discard decode(input, dataOffset.truncate(int) * 2, dataLen) # TODO: Check data len, and raise? let meaningfulLen = to.len * 2 - let actualDataOffset = (dataOffset.toInt + 32) * 2 + let actualDataOffset = (dataOffset.truncate(int) + 32) * 2 hexToByteArray(input[actualDataOffset .. actualDataOffset + meaningfulLen - 1], to) func decode*[N](input: string, offset: int, to: var DynamicBytes[N]): int {.inline.} = @@ -483,17 +483,17 @@ proc parseContract(body: NimNode): seq[InterfaceObject] = doAssert(procdef.kind == nnkProcDef, "Contracts can only be built with procedures") let - isconstructor = procdef[4].findChild(it.ident == !"constructor") != nil - isevent = procdef[4].findChild(it.ident == !"event") != nil + isconstructor = procdef[4].findChild(it.strVal == "constructor") != nil + isevent = procdef[4].findChild(it.strVal == "event") != nil doAssert(not (isconstructor and constructor.isSome), "Contract can only have a single constructor") doAssert(not (isconstructor and isevent), "Can't be both event and constructor") if not isevent: let - ispure = procdef[4].findChild(it.ident == !"pure") != nil - isview = procdef[4].findChild(it.ident == !"view") != nil - ispayable = procdef[4].findChild(it.ident == !"payable") != nil + ispure = procdef[4].findChild(it.strVal == "pure") != nil + isview = procdef[4].findChild(it.strVal == "view") != nil + ispayable = procdef[4].findChild(it.strVal == "payable") != nil doAssert(not (ispure and isview), "can't be both `pure` and `view`") doAssert(not ((ispure or isview) and ispayable), @@ -506,17 +506,17 @@ proc parseContract(body: NimNode): seq[InterfaceObject] = )) else: functions.add FunctionObject( - name: $procdef[0].ident, + name: procdef[0].strVal, stateMutability: if ispure: pure elif isview: view elif ispayable: payable else: nonpayable, inputs: parseInputs(procdef[3]), outputs: parseOutputs(procdef[3][0]) ) else: - let isanonymous = procdef[4].findChild(it.ident == !"anonymous") != nil + let isanonymous = procdef[4].findChild(it.strVal == "anonymous") != nil doAssert(procdef[3][0].kind == nnkEmpty, "Events can't have return values") events.add EventObject( - name: $procdef[0].ident, + name: procdef[0].strVal, inputs: parseEventInputs(procdef[3]), anonymous: isanonymous ) From 4097cfaf95c2f3d7d13fe41889d01f215334296f Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 15 Jul 2020 15:41:22 +0700 Subject: [PATCH 3/4] fix tests --- tests/test.nim | 2 +- tests/test_deposit_contract.nim | 2 +- tests/test_logs.nim | 2 +- tests/test_signed_tx.nim | 2 +- web3.nim | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test.nim b/tests/test.nim index cc17f34..7924d14 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -59,7 +59,7 @@ const MetaCoinCode = "608060405234801561001057600080fd5b503260009081526020819052 proc test() {.async.} = - let web3 = await newWeb3("ws://127.0.0.1:8545") + let web3 = await newWeb3("ws://127.0.0.1:8545/") let accounts = await web3.provider.eth_accounts() echo "accounts: ", accounts web3.defaultAccount = accounts[0] diff --git a/tests/test_deposit_contract.nim b/tests/test_deposit_contract.nim index a71c1df..5eb328b 100644 --- a/tests/test_deposit_contract.nim +++ b/tests/test_deposit_contract.nim @@ -12,7 +12,7 @@ const contractCode = "0x740100000000000000000000000000000000000000006020526f7fff var contractAddress = Address.fromHex("e9d8d67ec115e8345606b3ab59fc71cec46761e4") proc test() {.async.} = - let web3 = await newWeb3("ws://localhost:8545") + let web3 = await newWeb3("ws://localhost:8545/") let accounts = await web3.provider.eth_accounts() web3.defaultAccount = accounts[0] diff --git a/tests/test_logs.nim b/tests/test_logs.nim index 36b42d2..72c2230 100644 --- a/tests/test_logs.nim +++ b/tests/test_logs.nim @@ -28,7 +28,7 @@ const LoggerContractCode = "6080604052348015600f57600080fd5b5060bc8061001e600039 var contractAddress = Address.fromHex("0xEA255DeA28c84F698Fa195f87fC83D1d4125ef9C") proc test() {.async.} = - let web3 = await newWeb3("ws://localhost:8545") + let web3 = await newWeb3("ws://localhost:8545/") let accounts = await web3.provider.eth_accounts() echo "accounts: ", accounts web3.defaultAccount = accounts[0] diff --git a/tests/test_signed_tx.nim b/tests/test_signed_tx.nim index 4555f94..0ad6be6 100644 --- a/tests/test_signed_tx.nim +++ b/tests/test_signed_tx.nim @@ -25,7 +25,7 @@ contract(NumberStorage): const NumberStorageCode = "6060604052341561000f57600080fd5b60bb8061001d6000396000f30060606040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fb5c1cb8114604d578063f2c9ecd8146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b60726089565b60405190815260200160405180910390f35b600055565b600054905600a165627a7a7230582023e722f35009f12d5698a4ab22fb9d55a6c0f479fc43875c65be46fbdd8db4310029" proc test() {.async.} = - let web3 = await newWeb3("ws://127.0.0.1:8545") + let web3 = await newWeb3("ws://127.0.0.1:8545/") let accounts = await web3.provider.eth_accounts() web3.defaultAccount = accounts[0] diff --git a/web3.nim b/web3.nim index 4365233..b4126ec 100644 --- a/web3.nim +++ b/web3.nim @@ -44,7 +44,7 @@ type historicalEventsProcessed: bool removed: bool - ContractCallBase {.pure, inheritable.} = object + ContractCallBase = object of RootObj web3: Web3 data: string to: Address From a01a40b8d760db38899160164e1ecec402d9638a Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 15 Jul 2020 16:35:37 +0700 Subject: [PATCH 4/4] fix appveyor.yml: 'ganache-cli.cmd' instead of 'ganache-cli' --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 991e196..6089722 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -34,7 +34,7 @@ build_script: - nimble install -y test_script: - - ps: Start-Process ganache-cli -ArgumentList "-s 0" + - ps: Start-Process ganache-cli.cmd -ArgumentList "-s 0" - nimble test deploy: off