UNPKG

@ethereum-waffle/chai

Version:

A sweet set of chai matchers for your blockchain testing needs.

30 lines 1.55 kB
import { BigNumber } from 'ethers'; import { getAddressOf } from './misc/account'; import { getBalanceChange } from './changeEtherBalance'; import { callPromise } from '../call-promise'; export function supportChangeBalance(Assertion) { Assertion.addMethod('changeBalance', function (account, balanceChange) { callPromise(this); const isNegated = this.__flags.negate === true; const derivedPromise = this.callPromise.then(() => { if (!('txResponse' in this)) { throw new Error('The changeBalance matcher must be called on a transaction'); } return Promise.all([ getBalanceChange(this.txResponse, account, { includeFee: true }), getAddressOf(account) ]); }).then(([actualChange, address]) => { const isCurrentlyNegated = this.__flags.negate === true; this.__flags.negate = isNegated; this.assert(actualChange.eq(BigNumber.from(balanceChange)), `Expected "${address}" to change balance by ${balanceChange} wei, ` + `but it has changed by ${actualChange} wei`, `Expected "${address}" to not change balance by ${balanceChange} wei,`, balanceChange, actualChange); this.__flags.negate = isCurrentlyNegated; }); this.then = derivedPromise.then.bind(derivedPromise); this.catch = derivedPromise.catch.bind(derivedPromise); this.callPromise = derivedPromise; return this; }); } //# sourceMappingURL=changeBalance.js.map