From 330fa8a6b4d41aec499febea5ae62b0614181a7d Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 23 Oct 2024 19:43:23 +1100 Subject: [PATCH] clean up --- ethers/providers/jsonrpc/subscriptions.nim | 3 -- testmodule/providers/jsonrpc/rpc_mock.nim | 5 +--- .../jsonrpc/testJsonRpcSubscriptions.nim | 30 ++----------------- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/ethers/providers/jsonrpc/subscriptions.nim b/ethers/providers/jsonrpc/subscriptions.nim index 72cd44f..e93213d 100644 --- a/ethers/providers/jsonrpc/subscriptions.nim +++ b/ethers/providers/jsonrpc/subscriptions.nim @@ -175,11 +175,8 @@ proc new*(_: type JsonRpcSubscriptions, subscriptions method close*(subscriptions: PollingSubscriptions) {.async.} = - echo "Cancelling subscription polling..." await subscriptions.polling.cancelAndWait() - echo "Calling Provider.close..." await procCall JsonRpcSubscriptions(subscriptions).close() - echo "Close done." method subscribeBlocks(subscriptions: PollingSubscriptions, onBlock: BlockHandler): diff --git a/testmodule/providers/jsonrpc/rpc_mock.nim b/testmodule/providers/jsonrpc/rpc_mock.nim index 591aaa3..ab63b33 100644 --- a/testmodule/providers/jsonrpc/rpc_mock.nim +++ b/testmodule/providers/jsonrpc/rpc_mock.nim @@ -14,10 +14,7 @@ type MockRpcHttpServer* = ref object srv: RpcHttpServer proc new*(_: type MockRpcHttpServer): MockRpcHttpServer = - let port = rand(49152..65535) - let srv = newRpcHttpServer(["127.0.0.1:" & $port]) - let filters = initTable[string, bool]() - MockRpcHttpServer(filters: filters, newFilterCounter: 0, srv: srv) + MockRpcHttpServer(filters: initTable[string, bool](), newFilterCounter: 0, srv: newRpcHttpServer(["127.0.0.1:0"])) proc invalidateFilter*(server: MockRpcHttpServer, id: string) = server.filters[id] = false diff --git a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim index ff1a240..585619f 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcSubscriptions.nim @@ -103,58 +103,34 @@ suite "HTTP polling subscriptions - filter not found": var mockServer: MockRpcHttpServer setup: - echo "Creating MockRpcHttpServer instance" mockServer = MockRpcHttpServer.new() - echo "Starting MockRpcHttpServer..." mockServer.start() - echo "Started MockRpcHttpServer" - echo "Creating new RpcHttpClient instance..." client = newRpcHttpClient() - echo "Connecting RpcHttpClient to MockRpcHttpServer..." await client.connect("http://" & $mockServer.localAddress()[0]) - echo "Connected RpcHttpClient to MockRpcHttpServer" - echo "Creating new JsonRpcSubscriptions instance..." subscriptions = JsonRpcSubscriptions.new(client, pollingInterval = 100.millis) - echo "Starting JsonRpcSubscriptions..." subscriptions.start() - echo "Started JsonRpcSubscriptions" teardown: - echo "Closing subscriptions..." await subscriptions.close() - echo "Closing client..." await client.close() - echo "Stopping mock server..." await mockServer.stop() - echo "Stopped mock server" test "filter not found error recreates filter": - echo "1" let filter = EventFilter(address: Address.example, topics: @[array[32, byte].example]) - echo "2" let emptyHandler = proc(log: Log) = discard - echo "3" check mockServer.newFilterCounter == 0 - echo "4" let jsonId = await subscriptions.subscribeLogs(filter, emptyHandler) - echo "5" let id = string.fromJson(jsonId).tryGet - echo "6" check mockServer.newFilterCounter == 1 - echo "7" - await sleepAsync(200.millis) - echo "8" + await sleepAsync(300.millis) mockServer.invalidateFilter(id) - echo "9" - await sleepAsync(200.millis) - echo "10" + await sleepAsync(300.millis) check mockServer.newFilterCounter == 2 - echo "11" test "recreated filter can be still unsubscribed using the original id": let filter = EventFilter(address: Address.example, topics: @[array[32, byte].example]) @@ -165,7 +141,7 @@ suite "HTTP polling subscriptions - filter not found": let id = string.fromJson(jsonId).tryGet check mockServer.newFilterCounter == 1 - await sleepAsync(200.millis) + await sleepAsync(300.millis) mockServer.invalidateFilter(id) check eventually mockServer.newFilterCounter == 2 check mockServer.filters[id] == false