Skip to content

Commit

Permalink
Add stateDiff in SimulateTransaction API response
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed May 10, 2024
1 parent dedacda commit ecaaa92
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/soroban/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,18 @@ export namespace Api {
value: string;
}

export interface RequestAirdropResponse {
transaction_id: string;
interface RawLedgerEntryDiff {
type: number;
key: string;
before?: string;
after?: string;
}

interface LedgerEntryDiff{
type: number;
key: string;
before?: xdr.LedgerEntry;
after?: xdr.LedgerEntry;
}

export type SendTransactionStatus =
Expand Down Expand Up @@ -264,6 +274,9 @@ export namespace Api {

/** present only for invocation simulation */
result?: SimulateHostFunctionResult;

// State Difference information
stateDiff?: LedgerEntryDiff[];
}

/** Includes details about why the simulation failed */
Expand Down Expand Up @@ -347,5 +360,8 @@ export namespace Api {
minResourceFee: string;
transactionData: string;
};

// State Difference information
stateDiff?: RawLedgerEntryDiff[];
}
}
27 changes: 27 additions & 0 deletions test/unit/server/soroban/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ describe("Server#simulateTransaction", async function (done) {
retval: xdr.ScVal.fromXDR(simulationResponse.results[0].xdr, "base64"),
},
cost: simulationResponse.cost,
stateDiff: [{
type:1,
key: 'example-key',
before: new xdr.LedgerEntry({
lastModifiedLedgerSeq: 0,
ext: new xdr.LedgerEntryExt(0),
}),
after: new xdr.LedgerEntry({
lastModifiedLedgerSeq: 0,
ext: new xdr.LedgerEntryExt(0),
}),
}],
_parsed: true,
};

Expand Down Expand Up @@ -175,6 +187,7 @@ describe("Server#simulateTransaction", async function (done) {
delete expected.cost;
delete expected.transactionData;
delete expected.minResourceFee;
delete expected.stateDiff
expected.error = "This is an error";
expected.events = [];

Expand All @@ -200,6 +213,7 @@ function cloneSimulation(sim) {
retval: xdr.ScVal.fromXDR(sim.result.retval.toXDR()),
},
cost: sim.cost,
stateDiff: sim.stateDiff,
_parsed: sim._parsed,
};
}
Expand Down Expand Up @@ -262,6 +276,19 @@ function baseSimulationResponse(results) {
cpuInsns: "1",
memBytes: "2",
},
stateDiff:[{
type:1,
key: 'example-key',
before: new xdr.LedgerEntry({
lastModifiedLedgerSeq: 0,
ext: new xdr.LedgerEntryExt(0),
}).toXDR('base64'),
after: new xdr.LedgerEntry({
lastModifiedLedgerSeq: 0,
ext: new xdr.LedgerEntryExt(0),
}).toXDR('base64'),
}],

};
}

Expand Down

0 comments on commit ecaaa92

Please sign in to comment.