Remove duplication in tests
This commit is contained in:
parent
6a034870f8
commit
beac903a3f
|
@ -16,15 +16,7 @@ suite "JsonRpcSubscriptions":
|
||||||
let subscriptions = JsonRpcSubscriptions.new(client)
|
let subscriptions = JsonRpcSubscriptions.new(client)
|
||||||
check not isNil subscriptions
|
check not isNil subscriptions
|
||||||
|
|
||||||
suite "Web socket subscriptions":
|
template subscriptionTests(subscriptions, client) =
|
||||||
|
|
||||||
var subscriptions: JsonRpcSubscriptions
|
|
||||||
var client: RpcWebSocketClient
|
|
||||||
|
|
||||||
setup:
|
|
||||||
client = newRpcWebSocketClient()
|
|
||||||
await client.connect("ws://localhost:8545")
|
|
||||||
subscriptions = JsonRpcSubscriptions.new(client)
|
|
||||||
|
|
||||||
test "subscribes to new blocks":
|
test "subscribes to new blocks":
|
||||||
var latestBlock: Block
|
var latestBlock: Block
|
||||||
|
@ -37,6 +29,18 @@ suite "Web socket subscriptions":
|
||||||
check latestBlock.timestamp > 0.u256
|
check latestBlock.timestamp > 0.u256
|
||||||
await subscription.unsubscribe()
|
await subscription.unsubscribe()
|
||||||
|
|
||||||
|
suite "Web socket subscriptions":
|
||||||
|
|
||||||
|
var subscriptions: JsonRpcSubscriptions
|
||||||
|
var client: RpcWebSocketClient
|
||||||
|
|
||||||
|
setup:
|
||||||
|
client = newRpcWebSocketClient()
|
||||||
|
await client.connect("ws://localhost:8545")
|
||||||
|
subscriptions = JsonRpcSubscriptions.new(client)
|
||||||
|
|
||||||
|
subscriptionTests(subscriptions, client)
|
||||||
|
|
||||||
suite "HTTP polling subscriptions":
|
suite "HTTP polling subscriptions":
|
||||||
|
|
||||||
var subscriptions: JsonRpcSubscriptions
|
var subscriptions: JsonRpcSubscriptions
|
||||||
|
@ -47,13 +51,4 @@ suite "HTTP polling subscriptions":
|
||||||
await client.connect("http://localhost:8545")
|
await client.connect("http://localhost:8545")
|
||||||
subscriptions = JsonRpcSubscriptions.new(client)
|
subscriptions = JsonRpcSubscriptions.new(client)
|
||||||
|
|
||||||
test "subscribes to new blocks":
|
subscriptionTests(subscriptions, client)
|
||||||
var latestBlock: Block
|
|
||||||
proc callback(blck: Block) {.async.} =
|
|
||||||
latestBlock = blck
|
|
||||||
let subscription = await subscriptions.subscribeBlocks(callback)
|
|
||||||
discard await client.call("evm_mine", newJArray())
|
|
||||||
check eventually(latestBlock.number.isSome)
|
|
||||||
check latestBlock.hash.isSome
|
|
||||||
check latestBlock.timestamp > 0.u256
|
|
||||||
await subscription.unsubscribe()
|
|
||||||
|
|
Loading…
Reference in New Issue