UNPKG

@ledgerhq/live-common

Version:
67 lines 2.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("@ledgerhq/coin-framework/currencies/index"); const currencies_1 = require("@ledgerhq/cryptoassets/currencies"); const devices_1 = require("@ledgerhq/devices"); const specs_1 = require("@ledgerhq/ledger-wallet-framework/bot/specs"); const expect_1 = __importDefault(require("expect")); const invariant_1 = __importDefault(require("invariant")); const deviceActions_1 = require("./deviceActions"); const currency = (0, currencies_1.getCryptoCurrencyById)("ripple"); const minAmountCutoff = (0, index_1.parseCurrencyUnit)(currency.units[0], "0.1"); const reserve = (0, index_1.parseCurrencyUnit)(currency.units[0], "20"); const xrp = { name: "XRP", currency, appQuery: { model: devices_1.DeviceModelId.nanoS, appName: "XRP", }, genericDeviceAction: deviceActions_1.acceptTransaction, minViableAmount: minAmountCutoff, mutations: [ { name: "move ~50%", feature: "send", maxRun: 1, testDestination: specs_1.genericTestDestination, transaction: ({ account, siblings, bridge, maxSpendable }) => { (0, invariant_1.default)(maxSpendable.gt(minAmountCutoff), "balance is too low"); const transaction = bridge.createTransaction(account); const sibling = (0, specs_1.pickSiblings)(siblings, 3); const recipient = sibling.freshAddress; let amount = maxSpendable.div(1.9 + 0.2 * Math.random()).integerValue(); if (!sibling.used && amount.lt(reserve)) { (0, invariant_1.default)(maxSpendable.gt(reserve.plus(minAmountCutoff)), "not enough funds to send to new account"); amount = reserve; } return { transaction, updates: [ { amount, }, { recipient, }, Math.random() > 0.5 ? { tag: 123, } : null, ], }; }, test: ({ account, accountBeforeTransaction, operation }) => { (0, specs_1.botTest)("account balance moved with operation.value", () => (0, expect_1.default)(account.balance.toString()).toBe(accountBeforeTransaction.balance.minus(operation.value).toString())); }, }, ], }; exports.default = { xrp, }; //# sourceMappingURL=specs.js.map