Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed May 29, 2024
1 parent 7698a58 commit 4727249
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export namespace Api {
value: string;
}

export interface RawLedgerEntryChange {
interface RawLedgerEntryChange {
type: number;
/** This is LedgerKey in base64 */
key: string;
Expand Down
45 changes: 37 additions & 8 deletions test/unit/server/soroban/simulate_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -316,6 +324,8 @@ function simulationResponseError(events) {
}

function baseSimulationResponse(results) {
const accountId = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";

return {
id: 1,
events: [],
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit 4727249

Please sign in to comment.