diff --git a/CHANGELOG.md b/CHANGELOG.md index a491aad86..9176304d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,23 @@ A breaking change will get clearly marked in this log. Added: -- Add stateChanges in SimulateTransaction API response ([#963](https://github.com/stellar/js-stellar-sdk/pull/963)) +- `rpc.server.simulateTransaction` now supports optional stateChanges as mentioned below ([#963](https://github.com/stellar/js-stellar-sdk/pull/963)) +- If `Before` is omitted, it constitutes a creation, if `After` is omitted, it constitutes a deletions, note that `Before` and `After` cannot be be omitted at the same time. +``` +/** State Difference information */ + stateChanges?: LedgerEntryChange[]; + +interface LedgerEntryChange{ + type: number; + key: xdr.LedgerKey; + before: xdr.LedgerEntry | null; + after: xdr.LedgerEntry | null; + } + +``` + ## [v12.0.0-rc.3](https://github.com/stellar/js-stellar-sdk/compare/v11.3.0...v12.0.0-rc.3) ### Breaking Changes diff --git a/src/rpc/api.ts b/src/rpc/api.ts index cbfb8e442..0ec813c08 100644 --- a/src/rpc/api.ts +++ b/src/rpc/api.ts @@ -168,7 +168,7 @@ export namespace Api { value: string; } - export interface RawLedgerEntryChange { + interface RawLedgerEntryChange { type: number; /** This is LedgerKey in base64 */ key: string; diff --git a/test/unit/server/soroban/simulate_transaction_test.js b/test/unit/server/soroban/simulate_transaction_test.js index 55de24a89..863ad6b13 100644 --- a/test/unit/server/soroban/simulate_transaction_test.js +++ b/test/unit/server/soroban/simulate_transaction_test.js @@ -18,6 +18,14 @@ describe("Server#simulateTransaction", async function (done) { let contract = new StellarSdk.Contract(contractId); let address = contract.address().toScAddress(); + const accountId = + "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI"; + const accountKey = xdr.LedgerKey.account( + new xdr.LedgerKeyAccount({ + accountId: Keypair.fromPublicKey(accountId).xdrPublicKey(), + }), + ); + const simulationResponse = await invokeSimulationResponse(address); const parsedSimulationResponse = { id: simulationResponse.id, @@ -35,7 +43,7 @@ describe("Server#simulateTransaction", async function (done) { stateChanges: [ { type: 2, - key: "example-key-2", + key: accountKey, before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(), @@ -189,7 +197,7 @@ describe("Server#simulateTransaction", async function (done) { expected.stateChanges = [ { type: 2, - key: "example-key-2", + key: accountKey, before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(), @@ -203,7 +211,7 @@ describe("Server#simulateTransaction", async function (done) { }, { type: 1, - key: "example-key-1", + key: accountKey, before: null, after: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, @@ -213,7 +221,7 @@ describe("Server#simulateTransaction", async function (done) { }, { type: 3, - key: "example-key-3", + key: accountKey, before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(), @@ -316,6 +324,8 @@ function simulationResponseError(events) { } function baseSimulationResponse(results) { + const accountId = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI"; + return { id: 1, events: [], @@ -330,7 +340,11 @@ function baseSimulationResponse(results) { stateChanges: [ { type: 2, - key: "example-key-2", + key: xdr.LedgerKey.account( + new xdr.LedgerKeyAccount({ + accountId: Keypair.fromPublicKey(accountId).xdrPublicKey(), + }), + ).toXDR("base64"), before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(), @@ -357,12 +371,19 @@ async function invokeSimulationResponseWithRestoration(address) { } async function invokeSimulationResponseWithStateChanges(address) { + const accountId = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI"; + return { + ...(await invokeSimulationResponse(address)), stateChanges: [ { type: 2, - key: "example-key-2", + key: xdr.LedgerKey.account( + new xdr.LedgerKeyAccount({ + accountId: Keypair.fromPublicKey(accountId).xdrPublicKey(), + }), + ).toXDR("base64"), before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(), @@ -376,7 +397,11 @@ async function invokeSimulationResponseWithStateChanges(address) { }, { type: 1, - key: "example-key-1", + key: xdr.LedgerKey.account( + new xdr.LedgerKeyAccount({ + accountId: Keypair.fromPublicKey(accountId).xdrPublicKey(), + }), + ).toXDR("base64"), before: null, after: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, @@ -386,7 +411,11 @@ async function invokeSimulationResponseWithStateChanges(address) { }, { type: 3, - key: "example-key-3", + key: xdr.LedgerKey.account( + new xdr.LedgerKeyAccount({ + accountId: Keypair.fromPublicKey(accountId).xdrPublicKey(), + }), + ).toXDR("base64"), before: new xdr.LedgerEntry({ lastModifiedLedgerSeq: 0, data: new xdr.LedgerEntryData(),