locklift
Version:
Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.
26 lines (25 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportMessageErrors = void 0;
const supportMessageErrors = (Assertion, utils) => {
Assertion.addMethod("error", function (errorCode, contract) {
const rewriteThis = this;
const viewTracingTree = rewriteThis.__flags.object;
const errors = contract
? viewTracingTree.getErrorsByContract(contract)?.map(error => ({ ...error, contract })) || []
: viewTracingTree.getAllErrors();
if (errorCode !== null && typeof errorCode !== "number") {
this.assert(errors.length > 0, "Expected errors to be through, but it wasn't", `Expected errors NOT to be through, but it was \n ${JSON.stringify(errors.map(({ trace, contract, ...rest }) => ({
...rest,
contract: `${trace.contract.name}(${contract})`,
method: `${trace.decodedMsg?.method}(${JSON.stringify(trace.decodedMsg?.params)})`,
})), null, 4)}`, true);
}
else {
this.assert(errors.filter(({ code }) => code === errorCode).length > 0, `Expected error "${errorCode}" to be thrown, but it wasn't`, `Expected error "${errorCode}" NOT to be thrown, but it was`, true);
}
utils.flag(this, "errors", errors);
return this;
});
};
exports.supportMessageErrors = supportMessageErrors;