diff --git a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim index 83081ba..d5f6497 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim @@ -16,15 +16,7 @@ suite "JsonRpcSubscriptions": let subscriptions = JsonRpcSubscriptions.new(client) check not isNil subscriptions -suite "Web socket subscriptions": - - var subscriptions: JsonRpcSubscriptions - var client: RpcWebSocketClient - - setup: - client = newRpcWebSocketClient() - await client.connect("ws://localhost:8545") - subscriptions = JsonRpcSubscriptions.new(client) +template subscriptionTests(subscriptions, client) = test "subscribes to new blocks": var latestBlock: Block @@ -37,6 +29,18 @@ suite "Web socket subscriptions": check latestBlock.timestamp > 0.u256 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": var subscriptions: JsonRpcSubscriptions @@ -47,13 +51,4 @@ suite "HTTP polling subscriptions": await client.connect("http://localhost:8545") subscriptions = JsonRpcSubscriptions.new(client) - test "subscribes to new blocks": - 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() + subscriptionTests(subscriptions, client)