FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

52
node_modules/viem/actions/test/dropTransaction.ts generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hash } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type DropTransactionParameters = {
/** The hash of the transaction to drop. */
hash: Hash
}
export type DropTransactionErrorType = RequestErrorType | ErrorType
/**
* Removes a transaction from the mempool.
*
* - Docs: https://viem.sh/docs/actions/test/dropTransaction
*
* @param client - Client to use
* @param parameters - {@link DropTransactionParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { dropTransaction } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await dropTransaction(client, {
* hash: '0xe58dceb6b20b03965bb678e27d141e151d7d4efc2334c2d6a49b9fac523f7364'
* })
*/
export async function dropTransaction<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ hash }: DropTransactionParameters,
) {
await client.request({
method: `${client.mode}_dropTransaction`,
params: [hash],
})
}

44
node_modules/viem/actions/test/dumpState.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hex } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type DumpStateReturnType = Hex
export type DumpStateErrorType = RequestErrorType | ErrorType
/**
* Serializes the current state (including contracts code, contract's storage,
* accounts properties, etc.) into a savable data blob.
*
* - Docs: https://viem.sh/docs/actions/test/dumpState
*
* @param client - Client to use
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { dumpState } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await dumpState(client)
*/
export async function dumpState<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
): Promise<DumpStateReturnType> {
return client.request({
method: `${client.mode}_dumpState`,
})
}

48
node_modules/viem/actions/test/getAutomine.ts generated vendored Normal file
View File

@@ -0,0 +1,48 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type GetAutomineReturnType = boolean
export type GetAutomineErrorType = RequestErrorType | ErrorType
/**
* Returns the automatic mining status of the node.
*
* - Docs: https://viem.sh/docs/actions/test/getAutomine
*
* @param client - Client to use
* @returns Whether or not the node is auto mining. {@link GetAutomineReturnType}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { getAutomine } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const isAutomining = await getAutomine(client)
*/
export async function getAutomine<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
): Promise<GetAutomineReturnType> {
if (client.mode === 'ganache')
return await client.request({
method: 'eth_mining',
})
return await client.request({
method: `${client.mode}_getAutomine`,
})
}

52
node_modules/viem/actions/test/getTxpoolContent.ts generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RpcTransaction } from '../../types/rpc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type GetTxpoolContentReturnType = {
/** Pending transactions in the pool */
pending: Record<Address, Record<string, RpcTransaction>>
/** Queued transactions in the pool */
queued: Record<Address, Record<string, RpcTransaction>>
}
export type GetTxpoolContentErrorType = RequestErrorType | ErrorType
/**
* Returns the details of all transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.
*
* - Docs: https://viem.sh/docs/actions/test/getTxpoolContent
*
* @param client - Client to use
* @returns Transaction pool content. {@link GetTxpoolContentReturnType}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { getTxpoolContent } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const content = await getTxpoolContent(client)
*/
export async function getTxpoolContent<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
): Promise<GetTxpoolContentReturnType> {
return await client.request({
method: 'txpool_content',
})
}

52
node_modules/viem/actions/test/getTxpoolStatus.ts generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { hexToNumber } from '../../utils/encoding/fromHex.js'
export type GetTxpoolStatusReturnType = {
pending: number
queued: number
}
export type GetTxpoolStatusErrorType = RequestErrorType | ErrorType
/**
* Returns a summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.
*
* - Docs: https://viem.sh/docs/actions/test/getTxpoolStatus
*
* @param client - Client to use
* @returns Transaction pool status. {@link GetTxpoolStatusReturnType}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { getTxpoolStatus } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const status = await getTxpoolStatus(client)
*/
export async function getTxpoolStatus<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
): Promise<GetTxpoolStatusReturnType> {
const { pending, queued } = await client.request({
method: 'txpool_status',
})
return {
pending: hexToNumber(pending),
queued: hexToNumber(queued),
}
}

