-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(subscriptions): filter not found recreates polling filter (#78)
- Loading branch information
Showing
4 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import ../../examples | ||
import ../../../ethers/provider | ||
import ../../../ethers/providers/jsonrpc/conversions | ||
|
||
import std/tables | ||
import pkg/stew/byteutils | ||
import pkg/json_rpc/rpcserver except `%`, `%*` | ||
import pkg/json_rpc/errors | ||
|
||
|
||
type MockRpcHttpServer* = ref object | ||
filters*: Table[string, bool] | ||
newFilterCounter*: int | ||
srv: RpcHttpServer | ||
|
||
proc new*(_: type MockRpcHttpServer): MockRpcHttpServer = | ||
MockRpcHttpServer(filters: initTable[string, bool](), newFilterCounter: 0, srv: newRpcHttpServer(["127.0.0.1:0"])) | ||
|
||
proc invalidateFilter*(server: MockRpcHttpServer, id: string) = | ||
server.filters[id] = false | ||
|
||
proc start*(server: MockRpcHttpServer) = | ||
server.srv.router.rpc("eth_newFilter") do(filter: EventFilter) -> string: | ||
let filterId = "0x" & (array[16, byte].example).toHex | ||
server.filters[filterId] = true | ||
server.newFilterCounter += 1 | ||
return filterId | ||
|
||
server.srv.router.rpc("eth_getFilterChanges") do(id: string) -> seq[string]: | ||
if(not hasKey(server.filters, id) or not server.filters[id]): | ||
raise (ref ApplicationError)(code: -32000, msg: "filter not found") | ||
|
||
return @[] | ||
|
||
server.srv.router.rpc("eth_uninstallFilter") do(id: string) -> bool: | ||
if(not hasKey(server.filters, id)): | ||
raise (ref ApplicationError)(code: -32000, msg: "filter not found") | ||
|
||
server.filters.del(id) | ||
return true | ||
|
||
server.srv.start() | ||
|
||
proc stop*(server: MockRpcHttpServer) {.async.} = | ||
await server.srv.stop() | ||
await server.srv.closeWait() | ||
|
||
|
||
proc localAddress*(server: MockRpcHttpServer): seq[TransportAddress] = | ||
return server.srv.localAddress() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters