-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Test: Add eth_getTransactionCount tests
- Loading branch information
William Cory
authored and
William Cory
committed
Sep 13, 2024
1 parent
838631e
commit 99fe333
Showing
2 changed files
with
156 additions
and
12 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
102 changes: 102 additions & 0 deletions
102
packages/procedures/src/eth/ethGetTransactionCountProcedure.spec.ts
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,102 @@ | ||
import { callHandler } from '@tevm/actions' | ||
import { createAddress } from '@tevm/address' | ||
import { createTevmNode } from '@tevm/node' | ||
import { transports } from '@tevm/test-utils' | ||
import { numberToHex, parseEther } from '@tevm/utils' | ||
import { describe, expect, it } from 'vitest' | ||
import { ethGetTransactionCountProcedure } from './ethGetTransactionCountProcedure.js' | ||
|
||
const address = '0xb5d85CBf7cB3EE0D56b3bB207D5Fc4B82f43F511' as const | ||
|
||
describe(ethGetTransactionCountProcedure.name, () => { | ||
it('should work', async () => { | ||
const node = createTevmNode({ | ||
fork: { | ||
transport: transports.mainnet, | ||
blockTag: 20743493n, | ||
}, | ||
}) | ||
expect( | ||
await ethGetTransactionCountProcedure(node)({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'eth_getTransactionCount', | ||
params: [address, 'latest'], | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_getTransactionCount", | ||
"result": "0x8e96b4", | ||
} | ||
`) | ||
}) | ||
it('should work with past block tags', async () => { | ||
const node = createTevmNode({ | ||
fork: { | ||
transport: transports.mainnet, | ||
blockTag: 20743493n, | ||
}, | ||
}) | ||
expect( | ||
await ethGetTransactionCountProcedure(node)({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'eth_getTransactionCount', | ||
params: [address, numberToHex(20700000n)], | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_getTransactionCount", | ||
"result": "0x8df90f", | ||
} | ||
`) | ||
}) | ||
it('should work with pending tx', async () => { | ||
const node = createTevmNode({ | ||
fork: { | ||
transport: transports.mainnet, | ||
blockTag: 20743493n, | ||
}, | ||
}) | ||
await callHandler(node)({ | ||
from: address, | ||
to: createAddress(5).toString(), | ||
value: parseEther('0.1'), | ||
createTransaction: true, | ||
}) | ||
expect( | ||
await ethGetTransactionCountProcedure(node)({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'eth_getTransactionCount', | ||
params: [address, 'latest'], | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_getTransactionCount", | ||
"result": "0x8e96b4", | ||
} | ||
`) | ||
expect( | ||
await ethGetTransactionCountProcedure(node)({ | ||
jsonrpc: '2.0', | ||
id: 1, | ||
method: 'eth_getTransactionCount', | ||
params: [address, 'pending'], | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_getTransactionCount", | ||
"result": "0x8e96b5", | ||
} | ||
`) | ||
}) | ||
}) |