UNPKG

@ethereum-waffle/chai

Version:

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

34 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.supportChangeBalances = void 0; const ethers_1 = require("ethers"); const call_promise_1 = require("../call-promise"); const changeEtherBalances_1 = require("./changeEtherBalances"); const balance_1 = require("./misc/balance"); function supportChangeBalances(Assertion) { Assertion.addMethod('changeBalances', function (accounts, balanceChanges) { (0, call_promise_1.callPromise)(this); const isNegated = this.__flags.negate === true; const derivedPromise = this.callPromise.then(() => { if (!('txResponse' in this)) { throw new Error('The changeBalances matcher must be called on a transaction'); } return Promise.all([ (0, changeEtherBalances_1.getBalanceChanges)(this.txResponse, accounts, { includeFee: true }), (0, balance_1.getAddresses)(accounts) ]); }).then(([actualChanges, accountAddresses]) => { const isCurrentlyNegated = this.__flags.negate === true; this.__flags.negate = isNegated; this.assert(actualChanges.every((change, ind) => change.eq(ethers_1.BigNumber.from(balanceChanges[ind]))), `Expected ${accountAddresses} to change balance by ${balanceChanges} wei, ` + `but it has changed by ${actualChanges} wei`, `Expected ${accountAddresses} to not change balance by ${balanceChanges} wei,`, balanceChanges.map((balanceChange) => balanceChange.toString()), actualChanges.map((actualChange) => actualChange.toString())); this.__flags.negate = isCurrentlyNegated; }); this.then = derivedPromise.then.bind(derivedPromise); this.catch = derivedPromise.catch.bind(derivedPromise); this.callPromise = derivedPromise; return this; }); } exports.supportChangeBalances = supportChangeBalances; //# sourceMappingURL=changeBalances.js.map