Skip to content

Commit

Permalink
feat: add state override error types (#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm authored Feb 4, 2024
1 parent 2e7567c commit 444f61d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-bugs-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Added missing state override error types.
25 changes: 23 additions & 2 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import { multicall3Abi } from '../../constants/abis.js'
import { aggregate3Signature } from '../../constants/contract.js'
import { InvalidAddressError } from '../../errors/address.js'
import {
InvalidAddressError,
type InvalidAddressErrorType,
} from '../../errors/address.js'
import { BaseError } from '../../errors/base.js'
import {
ChainDoesNotSupportContract,
Expand All @@ -19,10 +22,15 @@ import {
RawContractError,
type RawContractErrorType,
} from '../../errors/contract.js'
import { InvalidBytesLengthError } from '../../errors/data.js'
import {
InvalidBytesLengthError,
type InvalidBytesLengthErrorType,
} from '../../errors/data.js'
import {
AccountStateConflictError,
type AccountStateConflictErrorType,
StateAssignmentConflictError,
type StateAssignmentConflictErrorType,
} from '../../errors/stateOverride.js'
import type { ErrorType } from '../../errors/utils.js'
import type { BlockTag } from '../../types/block.js'
Expand Down Expand Up @@ -106,6 +114,7 @@ export type CallReturnType = { data: Hex | undefined }

export type CallErrorType = GetCallErrorReturnType<
| ParseAccountErrorType
| ParseStateOverrideErrorType
| AssertRequestErrorType
| NumberToHexErrorType
| FormatTransactionRequestErrorType
Expand Down Expand Up @@ -350,6 +359,8 @@ export function getRevertErrorData(err: unknown) {
return typeof error.data === 'object' ? error.data.data : error.data
}

export type ParseStateMappingErrorType = InvalidBytesLengthErrorType

export function parseStateMapping(
stateMapping: StateMapping | undefined,
): RpcStateMapping | undefined {
Expand All @@ -372,6 +383,11 @@ export function parseStateMapping(
}, {} as RpcStateMapping)
}

export type ParseAccountStateOverrideErrorType =
| NumberToHexErrorType
| StateAssignmentConflictErrorType
| ParseStateMappingErrorType

export function parseAccountStateOverride(
args: Omit<StateOverride[number], 'address'>,
): RpcAccountStateOverride {
Expand All @@ -396,6 +412,11 @@ export function parseAccountStateOverride(
return rpcAccountStateOverride
}

export type ParseStateOverrideErrorType =
| InvalidAddressErrorType
| AccountStateConflictErrorType
| ParseAccountStateOverrideErrorType

export function parseStateOverride(
args?: StateOverride,
): RpcStateOverride | undefined {
Expand Down

0 comments on commit 444f61d

Please sign in to comment.