53
node_modules/viem/actions/test/impersonateAccount.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type ImpersonateAccountParameters = {
/** The account to impersonate. */
address: Address
}
export type ImpersonateAccountErrorType = RequestErrorType | ErrorType
/**
* Impersonate an account or contract address. This lets you send transactions from that account even if you don't have access to its private key.
*
* - Docs: https://viem.sh/docs/actions/test/impersonateAccount
*
* @param client - Client to use
* @param parameters - {@link ImpersonateAccountParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { impersonateAccount } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const content = await impersonateAccount(client, {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
*/
export async function impersonateAccount<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address }: ImpersonateAccountParameters,
) {
await client.request({
method: `${client.mode}_impersonateAccount`,
params: [address],
})
}

52
node_modules/viem/actions/test/increaseTime.ts generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type IncreaseTimeParameters = {
/** The amount of seconds to jump forward in time. */
seconds: number
}
export type IncreaseTimeErrorType = RequestErrorType | ErrorType
/**
* Jump forward in time by the given amount of time, in seconds.
*
* - Docs: https://viem.sh/docs/actions/test/increaseTime
*
* @param client - Client to use
* @param parameters {@link IncreaseTimeParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { increaseTime } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await increaseTime(client, {
* seconds: 420,
* })
*/
export async function increaseTime<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ seconds }: IncreaseTimeParameters,
) {
return await client.request({
method: 'evm_increaseTime',
params: [numberToHex(seconds)],
})
}

49
node_modules/viem/actions/test/inspectTxpool.ts generated vendored Normal file
View File

@@ -0,0 +1,49 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type InspectTxpoolReturnType = {
pending: Record<Address, Record<string, string>>
queued: Record<Address, Record<string, string>>
}
export type InspectTxpoolErrorType = RequestErrorType | ErrorType
/**
* Returns a summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only.
*
* - Docs: https://viem.sh/docs/actions/test/inspectTxpool
*
* @param client - Client to use
* @returns Transaction pool inspection data. {@link InspectTxpoolReturnType}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { inspectTxpool } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const data = await inspectTxpool(client)
*/
export async function inspectTxpool<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
): Promise<InspectTxpoolReturnType> {
return await client.request({
method: 'txpool_inspect',
})
}

47
node_modules/viem/actions/test/loadState.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hex } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type LoadStateParameters = { state: Hex }
export type LoadStateReturnType = void
export type LoadStateErrorType = RequestErrorType | ErrorType
/**
* Adds state previously dumped with `dumpState` to the current chain.
*
* - Docs: https://viem.sh/docs/actions/test/loadState
*
* @param client - Client to use
* @param parameters - {@link LoadStateParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { loadState } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await loadState(client, { state: '0x...' })
*/
export async function loadState<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ state }: LoadStateParameters,
): Promise<LoadStateReturnType> {
await client.request({
method: `${client.mode}_loadState`,
params: [state],
})
}

58
node_modules/viem/actions/test/mine.ts generated vendored Normal file
View File

@@ -0,0 +1,58 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type MineParameters = {
/** Number of blocks to mine. */
blocks: number
/** Interval between each block in seconds. */
interval?: number | undefined
}
export type MineErrorType = RequestErrorType | ErrorType
/**
* Mine a specified number of blocks.
*
* - Docs: https://viem.sh/docs/actions/test/mine
*
* @param client - Client to use
* @param parameters {@link MineParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { mine } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await mine(client, { blocks: 1 })
*/
export async function mine<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ blocks, interval }: MineParameters,
) {
if (client.mode === 'ganache')
await client.request({
method: 'evm_mine',
params: [{ blocks: numberToHex(blocks) }],
})
else
await client.request({
method: `${client.mode}_mine`,
params: [numberToHex(blocks), numberToHex(interval || 0)],
})
}

View File

@@ -0,0 +1,39 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type RemoveBlockTimestampIntervalErrorType = RequestErrorType | ErrorType
/**
* Removes [`setBlockTimestampInterval`](https://viem.sh/docs/actions/test/setBlockTimestampInterval) if it exists.
*
* - Docs: https://viem.sh/docs/actions/test/removeBlockTimestampInterval
*
* @param client - Client to use
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { removeBlockTimestampInterval } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await removeBlockTimestampInterval(client)
*/
export async function removeBlockTimestampInterval<
chain extends Chain | undefined,
account extends Account | undefined,
>(client: TestClient<TestClientMode, Transport, chain, account, false>) {
await client.request({
method: `${client.mode}_removeBlockTimestampInterval`,
})
}

