Test JSON-RPC Provider with polling

This commit is contained in:
Mark Spanbroek 2023-06-27 15:05:15 +02:00 committed by markspanbroek
parent 0322ae1451
commit 88d60b14b0

View File

@ -7,22 +7,18 @@ import pkg/stew/byteutils
import ../../examples
import ../../miner
suite "JsonRpcProvider":
for url in ["ws://localhost:8545", "http://localhost:8545"]:
suite "JsonRpcProvider (" & url & ")":
var provider: JsonRpcProvider
setup:
provider = JsonRpcProvider.new("ws://localhost:8545")
provider = JsonRpcProvider.new(url)
test "can be instantiated with a default URL":
discard JsonRpcProvider.new()
test "can be instantiated with an HTTP URL":
discard JsonRpcProvider.new("http://localhost:8545")
test "can be instantiated with a websocket URL":
discard JsonRpcProvider.new("ws://localhost:8545")
test "lists all accounts":
let accounts = await provider.listAccounts()
check accounts.len > 0
@ -50,6 +46,7 @@ suite "JsonRpcProvider":
let blockHandler = proc(blck: Block) {.async.} = newBlock = blck
let subscription = await provider.subscribe(blockHandler)
discard await provider.send("evm_mine")
check eventually newBlock.number.isSome
check !newBlock.number > !oldBlock.number
check newBlock.timestamp > oldBlock.timestamp
check newBlock.hash != oldBlock.hash