From 297525ac3bd6c0ff6cb515e8769676bcc17123f0 Mon Sep 17 00:00:00 2001 From: pritsheth Date: Mon, 13 May 2024 09:28:36 -0700 Subject: [PATCH] Update key type in LedgerEntryDiff --- src/soroban/api.ts | 3 +- src/soroban/parsers.ts | 2 +- test/unit/server/soroban/get_account_test.js | 4 +- test/unit/server/soroban/get_events_test.js | 8 +-- .../server/soroban/get_ledger_entries_test.js | 2 +- .../soroban/simulate_transaction_test.js | 55 ++++++++++--------- 6 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/soroban/api.ts b/src/soroban/api.ts index af73abb61..75f9e4a1c 100644 --- a/src/soroban/api.ts +++ b/src/soroban/api.ts @@ -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; @@ -186,7 +187,7 @@ export namespace Api { interface LedgerEntryDiff{ type: number; - key: string; + key: xdr.LedgerKey; before?: xdr.LedgerEntry; after?: xdr.LedgerEntry; } diff --git a/src/soroban/parsers.ts b/src/soroban/parsers.ts index b734632b5..61d5740db 100644 --- a/src/soroban/parsers.ts +++ b/src/soroban/parsers.ts @@ -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, }; diff --git a/test/unit/server/soroban/get_account_test.js b/test/unit/server/soroban/get_account_test.js index b6781f76c..8258291d3 100644 --- a/test/unit/server/soroban/get_account_test.js +++ b/test/unit/server/soroban/get_account_test.js @@ -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({ @@ -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({ diff --git a/test/unit/server/soroban/get_events_test.js b/test/unit/server/soroban/get_events_test.js index 8b3f4f8e7..f6de7132d 100644 --- a/test/unit/server/soroban/get_events_test.js +++ b/test/unit/server/soroban/get_events_test.js @@ -246,7 +246,7 @@ let getEventsResponseFixture = [ inSuccessfulContractCall: true, topic: topicVals.slice(0, 2), value: eventVal, - txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c" + txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c", }, { type: "contract", @@ -258,7 +258,7 @@ let getEventsResponseFixture = [ inSuccessfulContractCall: true, topic: topicVals.slice(0, 2), value: eventVal, - txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c" + txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c", }, { type: "diagnostic", @@ -270,7 +270,7 @@ let getEventsResponseFixture = [ inSuccessfulContractCall: true, topic: [topicVals[0]], value: eventVal, - txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c" + txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c", }, { type: "contract", @@ -282,6 +282,6 @@ let getEventsResponseFixture = [ inSuccessfulContractCall: true, topic: topicVals, value: eventVal, - txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c" + txHash: "d7d09af2ca4f2929ee701cf86d05e4ca5f849a726d0db344785a8f9894e79e6c", }, ]; diff --git a/test/unit/server/soroban/get_ledger_entries_test.js b/test/unit/server/soroban/get_ledger_entries_test.js index cf11dc5f3..4adda2d3c 100644 --- a/test/unit/server/soroban/get_ledger_entries_test.js +++ b/test/unit/server/soroban/get_ledger_entries_test.js @@ -44,7 +44,7 @@ describe("Server#getLedgerEntries", function () { jsonrpc: "2.0", id: 1, method: "getLedgerEntries", - params: {keys: requests}, + params: { keys: requests }, }) .returns( Promise.resolve({ diff --git a/test/unit/server/soroban/simulate_transaction_test.js b/test/unit/server/soroban/simulate_transaction_test.js index 87f6f8bbe..2bff0ff88 100644 --- a/test/unit/server/soroban/simulate_transaction_test.js +++ b/test/unit/server/soroban/simulate_transaction_test.js @@ -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, }; @@ -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 = []; @@ -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"), + }, + ], }; }