-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Test: Add more procedures tests (#1247)
## Description _Concise description of proposed changes_ ## Testing Explain the quality checks that have been done on the code changes ## Additional Information - [ ] I read the [contributing docs](../docs/contributing.md) (if this is your first contribution) Your ENS/address: <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced `getBlockFromRpc` function in the blockchain package, enabling retrieval of blocks from an RPC server. - **Documentation** - Updated blockchain package documentation to include details on the new `getBlockFromRpc` function. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: William Cory <[email protected]>
- Loading branch information
1 parent
cb2dd84
commit d1d20e8
Showing
54 changed files
with
3,294 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
137 changes: 137 additions & 0 deletions
137
packages/procedures/src/__snapshots__/createHandlers.spec.ts.snap
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,137 @@ | ||
// Bun Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createHandlers should handle tevm_mine 1`] = ` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "tevm_mine", | ||
"result": { | ||
"blockHashes": [ | ||
"0x3201277b6823bbcd45e1a1c4a334c31b083676c70cebb1f386139f6091ae8e49", | ||
], | ||
}, | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_chainId 1`] = ` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_chainId", | ||
"result": "0x384", | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_call 1`] = ` | ||
{ | ||
"error": { | ||
"code": -32000, | ||
"data": { | ||
"errors": [ | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
], | ||
}, | ||
"message": | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
}, | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_call", | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_getBalance 1`] = ` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_getBalance", | ||
"result": "0x0", | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_estimateGas 1`] = ` | ||
{ | ||
"error": { | ||
"code": -32000, | ||
"data": { | ||
"errors": [ | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
], | ||
}, | ||
"message": | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000000 and the sender's account (0x6969696969696969696969696969696969696969) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x96171020921a6736a4e62d65c40b749609224fe43187d437cb37d19b3c011005 nonce=0 value=0 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
}, | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_estimateGas", | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle tevm_contract 1`] = ` | ||
{ | ||
"error": { | ||
"code": "MethodNotSupported", | ||
"message": | ||
"UnsupportedMethodError: tevm_contract is not supported. Encode the contract arguments and use tevm_call instead. | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/methodnotsupportederror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
}, | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "tevm_contract", | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_mining 1`] = ` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_mining", | ||
"result": false, | ||
} | ||
`; | ||
|
||
exports[`createHandlers should handle eth_syncing 1`] = ` | ||
{ | ||
"id": 1, | ||
"jsonrpc": "2.0", | ||
"method": "eth_syncing", | ||
"result": false, | ||
} | ||
`; |
53 changes: 53 additions & 0 deletions
53
packages/procedures/src/call/__snapshots__/callProcedure.spec.ts.snap
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,53 @@ | ||
// Bun Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`callProcedure should handle a basic call 1`] = ` | ||
{ | ||
"amountSpent": "0x296a6", | ||
"createdAddresses": [], | ||
"executionGasUsed": "0xc62", | ||
"gas": "0x1c964d6", | ||
"logs": [], | ||
"rawData": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", | ||
"selfdestruct": [], | ||
"totalGasSpent": "0x5eaa", | ||
} | ||
`; | ||
|
||
exports[`callProcedure should handle a call with state override 1`] = ` | ||
{ | ||
"amountSpent": "0x23e38", | ||
"executionGasUsed": "0x0", | ||
"rawData": "0x", | ||
"totalGasSpent": "0x5208", | ||
} | ||
`; | ||
|
||
exports[`callProcedure should handle errors from callHandler 1`] = ` | ||
{ | ||
"code": -32000, | ||
"data": { | ||
"errors": [ | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000500 and the sender's account (0x4242424242424242424242424242424242424242) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x66575cf759d7c97e42f103bfc8de6f88f70ea97a785d0c1f558496abf977cae1 nonce=0 value=500 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
], | ||
}, | ||
"message": | ||
"sender doesn't have enough funds to send tx. The upfront cost is: 210000500 and the sender's account (0x4242424242424242424242424242424242424242) only has: 0 -> block number=0 hash=0x63b5bacdb65c8c9d10e77d77d40bda5b4dc010a4f7e02a10bdea21a2b1b0a454 hf=cancun baseFeePerGas=7 txs=0 uncles=0 -> tx type=2 hash=0x66575cf759d7c97e42f103bfc8de6f88f70ea97a785d0c1f558496abf977cae1 nonce=0 value=500 signed=true hf=cancun maxFeePerGas=7 maxPriorityFeePerGas=0) | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73 | ||
Docs: https://tevm.sh/reference/tevm/errors/classes/insufficientfundserror/ | ||
Details: /reference/tevm/errors/classes/insufficientfundserror/ | ||
Version: 1.1.0.next-73" | ||
, | ||
} | ||
`; |
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,105 @@ | ||
import { beforeEach, describe, expect, it } from 'bun:test' | ||
import { setAccountHandler } from '@tevm/actions' | ||
import { type BaseClient, createBaseClient } from '@tevm/base-client' | ||
import { ERC20 } from '@tevm/contract' | ||
import { encodeFunctionData, numberToHex, parseEther } from '@tevm/utils' | ||
import type { CallJsonRpcRequest } from './CallJsonRpcRequest.js' | ||
import { callProcedure } from './callProcedure.js' | ||
|
||
let client: BaseClient | ||
|
||
beforeEach(() => { | ||
client = createBaseClient() | ||
}) | ||
|
||
describe('callProcedure', () => { | ||
it('should handle a basic call', async () => { | ||
const address = `0x${'69'.repeat(20)}` as const | ||
|
||
await setAccountHandler(client)({ | ||
address, | ||
balance: 420n, | ||
nonce: 69n, | ||
deployedBytecode: ERC20.deployedBytecode, | ||
state: { | ||
'0x0': '0x01', | ||
}, | ||
}) | ||
|
||
const request: CallJsonRpcRequest = { | ||
jsonrpc: '2.0', | ||
method: 'tevm_call', | ||
id: 1, | ||
params: [ | ||
{ | ||
to: address, | ||
data: encodeFunctionData(ERC20.read.name()), | ||
gas: numberToHex(21000n), | ||
gasPrice: numberToHex(1n), | ||
}, | ||
], | ||
} | ||
|
||
const response = await callProcedure(client)(request) | ||
expect(response.error).toBeUndefined() | ||
expect(response.result).toBeDefined() | ||
expect(response.method).toBe('tevm_call') | ||
expect(response.id).toBe(request.id as any) | ||
expect(response.result).toMatchSnapshot() | ||
}) | ||
|
||
it('should handle a call with state override', async () => { | ||
const to = `0x${'69'.repeat(20)}` as const | ||
const from = `0x${'42'.repeat(20)}` as const | ||
const request: CallJsonRpcRequest = { | ||
jsonrpc: '2.0', | ||
method: 'tevm_call', | ||
id: 1, | ||
params: [ | ||
{ | ||
to, | ||
from, | ||
value: numberToHex(parseEther('.9')), | ||
}, | ||
{ | ||
[from]: { | ||
balance: numberToHex(parseEther('1')), | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
const response = await callProcedure(client)(request) | ||
expect(response.error).toBeUndefined() | ||
expect(response.result).toBeDefined() | ||
expect(response.method).toBe('tevm_call') | ||
expect(response.id).toBe(request.id as any) | ||
expect(response.result).toMatchSnapshot() | ||
}) | ||
|
||
it.todo('should handle a call with block override', async () => {}) | ||
|
||
it('should handle errors from callHandler', async () => { | ||
const request: CallJsonRpcRequest = { | ||
jsonrpc: '2.0', | ||
method: 'tevm_call', | ||
id: 1, | ||
params: [ | ||
{ | ||
to: `0x${'00'.repeat(20)}` as const, // Invalid address | ||
from: `0x${'42'.repeat(20)}` as const, | ||
data: '0x0', | ||
value: numberToHex(500n), | ||
gas: numberToHex(21000n), | ||
gasPrice: numberToHex(1n), | ||
}, | ||
], | ||
} | ||
|
||
const response = await callProcedure(client)(request) | ||
expect(response.error).toBeDefined() | ||
expect(response.error).toMatchSnapshot() | ||
expect(response.method).toBe('tevm_call') | ||
expect(response.id).toBe(request.id as any) | ||
}) | ||
}) |
Oops, something went wrong.