UNPKG

@ethereum-waffle/chai

Version:

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

15 lines 1.05 kB
export function supportHexEqual(Assertion) { Assertion.addMethod('hexEqual', function (other) { const subject = this._obj; const isNegated = this.__flags.negate === true; const isHex = (a) => /^0x[0-9a-fA-F]*$/.test(a); for (const element of [subject, other]) { if (!isHex(element)) { this.assert(isNegated, `Expected "${subject}" to be a hex string equal to "${other}", but "${element}" is not a valid hex string`, `Expected "${subject}" not to be a hex string equal to "${other}", but "${element}" is not a valid hex string`); } } const extractNumeric = (hex) => hex.replace(/^0x0*/, ''); this.assert(extractNumeric(subject.toLowerCase()) === extractNumeric(other.toLowerCase()), `Expected "${subject}" to be a hex string equal equal to "${other}"`, `Expected "${subject}" not to a hex string equal be equal to "${other}", but it was`, `Hex string representing the same number as ${other}`, subject); }); } //# sourceMappingURL=hexEqual.js.map