import type { AbiHolder, ErrorArgsOf, EventArgsOf } from "../abi-types.js"; import type { HardhatViemAssertions } from "../types.js"; import type { HardhatViemHelpers } from "@nomicfoundation/hardhat-viem/types"; import type { ChainType } from "hardhat/types/network"; import type { Abi, Address, ContractErrorName, ContractEventName, Hash, ReadContractReturnType, WriteContractReturnType, } from "viem"; import { balancesHaveChanged } from "./assertions/balances-have-changed.js"; import { emitWithArgs } from "./assertions/emit/emit-with-args.js"; import { emit } from "./assertions/emit/emit.js"; import { revertWithCustomErrorWithArgs } from "./assertions/revert/revert-with-custom-error-with-args.js"; import { revertWithCustomError } from "./assertions/revert/revert-with-custom-error.js"; import { revertWith } from "./assertions/revert/revert-with.js"; import { revert } from "./assertions/revert/revert.js"; export class HardhatViemAssertionsImpl< ChainTypeT extends ChainType | string = "generic", > implements HardhatViemAssertions { readonly #viem: HardhatViemHelpers; constructor(viem: HardhatViemHelpers) { this.#viem = viem; } public async balancesHaveChanged( txHash: Hash | Promise, changes: Array<{ address: Address; amount: bigint; }>, ): Promise { return await balancesHaveChanged(this.#viem, txHash, changes); } public async emit>( txHash: Hash | Promise, contract: TContract, eventName: ContractEventName, ): Promise { return await emit(this.#viem, txHash, contract, eventName); } public async emitWithArgs< TContract extends AbiHolder, TEventName extends ContractEventName, >( txHash: Hash | Promise, contract: TContract, eventName: TEventName, args: EventArgsOf, ): Promise { return await emitWithArgs(this.#viem, txHash, contract, eventName, args); } public async revert( contractFn: Promise, ): Promise { return await revert(contractFn); } public async revertWith( contractFn: Promise, expectedRevertReason: string, ): Promise { return await revertWith(contractFn, expectedRevertReason); } public async revertWithCustomError>( contractFn: Promise, contract: TContract, customErrorName: ContractErrorName, ): Promise { return await revertWithCustomError(contractFn, contract, customErrorName); } public async revertWithCustomErrorWithArgs< TContract extends AbiHolder, TErrorName extends ContractErrorName, >( contractFn: Promise, contract: TContract, customErrorName: TErrorName, args: ErrorArgsOf, ): Promise { return await revertWithCustomErrorWithArgs( contractFn, contract, customErrorName, args, ); } }