Skip to content

Commit

Permalink
🗽 Introduce TestProvider type (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad authored May 17, 2022
1 parent a39f6f7 commit 1e479c3
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-yaks-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ethereum-waffle/provider": patch
---

Introduce TestProvider type
106 changes: 82 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion waffle-chai/src/matchers/changeEtherBalance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {TestProvider} from '@ethereum-waffle/provider';
import {BigNumber, BigNumberish, providers} from 'ethers';
import {callPromise} from '../call-promise';
import {ensure} from './calledOnContract/utils';
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function getBalanceChange(
const gasPrice = txResponse.gasPrice ?? txReceipt.effectiveGasPrice;
const gasUsed = txReceipt.gasUsed;
const txFee = gasPrice.mul(gasUsed);
const provider = account.provider as any;
const provider = account.provider as TestProvider;
if (typeof provider.getL1Fee === 'function') {
const l1Fee = await provider.getL1Fee(txReceipt.transactionHash);
return balanceAfter.add(txFee).add(l1Fee).sub(balanceBefore);
Expand Down
3 changes: 2 additions & 1 deletion waffle-chai/src/matchers/changeEtherBalances.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {TestProvider} from '@ethereum-waffle/provider';
import {BigNumber, BigNumberish, providers} from 'ethers';
import {callPromise} from '../call-promise';
import {getAddressOf, Account} from './misc/account';
Expand Down Expand Up @@ -70,7 +71,7 @@ async function getTxFees(
const gasPrice = txResponse.gasPrice ?? txReceipt.effectiveGasPrice;
const gasUsed = txReceipt.gasUsed;
const txFee = gasPrice.mul(gasUsed);
const provider = account.provider as any;
const provider = account.provider as TestProvider;
if (typeof provider.getL1Fee === 'function') {
const l1Fee = await provider.getL1Fee(txReceipt.transactionHash);
return txFee.add(l1Fee);
Expand Down
2 changes: 1 addition & 1 deletion waffle-chai/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
declare namespace Chai {
interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
reverted: AsyncAssertion;
revertedWith(reason: string): RevertedWithAssertion;
revertedWith(reason: string | RegExp): RevertedWithAssertion;
emit(contract: any, eventName: string): EmitAssertion;
properHex(length: number): void;
hexEqual(other: string): void;
Expand Down
4 changes: 2 additions & 2 deletions waffle-chai/test/matchers/chainingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {Wallet, Contract, ContractFactory} from 'ethers';
import {MOCK_TOKEN_ABI, MOCK_TOKEN_BYTECODE} from '../contracts/MockToken';
import {COMPLEX_ABI, COMPLEX_BYTECODE} from '../contracts/Complex';

import {MockProvider} from '@ethereum-waffle/provider';
import type {TestProvider} from '@ethereum-waffle/provider';

export const chainingMatchersTest = (provider: MockProvider) => {
export const chainingMatchersTest = (provider: TestProvider) => {
let sender: Wallet;
let receiver: Wallet;
let token: Contract;
Expand Down
4 changes: 2 additions & 2 deletions waffle-chai/test/matchers/changeEtherBalanceTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MockProvider} from '@ethereum-waffle/provider';
import type {TestProvider} from '@ethereum-waffle/provider';
import {expect, AssertionError} from 'chai';
import {BigNumber, Contract, Wallet} from 'ethers';

Expand All @@ -8,7 +8,7 @@ interface ChangeEtherBalanceTestOptions {
}

export const changeEtherBalanceTest = (
provider: MockProvider,
provider: TestProvider,
options: ChangeEtherBalanceTestOptions
) => {
let txGasFees: number;
Expand Down
Loading

0 comments on commit 1e479c3

Please sign in to comment.