Skip to content
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

Fix app state not being properly reset when stepping back #19

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading