Skip to content

Commit

Permalink
πŸ‘¨β€πŸ”§ Do not rely on instanceOf for ethers related classes (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp authored Aug 30, 2022
1 parent 2f8bbd1 commit b96f0af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {ProviderWithHistoryExpected} from './error';
import {ensure} from './utils';

export function validateContract(contract: any): asserts contract is Contract {
const possiblyContract = contract as Contract;
ensure(
contract instanceof Contract, TypeError,
!!possiblyContract.address && !!possiblyContract.functions && !!possiblyContract.interface, TypeError,
'argument must be a contract'
);
}
Expand Down
12 changes: 2 additions & 10 deletions waffle-chai/src/matchers/misc/account.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {Contract, Signer, Wallet} from 'ethers';
import {Contract, Signer} from 'ethers';

export type Account = Signer | Contract;

export function isAccount(account: Account): account is Contract | Wallet {
return account instanceof Contract || account instanceof Wallet;
}

export async function getAddressOf(account: Account) {
if (isAccount(account)) {
return account.address;
} else {
return account.getAddress();
}
return (account as Contract).address ?? account.getAddress();
}

0 comments on commit b96f0af

Please sign in to comment.