Closed metaproph3t closed 1 year ago
Yes I think this can be done. May need to make some changes to solana-bankrun, like adding a method that processes a transaction and returns a result-like object instead of raising an error. Currently I think solana-bankrun is swallowing up the log messages when the transaction fails
Took a dive into the code; wasn't able to identify the place that needed fixing. Here's the workaround I'm using at the moment, in case useful to anyone else:
export const expectError = (
program: Program,
expectedError: string,
message: string
): [() => void, (e: any) => void] => {
return [
() => assert.fail(message),
(e) => {
assert(e.code != undefined, "problem retrieving program error code");
for (let idlError of program.idl.errors) {
if (idlError.code == e.code) {
assert.equal(idlError.name, expectedError);
return;
}
}
assert.fail("error doesn't match idl");
},
];
};
const callbacks = expectError(
vaultProgram,
"InsufficientUnderlyingTokens",
"mint suceeded despite user not having enough underlying tokens"
);
await mintConditionalTokens(
vaultProgram,
amount + 10,
bob,
bobDepositSlip,
vault,
vaultUnderlyingTokenAccount,
bobUnderlyingTokenAccount,
conditionalTokenMint,
bobConditionalTokenAccount
).then(callbacks[0], callbacks[1]);
When I call a
foo.methods.bar().rpc()
in a regular Anchor test and I expect an error, I get back an error that looks like this:In anchor-bankrun, I get one that looks like this:
Is it technically possible to have the latter look more like the former? Specifically, I assert against the human-readable code (
InvalidMetaDAOSigner
in this example), and was wondering if this is possible to include