UNPKG

@ethereum-waffle/chai

Version:

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

24 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.supportReverted = void 0; const call_promise_1 = require("../call-promise"); function supportReverted(Assertion) { Assertion.addProperty('reverted', function () { (0, call_promise_1.callPromise)(this); const onError = (error) => { const message = (error instanceof Object && 'message' in error) ? error.message : JSON.stringify(error); const isReverted = message.search('revert') >= 0; const isThrown = message.search('invalid opcode') >= 0; const isError = message.search('code=') >= 0; this.assert(isReverted || isThrown || isError, `Expected transaction to be reverted, but other exception was thrown: ${error}`, `Expected transaction NOT to be reverted, but it was reverted with "${message}"`, 'Transaction reverted.', error); return error; }; const assertNotReverted = () => this.assert(false, 'Expected transaction to be reverted', 'Expected transaction NOT to be reverted', 'Transaction reverted.', 'Transaction NOT reverted.'); this.callPromise = this.callPromise.then(assertNotReverted, onError); this.then = this.callPromise.then.bind(this.callPromise); this.catch = this.callPromise.catch.bind(this.callPromise); return this; }); } exports.supportReverted = supportReverted; //# sourceMappingURL=reverted.js.map