Skip to content

Commit

Permalink
Release 1.4.12 (#184)
Browse files Browse the repository at this point in the history
* makes the simulate-tx endpoint follow response conventions of other simulate endpoint, renames parameter to be more clear, adds test for simulate-tx route (#183)

* Bump the minor-and-patch group with 10 updates (#187)

Bumps the minor-and-patch group with 10 updates:

| Package | From | To |
| --- | --- | --- |
| [@blockaid/client](https://github.com/blockaid-official/blockaid-client-node) | `0.29.1` | `0.31.0` |
| [@fastify/rate-limit](https://github.com/fastify/fastify-rate-limit) | `10.1.1` | `10.2.1` |
| [@sentry/node](https://github.com/getsentry/sentry-javascript) | `8.38.0` | `8.42.0` |
| [axios](https://github.com/axios/axios) | `1.7.7` | `1.7.9` |
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.9.0` | `22.10.1` |
| [dotenv](https://github.com/motdotla/dotenv) | `16.4.5` | `16.4.7` |
| [husky](https://github.com/typicode/husky) | `9.1.6` | `9.1.7` |
| [prettier](https://github.com/prettier/prettier) | `3.3.3` | `3.4.2` |
| [typescript](https://github.com/microsoft/TypeScript) | `5.6.3` | `5.7.2` |
| [webpack](https://github.com/webpack/webpack) | `5.96.1` | `5.97.1` |


Updates `@blockaid/client` from 0.29.1 to 0.31.0
- [Release notes](https://github.com/blockaid-official/blockaid-client-node/releases)
- [Changelog](https://github.com/blockaid-official/blockaid-client-node/blob/main/CHANGELOG.md)
- [Commits](blockaid-official/blockaid-client-node@v0.29.1...v0.31.0)

Updates `@fastify/rate-limit` from 10.1.1 to 10.2.1
- [Release notes](https://github.com/fastify/fastify-rate-limit/releases)
- [Commits](fastify/fastify-rate-limit@v10.1.1...v10.2.1)

Updates `@sentry/node` from 8.38.0 to 8.42.0
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md)
- [Commits](getsentry/sentry-javascript@8.38.0...8.42.0)

Updates `axios` from 1.7.7 to 1.7.9
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.7.7...v1.7.9)

Updates `@types/node` from 22.9.0 to 22.10.1
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Updates `dotenv` from 16.4.5 to 16.4.7
- [Changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md)
- [Commits](motdotla/dotenv@v16.4.5...v16.4.7)

Updates `husky` from 9.1.6 to 9.1.7
- [Release notes](https://github.com/typicode/husky/releases)
- [Commits](typicode/husky@v9.1.6...v9.1.7)

Updates `prettier` from 3.3.3 to 3.4.2
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](prettier/prettier@3.3.3...3.4.2)

Updates `typescript` from 5.6.3 to 5.7.2
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
- [Commits](microsoft/TypeScript@v5.6.3...v5.7.2)

Updates `webpack` from 5.96.1 to 5.97.1
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.96.1...v5.97.1)

---
updated-dependencies:
- dependency-name: "@blockaid/client"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: "@fastify/rate-limit"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: minor-and-patch
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: dotenv
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: minor-and-patch
- dependency-name: husky
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: minor-and-patch
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
- dependency-name: webpack
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: minor-and-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
aristidesstaffieri and dependabot[bot] authored Dec 11, 2024
1 parent 75f619a commit 7944b76
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 437 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"node": ">=18.12.0"
},
"dependencies": {
"@blockaid/client": "^0.29.1",
"@blockaid/client": "^0.31.0",
"@fastify/cors": "^10.0.1",
"@fastify/helmet": "^13.0.0",
"@fastify/rate-limit": "^10.1.1",
"@sentry/node": "^8.38.0",
"@fastify/rate-limit": "^10.2.1",
"@sentry/node": "^8.42.0",
"@stellar/js-xdr": "^3.1.2",
"@urql/core": "^5.0.8",
"ajv": "^8.17.0",
"axios": "^1.7.7",
"axios": "^1.7.9",
"dotenv-expand": "^12.0.1",
"fastify": "^5.1.0",
"ioredis": "^5.4.1",
Expand All @@ -52,19 +52,19 @@
"@babel/preset-typescript": "^7.26.0",
"@stellar/tsconfig": "^1.0.2",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@types/node": "^22.10.1",
"@types/yargs": "^17.0.33",
"babel-jest": "^29.7.0",
"dotenv": "^16.4.5",
"husky": "^9.1.5",
"dotenv": "^16.4.7",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"pretty-quick": "^4.0.0",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"webpack": "^5.96.1",
"typescript": "^5.7.2",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
}
Expand Down
3 changes: 3 additions & 0 deletions src/helper/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { NetworkNames } from "./validate";
import { hasIndexerSupport } from "./mercury";
import { BlockAidService } from "../service/blockaid";

export const TEST_SOROBAN_TX =
"AAAAAgAAAACM6IR9GHiRoVVAO78JJNksy2fKDQNs2jBn8bacsRLcrDucaFsAAAWIAAAAMQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABHkEVdJ+UfDnWpBr/qF582IEoDQ0iW0WPzO9CEUdvvh8AAAAIdHJhbnNmZXIAAAADAAAAEgAAAAAAAAAAjOiEfRh4kaFVQDu/CSTZLMtnyg0DbNowZ/G2nLES3KwAAAASAAAAAAAAAADoFl2ACT9HZkbCeuaT9MAIdStpdf58wM3P24nl738AnQAAAAoAAAAAAAAAAAAAAAAAAAAFAAAAAQAAAAAAAAAAAAAAAR5BFXSflHw51qQa/6hefNiBKA0NIltFj8zvQhFHb74fAAAACHRyYW5zZmVyAAAAAwAAABIAAAAAAAAAAIzohH0YeJGhVUA7vwkk2SzLZ8oNA2zaMGfxtpyxEtysAAAAEgAAAAAAAAAA6BZdgAk/R2ZGwnrmk/TACHUraXX+fMDNz9uJ5e9/AJ0AAAAKAAAAAAAAAAAAAAAAAAAABQAAAAAAAAABAAAAAAAAAAIAAAAGAAAAAR5BFXSflHw51qQa/6hefNiBKA0NIltFj8zvQhFHb74fAAAAFAAAAAEAAAAHa35L+/RxV6EuJOVk78H5rCN+eubXBWtsKrRxeLnnpRAAAAACAAAABgAAAAEeQRV0n5R8OdakGv+oXnzYgSgNDSJbRY/M70IRR2++HwAAABAAAAABAAAAAgAAAA8AAAAHQmFsYW5jZQAAAAASAAAAAAAAAACM6IR9GHiRoVVAO78JJNksy2fKDQNs2jBn8bacsRLcrAAAAAEAAAAGAAAAAR5BFXSflHw51qQa/6hefNiBKA0NIltFj8zvQhFHb74fAAAAEAAAAAEAAAACAAAADwAAAAdCYWxhbmNlAAAAABIAAAAAAAAAAOgWXYAJP0dmRsJ65pP0wAh1K2l1/nzAzc/bieXvfwCdAAAAAQBkcwsAACBwAAABKAAAAAAAAB1kAAAAAA==";

export const base64regex =
/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;

Expand Down
73 changes: 72 additions & 1 deletion src/route/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import * as StellarSdk from "stellar-sdk";
import "@blockaid/client";
import {
getDevServer,
queryMockResponse,
pubKey,
register,
TEST_SOROBAN_TX,
} from "../helper/test-helper";
import { transformAccountHistory } from "../service/mercury/helpers/transformers";
import { query } from "../service/mercury/queries";
import { defaultBenignResponse } from "../service/blockaid/helpers/addScanResults";
import { Networks } from "stellar-sdk-next";
import { SOROBAN_RPC_URLS } from "../helper/soroban-rpc";
import * as StellarHelpers from "../helper/stellar";

jest.mock("@blockaid/client", () => {
return class Blockaid {
Expand Down Expand Up @@ -99,7 +104,6 @@ describe("API routes", () => {
await server.close();
});
});

describe("/account-balances/:pubKey", () => {
it("can fetch account balances for a pub key & contract IDs", async () => {
const server = await getDevServer();
Expand Down Expand Up @@ -399,4 +403,71 @@ describe("API routes", () => {
await server.close();
});
});
describe("/simulate-tx", () => {
const simResponse = "simulated xdr";
const preparedTransaction = "assembled tx xdr";
let spy: any;

beforeEach(() => {
spy = jest
.spyOn(StellarHelpers, "getSdk")
.mockImplementation((_networkPassphrase: Networks) => {
return {
TransactionBuilder: {
fromXDR: (_xdr: string, _networkPassphrase: string) => "",
},
SorobanRpc: {
Server: class Server {
constructor(_url: string) {}
simulateTransaction = (_tx: string) => simResponse;
},
assembleTransaction: (
_tx: string,
_simulateTransaction: StellarSdk.rpc.Api.SimulateTransactionResponse,
) => {
return {
build: () => {
return {
toXDR: () => preparedTransaction,
};
},
};
},
},
} as any;
});
});

afterEach(() => {
spy.mockRestore(); // Restore original implementation for the other tests
});

it("can simulate a transaction", async () => {
const server = await getDevServer();
const url = new URL(
`http://localhost:${
(server?.server?.address() as any).port
}/api/v1/simulate-tx`,
);
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
xdr: TEST_SOROBAN_TX,
network_url: SOROBAN_RPC_URLS.TESTNET,
network_passphrase: Networks.TESTNET,
}),
};
const response = await fetch(url.href, options);
const data = await response.json();

expect(response.status).toEqual(200);
expect(data.simulationResponse).toEqual(simResponse);
expect(data.preparedTransaction).toEqual(preparedTransaction);
register.clear();
await server.close();
});
});
});
34 changes: 17 additions & 17 deletions src/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
buildTransfer,
getContractSpec,
getIsTokenSpec,
simulateTx,
isSacContractExecutable,
} from "../helper/soroban-rpc";
import { ERROR } from "../helper/error";
Expand Down Expand Up @@ -985,9 +984,9 @@ export async function initApiServer(
schema: {
body: {
type: "object",
required: ["signed_xdr", "network_url", "network_passphrase"],
required: ["xdr", "network_url", "network_passphrase"],
properties: {
signed_xdr: { type: "string" },
xdr: { type: "string" },
network_url: { type: "string" },
network_passphrase: { type: "string" },
},
Expand All @@ -996,33 +995,34 @@ export async function initApiServer(
handler: async (
request: FastifyRequest<{
Body: {
signed_xdr: string;
xdr: string;
network_url: string;
network_passphrase: string;
};
}>,
reply,
) => {
const { signed_xdr, network_url, network_passphrase } = request.body;
const { xdr, network_url, network_passphrase } = request.body;

try {
const Sdk = getSdk(network_passphrase as Networks);
const tx = Sdk.TransactionBuilder.fromXDR(
signed_xdr,
network_passphrase,
);
const tx = Sdk.TransactionBuilder.fromXDR(xdr, network_passphrase);
const server = new Sdk.SorobanRpc.Server(network_url);
const simulationResponse = await server.simulateTransaction(tx);
const preparedTransaction = Sdk.SorobanRpc.assembleTransaction(
tx,
simulationResponse,
)
.build()
.toXDR();

const data = await simulateTx<unknown>(
tx as StellarSdk.Transaction<
StellarSdk.Memo<StellarSdk.MemoType>,
StellarSdk.Operation[]
>,
server,
network_passphrase as Networks,
);
const data = {
simulationResponse,
preparedTransaction,
};
reply.code(200).send(data);
} catch (error) {
logger.error(JSON.stringify(error));
reply.code(400).send(JSON.stringify(error));
}
},
Expand Down
Loading

0 comments on commit 7944b76

Please sign in to comment.