-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds an assertion assertEOSErrorIncludesMessage
#97
Adds an assertion assertEOSErrorIncludesMessage
#97
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this idea, and actually have it integrated locally. Consider factoring it directly into the assertEOSError
method with a simple determiner within;
if (error.json && error.json.error && error.json.error.name) {
// Compare error and fail if the error doesn't match the expected
assert(
error.json.error.name === eosErrorName,
`Expected ${eosErrorName}, got ${error.json.error.name} instead.`
);
// Check the error details contain the optional message
if (withMessage && error.json.error.details.length > 0) {
assert.deepEqual(error.json.error.details[0], {
message: `assertion failure with message: ${withMessage}`,
});
}
return;
}
Then adding a withMessage
argument like so;
export const assertEOSError = async (operation: Promise<any>, eosErrorName:string, withMessage?: string) {}
You can also add some icing to the default assert like;
// Fail if no exception thrown
assert.fail(`Expected ${withMessage || 'error'} but operation completed successfully.`);
Thoughts?
I was thinking that having a specific assert would mean that the èosErrorName |
Ahh yes I see what your going for there! Good idea, much cleaner! I think I ran into this problem too. Can I suggest you add this determiner to export const assertEOSErrorMessage = async (operation: Promise<any>, message: string) => {
// Pass our operation and message onto assertEOSError
return assertEOSError(operation, 'eosio_assert_message_exception', message);
} This will minimize duplicate code. Also please add yourself to the authors on Kevin's Am I still missing things? |
I had deliberately not checked for |
I agree, great idea! Would it be a good idea to consolidate your changes into |
13764ef
to
3aa2704
Compare
I feel like we can be consistent on how we assert EOS errors and this can be a flavour of an EOS error we assert (e.g. shorthand like you're saying) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor things I noticed. Thanks again for the contribution!
f1b14a0
to
570cd9b
Compare
…e error message for an expected `eosio_assert_message_exception` includes the given description.
… assertions by creating a private function for other assertions to call into.
570cd9b
to
3d3572b
Compare
This should assert the error message for an expected
eosio_assert_message_exception
includes the given description message.eg. A contract may include:
and a safe test assertion may only check for the
ERR::CREATE_EXISITNG_SYMBOL
part which allows for the contract developer to safely evolve the error message for debugging purposes without breaking the tests.