mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-04 06:33:07 +00:00
makes sure that a key on subscriptionMapping exists before trying to access it
This commit is contained in:
parent
d88e4614b1
commit
4642545309
@ -285,6 +285,7 @@ method unsubscribe*(subscriptions: PollingSubscriptions,
|
||||
{.async.} =
|
||||
subscriptions.logFilters.del(id)
|
||||
subscriptions.callbacks.del(id)
|
||||
if subscriptions.subscriptionMapping.hasKey(id):
|
||||
let sub = subscriptions.subscriptionMapping[id]
|
||||
subscriptions.subscriptionMapping.del(id)
|
||||
try:
|
||||
|
||||
@ -50,6 +50,15 @@ template subscriptionTests(subscriptions, client) =
|
||||
await sleepAsync(100.millis)
|
||||
check count == 0
|
||||
|
||||
test "unsubscribing from a non-existent subscription does not do any harm":
|
||||
await subscriptions.unsubscribe(newJInt(0))
|
||||
|
||||
test "duplicate unsubscribe is harmless":
|
||||
proc callback(blck: Block) = discard
|
||||
let subscription = await subscriptions.subscribeBlocks(callback)
|
||||
await subscriptions.unsubscribe(subscription)
|
||||
await subscriptions.unsubscribe(subscription)
|
||||
|
||||
test "stops listening to new blocks when provider is closed":
|
||||
var count = 0
|
||||
proc callback(blck: ?!Block) =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user