Skip to content

Commit

Permalink
test(simulator): Factorizing profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeAERGO committed Oct 30, 2023
1 parent ff1869a commit e8bd0d8
Showing 1 changed file with 27 additions and 105 deletions.
132 changes: 27 additions & 105 deletions packages/simulator/tests/simulator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import { WalletAPIClient } from "@ledgerhq/wallet-api-client";
import { getSimulatorTransport, profiles } from "../src";
import BigNumber from "bignumber.js";

const profileWithNoPermissions = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const profileWithUnhandledMethods = {
...profiles.STANDARD,
methods: {},
};

describe("Simulator", () => {
describe("bitcoin.getXPub", () => {
it("should return the xpub", async () => {
Expand All @@ -18,15 +31,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -37,12 +42,7 @@ describe("Simulator", () => {

it("should throw an error if method not handled by server", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
methods: {},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithUnhandledMethods);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -67,15 +67,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -100,15 +92,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -132,15 +116,7 @@ describe("Simulator", () => {
});

it("should throw an error if permission not granted", async () => {
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand Down Expand Up @@ -196,15 +172,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -228,15 +196,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);
const message = Buffer.from("Hello, world!", "utf-8");

Expand All @@ -248,12 +208,7 @@ describe("Simulator", () => {

it("should throw an error if method not handled by server", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
methods: {},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithUnhandledMethods);
const client = new WalletAPIClient(transport);
const message = Buffer.from("Hello, world!", "utf-8");

Expand Down Expand Up @@ -282,15 +237,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

const key = "testKey";
Expand All @@ -305,12 +252,7 @@ describe("Simulator", () => {

it("should throw an error if method not handled by server", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
methods: {},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithUnhandledMethods);
const client = new WalletAPIClient(transport);

const key = "testKey";
Expand Down Expand Up @@ -373,17 +315,10 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
await expect(
client.transaction.sign("accountId", transaction),
).rejects.toThrow("permission");
Expand Down Expand Up @@ -420,15 +355,7 @@ describe("Simulator", () => {

it("should throw an error if permission not granted", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
permissions: {
...profiles.STANDARD.permissions,
methodIds: [],
},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithNoPermissions);
const client = new WalletAPIClient(transport);

// THEN
Expand All @@ -437,12 +364,7 @@ describe("Simulator", () => {

it("should throw an error if method not handled by server", async () => {
// GIVEN
const profile = {
...profiles.STANDARD,
methods: {},
};

const transport = getSimulatorTransport(profile);
const transport = getSimulatorTransport(profileWithUnhandledMethods);
const client = new WalletAPIClient(transport);

// THEN
Expand Down

0 comments on commit e8bd0d8

Please sign in to comment.