@ledgerhq/ledger-trust-service
Version:
Ledger Trust service client
106 lines • 4.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const solana_1 = require("./solana");
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
jest.mock("@ledgerhq/live-network");
describe("solana", () => {
beforeEach(() => {
jest.resetModules();
jest.clearAllMocks();
});
describe("getOwnerAddress", () => {
it.each([
["prod", "https://nft.api.live.ledger.com"],
[undefined, "https://nft.api.live.ledger.com"],
["test", "https://nft.api.live.ledger-test.com"],
])("fetch the correct %s service environement", async (env, baseUrl) => {
// Given
const ownerAddress = "SOL_ADDR";
const challenge = "WHATEVER_CHALLENGE";
const mockResponse = {};
live_network_1.default.mockResolvedValue({ data: mockResponse });
// When
await (0, solana_1.getOwnerAddress)(ownerAddress, challenge, env);
// Then
expect(live_network_1.default).toHaveBeenCalledWith({
method: "GET",
url: `${baseUrl}/v2/solana/owner/${ownerAddress}?challenge=${challenge}`,
});
});
it("transforms data as expected", async () => {
// Given
const ownerAddress = "SOL_ADDR";
const challenge = "WHATEVER_CHALLENGE";
const mintAddress = "MINT_ADDR";
const tokenAddress = "TOKEN_ADDR";
const mockResponse = {
descriptorType: "TrustedName",
descriptorVersion: 2,
tokenAccount: tokenAddress,
owner: ownerAddress,
contract: mintAddress,
signedDescriptor: "SIGNATURE",
};
live_network_1.default.mockResolvedValue({ data: mockResponse });
// When
const result = await (0, solana_1.getOwnerAddress)(ownerAddress, challenge);
// Then
expect(result).toEqual({
contract: mintAddress,
owner: ownerAddress,
tokenAccount: tokenAddress,
signedDescriptor: "SIGNATURE",
});
});
});
describe("computedTokenAddress", () => {
it.each([
["prod", "https://nft.api.live.ledger.com"],
[undefined, "https://nft.api.live.ledger.com"],
["test", "https://nft.api.live.ledger-test.com"],
])("fetch the correct %s service environement", async (env, baseUrl) => {
// Given
const ownerAddress = "SOL_ADDR";
const mintAddress = "MINT_ADDR";
const challenge = "WHATEVER_CHALLENGE";
const mockResponse = {};
live_network_1.default.mockResolvedValue({ data: mockResponse });
// When
await (0, solana_1.computedTokenAddress)(ownerAddress, mintAddress, challenge, env);
// Then
expect(live_network_1.default).toHaveBeenCalledWith({
method: "GET",
url: `${baseUrl}/v2/solana/computed-token-account/${ownerAddress}/${mintAddress}?challenge=${challenge}`,
});
});
it("transforms data as expected", async () => {
// Given
const ownerAddress = "SOL_ADDR";
const challenge = "WHATEVER_CHALLENGE";
const mintAddress = "MINT_ADDR";
const tokenAddress = "TOKEN_ADDR";
const mockResponse = {
descriptorType: "TrustedName",
descriptorVersion: 2,
tokenAccount: tokenAddress,
owner: ownerAddress,
contract: mintAddress,
signedDescriptor: "SIGNATURE",
};
live_network_1.default.mockResolvedValue({ data: mockResponse });
// When
const result = await (0, solana_1.computedTokenAddress)(ownerAddress, mintAddress, challenge);
// Then
expect(result).toEqual({
contract: mintAddress,
owner: ownerAddress,
tokenAccount: tokenAddress,
signedDescriptor: "SIGNATURE",
});
});
});
});
//# sourceMappingURL=solana.test.js.map