diff --git a/src/api/checkAddress.test.ts b/src/api/checkAddress.test.ts index ddc2744..4b2c1f9 100644 --- a/src/api/checkAddress.test.ts +++ b/src/api/checkAddress.test.ts @@ -21,6 +21,7 @@ describe("Function: checkAddress", () => { const mockResponse = { status: "ok", data: true, + coint: "arionum", }; let requestUrl = ""; @@ -55,6 +56,7 @@ describe("Function: checkAddress", () => { const mockResponse = { status: "ok", data: false, + coint: "arionum", }; let requestUrl = ""; diff --git a/src/api/checkSignature.test.ts b/src/api/checkSignature.test.ts index 315eebd..142c909 100644 --- a/src/api/checkSignature.test.ts +++ b/src/api/checkSignature.test.ts @@ -21,6 +21,7 @@ describe("Function: checkSignature", () => { const mockResponse = { status: "ok", data: true, + coint: "arionum", }; let requestUrl = ""; @@ -64,6 +65,7 @@ describe("Function: checkSignature", () => { const mockResponse = { status: "ok", data: false, + coint: "arionum", }; let requestUrl = ""; diff --git a/src/api/getAlias.test.ts b/src/api/getAlias.test.ts new file mode 100644 index 0000000..3f18fc9 --- /dev/null +++ b/src/api/getAlias.test.ts @@ -0,0 +1,84 @@ +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; + +import { buildNodeConfiguration } from "../utils/public"; +import { getAlias } from "./getAlias"; + +const server = setupServer(); + +describe("Function: getAlias", () => { + // MSW Setup + beforeAll(() => server.listen()); + afterEach(() => server.resetHandlers()); + afterAll(() => server.close()); + + it("returns alias for address", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "PXGAMER", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getAlias(nodeConfiguration, { + address: + "51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J", + }); + + // ASSERT + expect(requestUrl).toContain( + "account=51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J", + ); + + expect(response).toEqual("PXGAMER"); + }); + + it("returns alias with public key validation", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "PXGAMER", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getAlias(nodeConfiguration, { + publicKey: + "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4", + }); + + // ASSERT + expect(requestUrl).toContain( + "public_key=PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4", + ); + + expect(response).toEqual("PXGAMER"); + }); +}); diff --git a/src/api/getAlias.ts b/src/api/getAlias.ts index bb1b080..712a3e9 100644 --- a/src/api/getAlias.ts +++ b/src/api/getAlias.ts @@ -4,7 +4,7 @@ import { call } from "../utils/internal"; export const getAlias = async ( nodeConfiguration: NodeConfiguration, - payload: { address: string; publicKey?: string }, + payload: { address?: string; publicKey?: string }, ): Promise => { const { address, publicKey } = payload; diff --git a/src/api/getAssetBalance.test.ts b/src/api/getAssetBalance.test.ts new file mode 100644 index 0000000..e6a4f16 --- /dev/null +++ b/src/api/getAssetBalance.test.ts @@ -0,0 +1,166 @@ +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; + +import { buildNodeConfiguration } from "../utils/public"; +import { getAssetBalance } from "./getAssetBalance"; + +const server = setupServer(); + +describe("Function: getAssetBalance", () => { + // MSW Setup + beforeAll(() => server.listen()); + afterEach(() => server.resetHandlers()); + afterAll(() => server.close()); + + it("returns asset balances for asset", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: [ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + account: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ], + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getAssetBalance(nodeConfiguration, { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + }); + + // ASSERT + expect(requestUrl).toContain( + "asset=63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + ); + + expect(response).toEqual([ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + address: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ]); + }); + + it("returns asset balances for account", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: [ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + account: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ], + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getAssetBalance(nodeConfiguration, { + address: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + }); + + // ASSERT + expect(requestUrl).toContain( + "account=2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + ); + + expect(response).toEqual([ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + address: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ]); + }); + + it("returns asset balances for public key", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: [ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + account: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ], + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getAssetBalance(nodeConfiguration, { + publicKey: + "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m", + }); + + // ASSERT + expect(requestUrl).toContain( + "public_key=PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m", + ); + + expect(response).toEqual([ + { + asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE", + alias: "AUOS", + address: + "2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5", + balance: 1234, + }, + ]); + }); +}); diff --git a/src/api/getBalance.test.ts b/src/api/getBalance.test.ts new file mode 100644 index 0000000..3a01301 --- /dev/null +++ b/src/api/getBalance.test.ts @@ -0,0 +1,116 @@ +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; + +import { buildNodeConfiguration } from "../utils/public"; +import { getBalance } from "./getBalance"; + +const server = setupServer(); + +describe("Function: getBalance", () => { + // MSW Setup + beforeAll(() => server.listen()); + afterEach(() => server.resetHandlers()); + afterAll(() => server.close()); + + it("returns the balance for an account", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "12345", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getBalance(nodeConfiguration, { + address: + "51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J", + }); + + // ASSERT + expect(requestUrl).toContain( + "account=51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J", + ); + + expect(response).toEqual("12345"); + }); + + it("returns the balance for a public key", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "12345", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getBalance(nodeConfiguration, { + publicKey: + "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m", + }); + + // ASSERT + expect(requestUrl).toContain( + "public_key=PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m", + ); + + expect(response).toEqual("12345"); + }); + + it("returns the balance for an alias", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "12345", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getBalance(nodeConfiguration, { + alias: "PXGAMER", + }); + + // ASSERT + expect(requestUrl).toContain("alias=PXGAMER"); + + expect(response).toEqual("12345"); + }); +}); diff --git a/src/api/getBase58.test.ts b/src/api/getBase58.test.ts new file mode 100644 index 0000000..9729eeb --- /dev/null +++ b/src/api/getBase58.test.ts @@ -0,0 +1,46 @@ +import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; + +import { buildNodeConfiguration } from "../utils/public"; +import { getBase58 } from "./getBase58"; + +const server = setupServer(); + +describe("Function: getBase58", () => { + // MSW Setup + beforeAll(() => server.listen()); + afterEach(() => server.resetHandlers()); + afterAll(() => server.close()); + + it("returns a Base 58 encoded string", async () => { + // ARRANGE + const nodeConfiguration = buildNodeConfiguration({ + url: "http://localhost", + }); + + const mockResponse = { + status: "ok", + data: "3yZe7d", + coin: "arionum", + }; + + let requestUrl = ""; + + server.use( + http.get(`http://localhost/api.php`, (info) => { + requestUrl = info.request.url; + return HttpResponse.json(mockResponse); + }), + ); + + // ACT + const response = await getBase58(nodeConfiguration, { + data: "test", + }); + + // ASSERT + expect(requestUrl).toContain("data=test"); + + expect(response).toEqual("3yZe7d"); + }); +});