51
node_modules/viem/actions/test/reset.ts generated vendored Normal file
View File

@@ -0,0 +1,51 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type ResetParameters = {
/** The block number to reset from. */
blockNumber?: bigint | undefined
/** The JSON RPC URL. */
jsonRpcUrl?: string | undefined
}
export type ResetErrorType = RequestErrorType | ErrorType
/**
* Resets fork back to its original state.
*
* - Docs: https://viem.sh/docs/actions/test/reset
*
* @param client - Client to use
* @param parameters {@link ResetParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { reset } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await reset(client, { blockNumber: 69420n })
*/
export async function reset<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ blockNumber, jsonRpcUrl }: ResetParameters = {},
) {
await client.request({
method: `${client.mode}_reset`,
params: [{ forking: { blockNumber: Number(blockNumber), jsonRpcUrl } }],
})
}

50
node_modules/viem/actions/test/revert.ts generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Quantity } from '../../types/rpc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type RevertParameters = {
/** The snapshot ID to revert to. */
id: Quantity
}
export type RevertErrorType = RequestErrorType | ErrorType
/**
* Revert the state of the blockchain at the current block.
*
* - Docs: https://viem.sh/docs/actions/test/revert
*
* @param client - Client to use
* @param parameters {@link RevertParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { revert } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await revert(client, { id: '0x…' })
*/
export async function revert<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ id }: RevertParameters,
) {
await client.request({
method: 'evm_revert',
params: [id],
})
}

View File

@@ -0,0 +1,97 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hash } from '../../types/misc.js'
import type { TransactionRequest } from '../../types/transaction.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { extract } from '../../utils/formatters/extract.js'
import {
type FormattedTransactionRequest,
formatTransactionRequest,
} from '../../utils/formatters/transactionRequest.js'
export type SendUnsignedTransactionParameters<
chain extends Chain | undefined = Chain | undefined,
> = FormattedTransactionRequest<chain>
export type SendUnsignedTransactionReturnType = Hash
export type SendUnsignedTransactionErrorType = RequestErrorType | ErrorType
/**
* Executes a transaction regardless of the signature.
*
* - Docs: https://viem.sh/docs/actions/test/sendUnsignedTransaction#sendunsignedtransaction
*
* @param client - Client to use
* @param parameters {@link SendUnsignedTransactionParameters}
* @returns The transaction hash. {@link SendUnsignedTransactionReturnType}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { sendUnsignedTransaction } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* const hash = await sendUnsignedTransaction(client, {
* from: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: 1000000000000000000n,
* })
*/
export async function sendUnsignedTransaction<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
args: SendUnsignedTransactionParameters<chain>,
): Promise<SendUnsignedTransactionReturnType> {
const {
accessList,
data,
from,
gas,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
...rest
} = args
const chainFormat = client.chain?.formatters?.transactionRequest?.format
const format = chainFormat || formatTransactionRequest
const request = format(
{
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format: chainFormat }),
accessList,
data,
from,
gas,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
} as TransactionRequest,
'sendUnsignedTransaction',
)
const hash = await client.request({
method: 'eth_sendUnsignedTransaction',
params: [request],
})
return hash
}

47
node_modules/viem/actions/test/setAutomine.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetAutomineErrorType = RequestErrorType | ErrorType
/**
* Enables or disables the automatic mining of new blocks with each new transaction submitted to the network.
*
* - Docs: https://viem.sh/docs/actions/test/setAutomine
*
* @param client - Client to use
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setAutomine } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setAutomine(client)
*/
export async function setAutomine<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
enabled: boolean,
) {
if (client.mode === 'ganache') {
if (enabled) await client.request({ method: 'miner_start' })
else await client.request({ method: 'miner_stop' })
} else
await client.request({
method: 'evm_setAutomine',
params: [enabled],
})
}

63
node_modules/viem/actions/test/setBalance.ts generated vendored Normal file
View File

