diff --git a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim index 3d01fc0..7714328 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim @@ -24,11 +24,24 @@ template subscriptionTests(subscriptions, client) = latestBlock = blck let subscription = await subscriptions.subscribeBlocks(callback) discard await client.call("evm_mine", newJArray()) - check eventually(latestBlock.number.isSome) + check eventually latestBlock.number.isSome check latestBlock.hash.isSome check latestBlock.timestamp > 0.u256 await subscription.unsubscribe() + test "stops listening to new blocks when unsubscribed": + var count = 0 + proc callback(blck: Block) {.async.} = + inc count + let subscription = await subscriptions.subscribeBlocks(callback) + discard await client.call("evm_mine", newJArray()) + check eventually count > 0 + await subscription.unsubscribe() + let endcount = count + discard await client.call("evm_mine", newJArray()) + await sleepAsync(100.millis) + check count == endcount + suite "Web socket subscriptions": var subscriptions: JsonRpcSubscriptions