UNPKG

@ledgerhq/coin-canton

Version:
206 lines 10.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.dataset = exports.mockPublicKeys = exports.mockCantonAddresses = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); const errors_1 = require("@ledgerhq/errors"); const transaction_1 = require("../bridge/transaction"); const accountId_1 = require("@ledgerhq/coin-framework/lib/account/accountId"); // Mock Canton addresses using SECP256R1-compatible format exports.mockCantonAddresses = { sender: "canton_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z", recipient1: "canton_2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a", recipient2: "canton_3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b", invalid: "invalid_canton_address", }; // Mock public keys (SECP256R1 uncompressed format) exports.mockPublicKeys = { sender: "0x04" + "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" + "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", recipient1: "0x04" + "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" + "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd", }; const mainAccId = (0, accountId_1.encodeAccountId)({ type: "js", version: "2", currencyId: "canton_network", xpubOrAddress: exports.mockCantonAddresses.sender, derivationMode: "", }); const fees = new bignumber_js_1.default("1000"); const zero = new bignumber_js_1.default(0); const canton = { implementations: ["mock"], currencies: { canton_network: { scanAccounts: [ { name: "canton seed 1", unstableAccounts: true, apdus: ` => e00200400d038000002c8000009080000000 <= 2103c73f64083463fa923e1530af6f558204853873c6a45cbfb1f2f1e2ac2a5d989c2272734a4675764165634c333153513750594864504b6b3335625a456f78446d5231789000 => e002004015058000002c80000090800000000000000000000000 <= 2103d1adcff3e0cf1232b1416a75cd6f23b49dd6a25c69bc291a1f6783ec6825ec062272616765584842365134566276765764547a4b414e776a65435434485846434b58379000 => e002004015058000002c80000090800000010000000000000000 <= 21036da109ee84825eab0f55fb57bcf9ef0b05621e71fb0400266fb42d6f68f9487c2272425065393169766d67384347573450414e6f657555555173756d337470786a55469000 => e002004015058000002c80000090800000020000000000000000 <= 2102df9a55b79fb3668dac70fee7372806195841cd713ab8da9fba82240f9db8a23921725a76426335653259523141396f745333723944794768334e445038584c4c70349000 `, }, ], accounts: [ { raw: { id: mainAccId, seedIdentifier: exports.mockCantonAddresses.sender, name: "Canton 1", derivationMode: "", index: 0, freshAddress: exports.mockCantonAddresses.sender, freshAddressPath: "44'/6767'/0'/0'/0'", blockHeight: 12345, operations: [], pendingOperations: [], currencyId: "canton_network", lastSyncDate: "2024-01-01T00:00:00.000Z", balance: "1000000000", // 1000 CANTON spendableBalance: "999999000", // 999.999 CANTON (reserving 1000 for fees) subAccounts: [], }, transactions: [ // Basic transaction tests { name: "recipient and sender must not be the same", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.sender, amount: "10000000", fee: "1000", }), expectedStatus: { amount: new bignumber_js_1.default("10000000"), estimatedFees: fees, errors: { recipient: new errors_1.InvalidAddressBecauseDestinationIsAlsoSource(), }, warnings: {}, totalSpent: new bignumber_js_1.default("10001000"), }, }, { name: "valid transaction with sufficient balance", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.recipient1, amount: "10000000", // 10 CANTON fee: "1000", }), expectedStatus: { amount: new bignumber_js_1.default("10000000"), estimatedFees: fees, errors: {}, warnings: {}, totalSpent: new bignumber_js_1.default("10001000"), }, }, { name: "transaction with insufficient balance", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.recipient1, amount: "2000000000", // 2000 CANTON (more than balance) fee: "1000", }), expectedStatus: { amount: new bignumber_js_1.default("2000000000"), estimatedFees: fees, errors: { amount: new errors_1.NotEnoughBalance(), }, warnings: {}, totalSpent: new bignumber_js_1.default("20001000"), }, }, { name: "transaction with invalid recipient address", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.invalid, amount: "10000000", fee: "1000", }), expectedStatus: { amount: new bignumber_js_1.default("10000000"), estimatedFees: fees, errors: { recipient: new errors_1.InvalidAddress(), }, warnings: {}, totalSpent: new bignumber_js_1.default("10001000"), }, }, { name: "transaction with zero amount", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.recipient1, amount: "0", fee: "1000", }), expectedStatus: { amount: zero, estimatedFees: fees, errors: { amount: new errors_1.AmountRequired(), }, warnings: {}, totalSpent: fees, }, }, { name: "transaction with empty recipient", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: "", amount: "10000000", fee: "1000", }), expectedStatus: { amount: new bignumber_js_1.default("10000000"), estimatedFees: fees, errors: { recipient: new errors_1.RecipientRequired(), }, warnings: {}, totalSpent: new bignumber_js_1.default("10001000"), }, }, { name: "transaction with high fee", transaction: (0, transaction_1.fromTransactionRaw)({ family: "canton", recipient: exports.mockCantonAddresses.recipient1, amount: "10000000", fee: "50000", // 50 CANTON fee }), expectedStatus: { amount: new bignumber_js_1.default("10000000"), estimatedFees: new bignumber_js_1.default("50000"), errors: {}, warnings: {}, totalSpent: new bignumber_js_1.default("10050000"), }, }, ], }, ], }, }, }; exports.dataset = canton; //# sourceMappingURL=bridgeDatasetTest.js.map