Skip to content

Commit

Permalink
fix: resolves #2067
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Apr 3, 2024
1 parent f539b0d commit 8a8fab2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-walls-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed parsing of `stateOverrides`.
4 changes: 2 additions & 2 deletions src/actions/public/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ describe('parsing overrides', () => {

expect(parseAccountStateOverride(stateOverride)).toMatchInlineSnapshot(`
{
"balance": "0x0000000000000000000000000000000000000000000000000000000000000001",
"balance": "0x1",
}
`)

Expand All @@ -1127,7 +1127,7 @@ describe('parsing overrides', () => {

expect(parseAccountStateOverride(stateOverride)).toMatchInlineSnapshot(`
{
"nonce": "0x0000000000000001",
"nonce": "0x1",
}
`)

Expand Down
16 changes: 5 additions & 11 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,12 @@ export function parseAccountStateOverride(
): RpcAccountStateOverride {
const { balance, nonce, state, stateDiff, code } = args
const rpcAccountStateOverride: RpcAccountStateOverride = {}
if (code !== undefined) {
rpcAccountStateOverride.code = code
}
if (balance !== undefined) {
rpcAccountStateOverride.balance = numberToHex(balance, { size: 32 })
}
if (nonce !== undefined) {
rpcAccountStateOverride.nonce = numberToHex(nonce, { size: 8 })
}
if (state !== undefined) {
if (code !== undefined) rpcAccountStateOverride.code = code
if (balance !== undefined)
rpcAccountStateOverride.balance = numberToHex(balance)
if (nonce !== undefined) rpcAccountStateOverride.nonce = numberToHex(nonce)
if (state !== undefined)
rpcAccountStateOverride.state = parseStateMapping(state)
}
if (stateDiff !== undefined) {
if (rpcAccountStateOverride.state) throw new StateAssignmentConflictError()
rpcAccountStateOverride.stateDiff = parseStateMapping(stateDiff)
Expand Down

0 comments on commit 8a8fab2

Please sign in to comment.