Skip to content

Commit

Permalink
wip: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jun 17, 2024
1 parent e9a3ebe commit 1ef5db7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/clients/transports/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ describe('request', () => {
args
.map((arg) => JSON.parse(arg))
.sort((a, b) => a.id - b.id)
.map((arg) => JSON.stringify({ ...arg, id: undefined })),
.map((arg) => JSON.stringify(arg)),
).toMatchInlineSnapshot(`
[
"{"jsonrpc":"2.0","method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","method":"eth_blockNumber","params":[1]}",
"{"jsonrpc":"2.0","method":"eth_chainId"}",
"{"jsonrpc":"2.0","method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","id":22,"method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","id":23,"method":"eth_blockNumber","params":[1]}",
"{"jsonrpc":"2.0","id":24,"method":"eth_chainId"}",
"{"jsonrpc":"2.0","id":25,"method":"eth_blockNumber"}",
]
`)
expect(results).toMatchInlineSnapshot(`
Expand Down
8 changes: 1 addition & 7 deletions src/experimental/utils/nonceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ type FunctionParameters = {
}

export type NonceManager = {
/** Clear all nonces. */
clear(): Promise<void>
/** Get and increment a nonce. */
consume(parameters: FunctionParameters & { client: Client }): Promise<number>
/** Increment a nonce. */
Expand Down Expand Up @@ -44,16 +42,12 @@ export function createNonceManager(

const deltaMap = new Map()
const nonceMap = new LruMap<number>(8192)
let promiseMap = new Map<string, Promise<number>>()
const promiseMap = new Map<string, Promise<number>>()

const getKey = ({ address, chainId }: FunctionParameters) =>
`${address}.${chainId}`

return {
async clear() {
deltaMap.clear()
promiseMap = new Map()
},
async consume({ address, chainId, client }) {
const key = getKey({ address, chainId })
const promise = this.get({ address, chainId, client })
Expand Down
10 changes: 5 additions & 5 deletions src/utils/buildRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ describe('behavior', () => {
args
.map((arg) => JSON.parse(arg))
.sort((a, b) => a.id - b.id)
.map((arg) => JSON.stringify({ ...arg, id: undefined })),
.map((arg) => JSON.stringify(arg)),
).toMatchInlineSnapshot(`
[
"{"jsonrpc":"2.0","method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","method":"eth_blockNumber","params":[1]}",
"{"jsonrpc":"2.0","method":"eth_chainId"}",
"{"jsonrpc":"2.0","method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","id":61,"method":"eth_blockNumber"}",
"{"jsonrpc":"2.0","id":62,"method":"eth_blockNumber","params":[1]}",
"{"jsonrpc":"2.0","id":63,"method":"eth_chainId"}",
"{"jsonrpc":"2.0","id":64,"method":"eth_blockNumber"}",
]
`)
expect(results).toMatchInlineSnapshot(`
Expand Down

0 comments on commit 1ef5db7

Please sign in to comment.