@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
24 lines (23 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportRevertedWith = void 0;
function supportRevertedWith(Assertion) {
Assertion.addMethod('revertedWith', function (revertReason) {
const promise = this._obj;
const onSuccess = (value) => {
this.assert(false, 'Expected transaction to be reverted', 'Expected transaction NOT to be reverted', 'Transaction reverted.', 'Transaction NOT reverted.');
return value;
};
const onError = (error) => {
const message = (error instanceof Object && 'message' in error) ? error.message : JSON.stringify(error);
const isReverted = message.toLowerCase().includes(revertReason.toLowerCase());
this.assert(isReverted, `Expected transaction to be reverted with ${revertReason}, but other exception was thrown: ${message}`, `Expected transaction NOT to be reverted with ${revertReason}`, `Transaction reverted with ${revertReason}.`, error);
return error;
};
const derivedPromise = promise.then(onSuccess, onError);
this.then = derivedPromise.then.bind(derivedPromise);
this.catch = derivedPromise.catch.bind(derivedPromise);
return this;
});
}
exports.supportRevertedWith = supportRevertedWith;