Skip to content

Commit

Permalink
Update key type in LedgerEntryDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed May 13, 2024
1 parent 84eda50 commit 297525a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/soroban/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export namespace Api {

interface RawLedgerEntryDiff {
type: number;
// This is LedgerKey in base64
key: string;
// these are xdr.LedgerEntry in base64
before?: string;
Expand All @@ -186,7 +187,7 @@ export namespace Api {

interface LedgerEntryDiff{
type: number;
key: string;
key: xdr.LedgerKey;
before?: xdr.LedgerEntry;
after?: xdr.LedgerEntry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/soroban/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function parseSuccessful(
? sim.stateDiff!.map((entryDiff) => {
return {
type: entryDiff.type,
key: entryDiff.key,
key: xdr.LedgerKey.fromXDR(entryDiff.key, 'base64'),
before: !!entryDiff.before ? xdr.LedgerEntry.fromXDR(entryDiff.before, 'base64') : undefined,
after: !!entryDiff.after ? xdr.LedgerEntry.fromXDR(entryDiff.after, 'base64') : undefined,
};
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server/soroban/get_account_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Server#getAccount", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: { keys: [ key.toXDR("base64") ] },
params: { keys: [key.toXDR("base64")] },
})
.returns(
Promise.resolve({
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("Server#getAccount", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: { keys: [ key.toXDR("base64") ] },
params: { keys: [key.toXDR("base64")] },
})
.returns(
Promise.resolve({
Expand Down
8 changes: 4 additions & 4 deletions test/unit/server/soroban/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let getEventsResponseFixture = [
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c"
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c",
},
{
type: "contract",
Expand All @@ -258,7 +258,7 @@ let getEventsResponseFixture = [
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c"
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c",
},
{
type: "diagnostic",
Expand All @@ -270,7 +270,7 @@ let getEventsResponseFixture = [
inSuccessfulContractCall: true,
topic: [topicVals[0]],
value: eventVal,
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c"
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c",
},
{
type: "contract",
Expand All @@ -282,6 +282,6 @@ let getEventsResponseFixture = [
inSuccessfulContractCall: true,
topic: topicVals,
value: eventVal,
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c"
txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c",
},
];
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_ledger_entries_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Server#getLedgerEntries", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: {keys: requests},
params: { keys: requests },
})
.returns(
Promise.resolve({
Expand Down
55 changes: 29 additions & 26 deletions test/unit/server/soroban/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ 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),
}),
}],
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 @@ -187,7 +189,7 @@ describe("Server#simulateTransaction", async function (done) {
delete expected.cost;
delete expected.transactionData;
delete expected.minResourceFee;
delete expected.stateDiff
delete expected.stateDiff;
expected.error = "This is an error";
expected.events = [];

Expand Down Expand Up @@ -276,19 +278,20 @@ 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'),
}],

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 297525a

Please sign in to comment.