@@ -0,0 +1,63 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetBalanceParameters = {
/** The account address. */
address: Address
/** Amount (in wei) to set */
value: bigint
}
export type SetBalanceErrorType = RequestErrorType | ErrorType
/**
* Modifies the balance of an account.
*
* - Docs: https://viem.sh/docs/actions/test/setBalance
*
* @param client - Client to use
* @param parameters {@link SetBalanceParameters}
*
* @example
* import { createTestClient, http, parseEther } from 'viem'
* import { foundry } from 'viem/chains'
* import { setBalance } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setBalance(client, {
* address: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
* value: parseEther('1'),
* })
*/
export async function setBalance<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, value }: SetBalanceParameters,
) {
if (client.mode === 'ganache')
await client.request({
method: 'evm_setAccountBalance',
params: [address, numberToHex(value)],
})
else
await client.request({
method: `${client.mode}_setBalance`,
params: [address, numberToHex(value)],
})
}

50
node_modules/viem/actions/test/setBlockGasLimit.ts generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetBlockGasLimitParameters = {
/** Gas limit (in wei). */
gasLimit: bigint
}
export type SetBlockGasLimitErrorType = RequestErrorType | ErrorType
/**
* Sets the block's gas limit.
*
* - Docs: https://viem.sh/docs/actions/test/setBlockGasLimit
*
* @param client - Client to use
* @param parameters {@link SetBlockGasLimitParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setBlockGasLimit } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setBlockGasLimit(client, { gasLimit: 420_000n })
*/
export async function setBlockGasLimit<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ gasLimit }: SetBlockGasLimitParameters,
) {
await client.request({
method: 'evm_setBlockGasLimit',
params: [numberToHex(gasLimit)],
})
}

View File

@@ -0,0 +1,54 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetBlockTimestampIntervalParameters = {
/** The interval (in seconds). */
interval: number
}
export type SetBlockTimestampIntervalErrorType = RequestErrorType | ErrorType
/**
* Similar to [`increaseTime`](https://viem.sh/docs/actions/test/increaseTime), but sets a block timestamp `interval`. The timestamp of future blocks will be computed as `lastBlock_timestamp` + `interval`.
*
* - Docs: https://viem.sh/docs/actions/test/setBlockTimestampInterval
*
* @param client - Client to use
* @param parameters {@link SetBlockTimestampIntervalParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setBlockTimestampInterval } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setBlockTimestampInterval(client, { interval: 5 })
*/
export async function setBlockTimestampInterval<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ interval }: SetBlockTimestampIntervalParameters,
) {
const interval_ = (() => {
if (client.mode === 'hardhat') return interval * 1000
return interval
})()
await client.request({
method: `${client.mode}_setBlockTimestampInterval`,
params: [interval_],
})
}

63
node_modules/viem/actions/test/setCode.ts generated vendored Normal file
View File

@@ -0,0 +1,63 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hex } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetCodeParameters = {
/** The account address. */
address: Address
/** The bytecode to set */
bytecode: Hex
}
export type SetCodeErrorType = RequestErrorType | ErrorType
/**
* Modifies the bytecode stored at an account's address.
*
* - Docs: https://viem.sh/docs/actions/test/setCode
*
* @param client - Client to use
* @param parameters {@link SetCodeParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setCode } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setCode(client, {
* address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
* bytecode: '0x60806040526000600355600019600955600c80546001600160a01b031916737a250d5630b4cf539739df…',
* })
*/
export async function setCode<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, bytecode }: SetCodeParameters,
) {
if (client.mode === 'ganache')
await client.request({
method: 'evm_setAccountCode',
params: [address, bytecode],
})
else
await client.request({
method: `${client.mode}_setCode`,
params: [address, bytecode],
})
}

53
node_modules/viem/actions/test/setCoinbase.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetCoinbaseParameters = {
/** The coinbase address. */
address: Address
}
export type SetCoinbaseErrorType = RequestErrorType | ErrorType
/**
* Sets the coinbase address to be used in new blocks.
*
* - Docs: https://viem.sh/docs/actions/test/setCoinbase
*
* @param client - Client to use
* @param parameters {@link SetCoinbaseParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setCoinbase } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setCoinbase(client, {
* address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
* })
*/
export async function setCoinbase<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address }: SetCoinbaseParameters,
) {
await client.request({
method: `${client.mode}_setCoinbase`,
params: [address],
})
}

