@ethereum-waffle/chai
Version:
A sweet set of chai matchers for your blockchain testing needs.
34 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportChangeBalance = void 0;
const ethers_1 = require("ethers");
const account_1 = require("./misc/account");
const changeEtherBalance_1 = require("./changeEtherBalance");
const call_promise_1 = require("../call-promise");
function supportChangeBalance(Assertion) {
Assertion.addMethod('changeBalance', function (account, balanceChange) {
(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 changeBalance matcher must be called on a transaction');
}
return Promise.all([
(0, changeEtherBalance_1.getBalanceChange)(this.txResponse, account, { includeFee: true }),
(0, account_1.getAddressOf)(account)
]);
}).then(([actualChange, address]) => {
const isCurrentlyNegated = this.__flags.negate === true;
this.__flags.negate = isNegated;
this.assert(actualChange.eq(ethers_1.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;
});
}
exports.supportChangeBalance = supportChangeBalance;
//# sourceMappingURL=changeBalance.js.map