Skip to content

Commit

Permalink
skipEvalTrace on tests that are expected to throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed Dec 18, 2024
1 parent 1cf4561 commit ecf168a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ export async function runMethod({
callType = 'call',
fundAmount = 0,
fee = 1000,
skipEvalTrace = false,
}: {
appClient: ApplicationClient;
method: string;
methodArgs?: algosdk.ABIArgument[];
callType?: 'call' | 'optIn';
fundAmount?: number;
fee?: number;
skipEvalTrace?: boolean;
}) {
const params = {
method,
Expand All @@ -179,6 +181,10 @@ export async function runMethod({
}
return (await appClient[callType](params)).return?.returnValue;
} catch (e) {
if (skipEvalTrace) {
console.warn(e);
throw e;
}
// eslint-disable-next-line no-console
const abiMethod = appClient.getABIMethod(params.method)!;
const { appId } = await appClient.getAppReference();
Expand Down
4 changes: 2 additions & 2 deletions tests/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('General', function () {
const { appClient, compiler } = await compileAndCreate(await sender, PATH, ARTIFACTS_DIR, NAME);
let msg = 'No error';
try {
await runMethod({ appClient, method: 'assertComment' });
await runMethod({ appClient, method: 'assertComment', skipEvalTrace: true });
} catch (e) {
msg = getErrorMessage(e.message, compiler.sourceInfo);
}
Expand All @@ -111,7 +111,7 @@ describe('General', function () {
const { appClient, compiler } = await compileAndCreate(await sender, PATH, ARTIFACTS_DIR, NAME);
let msg = 'No error';
try {
await runMethod({ appClient, method: 'throwErrorMessage' });
await runMethod({ appClient, method: 'throwErrorMessage', skipEvalTrace: true });
} catch (e) {
msg = getErrorMessage(e.message, compiler.sourceInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Math', function () {

let msg: string;
try {
await runMethod({ appClient, method: 'uint8plus', methodArgs: [2 ** 8 - 1, 1] });
await runMethod({ appClient, method: 'uint8plus', methodArgs: [2 ** 8 - 1, 1], skipEvalTrace: true });
msg = 'No error';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Expand Down
3 changes: 2 additions & 1 deletion tests/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Template Variables', function () {
});
let pc = 0;
try {
await runMethod({ appClient, method: 'throwError' });
await runMethod({ appClient, method: 'throwError', skipEvalTrace: true });
} catch (error) {
pc = Number(String(error).match(/pc=(\d+)/)?.[1]);
}
Expand All @@ -86,6 +86,7 @@ describe('Template Variables', function () {
const offsetPc = pc - cblocksOffset;

const sourceInfo = arc56.sourceInfo.approval.sourceInfo.find((s) => s.pc?.includes(offsetPc));
console.debug(arc56.sourceInfo.approval.sourceInfo, offsetPc, pc);
expect(sourceInfo?.errorMessage).toBe('this is an error');
});
});
Expand Down

0 comments on commit ecf168a

Please sign in to comment.