54
node_modules/viem/actions/test/setIntervalMining.ts generated vendored Normal file
View File

@@ -0,0 +1,54 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetIntervalMiningParameters = {
/** The mining interval. */
interval: number
}
export type SetIntervalMiningErrorType = RequestErrorType | ErrorType
/**
* Sets the automatic mining interval (in seconds) of blocks. Setting the interval to 0 will disable automatic mining.
*
* - Docs: https://viem.sh/docs/actions/test/setIntervalMining
*
* @param client - Client to use
* @param parameters {@link SetIntervalMiningParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setIntervalMining } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setIntervalMining(client, { interval: 5 })
*/
export async function setIntervalMining<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ interval }: SetIntervalMiningParameters,
) {
const interval_ = (() => {
if (client.mode === 'hardhat') return interval * 1000
return interval
})()
await client.request({
method: 'evm_setIntervalMining',
params: [interval_],
})
}

43
node_modules/viem/actions/test/setLoggingEnabled.ts generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetLoggingEnabledErrorType = RequestErrorType | ErrorType
/**
* Enable or disable logging on the test node network.
*
* - Docs: https://viem.sh/docs/actions/test/setLoggingEnabled
*
* @param client - Client to use
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setLoggingEnabled } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setLoggingEnabled(client)
*/
export async function setLoggingEnabled<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
enabled: boolean,
) {
await client.request({
method: `${client.mode}_setLoggingEnabled`,
params: [enabled],
})
}

54
node_modules/viem/actions/test/setMinGasPrice.ts generated vendored Normal file
View File

@@ -0,0 +1,54 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetMinGasPriceParameters = {
/** The gas price. */
gasPrice: bigint
}
export type SetMinGasPriceErrorType = RequestErrorType | ErrorType
/**
* Change the minimum gas price accepted by the network (in wei).
*
* - Docs: https://viem.sh/docs/actions/test/setMinGasPrice
*
* Note: `setMinGasPrice` can only be used on clients that do not have EIP-1559 enabled.
*
* @param client - Client to use
* @param parameters {@link SetBlockGasLimitParameters}
*
* @example
* import { createTestClient, http, parseGwei } from 'viem'
* import { foundry } from 'viem/chains'
* import { setMinGasPrice } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setMinGasPrice(client, {
* gasPrice: parseGwei('20'),
* })
*/
export async function setMinGasPrice<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ gasPrice }: SetMinGasPriceParameters,
) {
await client.request({
method: `${client.mode}_setMinGasPrice`,
params: [numberToHex(gasPrice)],
})
}

View File

@@ -0,0 +1,52 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetNextBlockBaseFeePerGasParameters = {
/** Base fee per gas (in wei). */
baseFeePerGas: bigint
}
export type SetNextBlockBaseFeePerGasErrorType = RequestErrorType | ErrorType
/**
* Sets the next block's base fee per gas.
*
* - Docs: https://viem.sh/docs/actions/test/setNextBlockBaseFeePerGas
*
* @param client - Client to use
* @param parameters {@link SetNextBlockBaseFeePerGasParameters}
*
* @example
* import { createTestClient, http, parseGwei } from 'viem'
* import { foundry } from 'viem/chains'
* import { setNextBlockBaseFeePerGas } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setNextBlockBaseFeePerGas(client, {
* baseFeePerGas: parseGwei('20'),
* })
*/
export async function setNextBlockBaseFeePerGas<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ baseFeePerGas }: SetNextBlockBaseFeePerGasParameters,
) {
await client.request({
method: `${client.mode}_setNextBlockBaseFeePerGas`,
params: [numberToHex(baseFeePerGas)],
})
}

View File

