Skip to content

Commit

Permalink
Fix app state not being properly reset when stepping back (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos authored Jan 4, 2024
1 parent ea323d2 commit d4a1b8b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix app state not being properly reset when stepping back ([#19](https://github.com/algorand/avm-debugger/pull/19))

## [0.1.2] - 2023-12-14

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/common/traceReplayEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ export class ProgramStackFrame extends TraceReplayStackFrame {
if (typeof this.initialAppState !== 'undefined') {
this.engine.currentAppState.set(
this.currentAppID()!,
this.initialAppState,
this.initialAppState.clone(),
);
}
}
Expand Down
101 changes: 101 additions & 0 deletions tests/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,35 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Move to the end of the program
await advanceTo(client, { program: PROGRAM, line: 46 });

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the global state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1050],
apps: [
{
appID: 1050,
globalState: new ByteArrayMap(),
},
],
});
});
});

Expand Down Expand Up @@ -1535,6 +1564,41 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Move to the end of the program
await advanceTo(client, { program: PROGRAM, line: 46 });

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the local state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1054],
apps: [
{
appID: 1054,
localState: [
{
account:
'YGOSQB6R5IVQDJHJUHTIZAJNWNIT7VLMWHXFWY2H5HMWPK7QOPXHELNPJ4',
state: new ByteArrayMap(),
},
],
},
],
});
});
});

Expand Down Expand Up @@ -1632,6 +1696,43 @@ describe('Debug Adapter Tests', () => {
},
],
});

// Clear breakpoints -- must do because the 'next' request is on line 46 as well
await client.setBreakpointsRequest({
source: { path: PROGRAM },
breakpoints: [],
});

// Move to the end of the program
await client.nextRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');

// Step back to the beginning of the program
for (;;) {
const stackTraceResponse = await client.stackTraceRequest({
threadId: 1,
});
const currentFrame = stackTraceResponse.body.stackFrames[0];
if (currentFrame.source?.path === PROGRAM && currentFrame.line === 3) {
break;
}
await client.stepBackRequest({ threadId: 1 });
const stoppedEvent = await client.waitForStop();
assert.strictEqual(stoppedEvent.body.reason, 'step');
}

// Ensure that the box state at the beginning does not show changes that will happen later
await assertVariables(client, {
pc: 6,
stack: [1058],
apps: [
{
appID: 1058,
boxState: new ByteArrayMap(),
},
],
});
});
});

Expand Down

0 comments on commit d4a1b8b

Please sign in to comment.