@@ -0,0 +1,50 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetNextBlockTimestampParameters = {
/** The timestamp (in seconds). */
timestamp: bigint
}
export type SetNextBlockTimestampErrorType = RequestErrorType | ErrorType
/**
* Sets the next block's timestamp.
*
* - Docs: https://viem.sh/docs/actions/test/setNextBlockTimestamp
*
* @param client - Client to use
* @param parameters {@link SetNextBlockTimestampParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setNextBlockTimestamp } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setNextBlockTimestamp(client, { timestamp: 1671744314n })
*/
export async function setNextBlockTimestamp<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ timestamp }: SetNextBlockTimestampParameters,
) {
await client.request({
method: 'evm_setNextBlockTimestamp',
params: [numberToHex(timestamp)],
})
}

57
node_modules/viem/actions/test/setNonce.ts generated vendored Normal file
View File

@@ -0,0 +1,57 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetNonceParameters = {
/** The account address. */
address: Address
/** The nonce to set. */
nonce: number
}
export type SetNonceErrorType = RequestErrorType | ErrorType
/**
* Modifies (overrides) the nonce of an account.
*
* - Docs: https://viem.sh/docs/actions/test/setNonce
*
* @param client - Client to use
* @param parameters {@link SetNonceParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setNonce } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setNonce(client, {
* address: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
* nonce: 420,
* })
*/
export async function setNonce<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, nonce }: SetNonceParameters,
) {
await client.request({
method: `${client.mode}_setNonce`,
params: [address, numberToHex(nonce)],
})
}

44
node_modules/viem/actions/test/setRpcUrl.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetRpcUrlErrorType = RequestErrorType | ErrorType
/**
* Sets the backend RPC URL.
*
* - Docs: https://viem.sh/docs/actions/test/setRpcUrl
*
* @param client - Client to use
* @param jsonRpcUrl RPC URL
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setRpcUrl } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setRpcUrl(client, 'https://eth-mainnet.g.alchemy.com/v2')
*/
export async function setRpcUrl<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
jsonRpcUrl: string,
) {
await client.request({
method: `${client.mode}_setRpcUrl`,
params: [jsonRpcUrl],
})
}

65
node_modules/viem/actions/test/setStorageAt.ts generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hash, Hex } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
import { numberToHex } from '../../utils/encoding/toHex.js'
export type SetStorageAtParameters = {
/** The account address. */
address: Address
/** The storage slot (index). Can either be a number or hash value. */
index: number | Hash
/** The value to store as a 32 byte hex string. */
value: Hex
}
export type SetStorageAtErrorType = RequestErrorType | ErrorType
/**
* Writes to a slot of an account's storage.
*
* - Docs: https://viem.sh/docs/actions/test/setStorageAt
*
* @param client - Client to use
* @param parameters {@link SetStorageAtParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setStorageAt } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setStorageAt(client, {
* address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
* index: 2,
* value: '0x0000000000000000000000000000000000000000000000000000000000000069',
* })
*/
export async function setStorageAt<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, index, value }: SetStorageAtParameters,
) {
await client.request({
method: `${client.mode}_setStorageAt`,
params: [
address,
typeof index === 'number' ? numberToHex(index) : index,
value,
],
})
}

39
node_modules/viem/actions/test/snapshot.ts generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SnapshotErrorType = RequestErrorType | ErrorType
/**
* Snapshot the state of the blockchain at the current block.
*
* - Docs: https://viem.sh/docs/actions/test/snapshot
*
* @param client - Client to use
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { snapshot } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await snapshot(client)
*/
export async function snapshot<
chain extends Chain | undefined,
account extends Account | undefined,
>(client: TestClient<TestClientMode, Transport, chain, account, false>) {
return await client.request({
method: 'evm_snapshot',
})
}

View File

@@ -0,0 +1,53 @@
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type StopImpersonatingAccountParameters = {
/** The account to impersonate. */
address: Address
}
export type StopImpersonatingAccountErrorType = RequestErrorType | ErrorType
/**
* Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount).
*
* - Docs: https://viem.sh/docs/actions/test/stopImpersonatingAccount
*
* @param client - Client to use
* @param parameters {@link StopImpersonatingAccountParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { stopImpersonatingAccount } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await stopImpersonatingAccount(client, {
* address: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
* })
*/
export async function stopImpersonatingAccount<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address }: StopImpersonatingAccountParameters,
) {
await client.request({
method: `${client.mode}_stopImpersonatingAccount`,
params: [address],
})
}