@ledgerhq/coin-mina
Version:
107 lines • 4.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const invariant_1 = __importDefault(require("invariant"));
const devices_1 = require("@ledgerhq/devices");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const expect_1 = __importDefault(require("expect"));
const specs_1 = require("@ledgerhq/coin-framework/bot/specs");
const bot_deviceActions_1 = require("./bot-deviceActions");
const index_1 = require("@ledgerhq/cryptoassets/index");
const testUtils_1 = require("./testUtils");
const maxAccount = 6;
// 0.1 MINA
const MIN_SAFE = new bignumber_js_1.default(1 * 10 ** 8);
const minaSpecs = {
name: "Mina",
currency: (0, index_1.getCryptoCurrencyById)("mina"),
appQuery: {
model: devices_1.DeviceModelId.nanoS,
appName: "Mina",
},
genericDeviceAction: bot_deviceActions_1.acceptTransaction,
testTimeout: 15 * 60 * 1000,
minViableAmount: MIN_SAFE,
transactionCheck: ({ maxSpendable }) => {
(0, invariant_1.default)(maxSpendable.gt(MIN_SAFE), "balance is too low");
},
mutations: [
{
name: "Send ~50% to another account",
maxRun: 1,
testDestination: specs_1.genericTestDestination,
feature: "send",
transaction: ({ account, siblings, bridge, maxSpendable }) => {
(0, invariant_1.default)(maxSpendable.gt(MIN_SAFE), "balance is too low");
const sibling = (0, specs_1.pickSiblings)(siblings, maxAccount);
const recipient = sibling.freshAddress;
const amount = maxSpendable.div(2).integerValue();
const transaction = bridge.createTransaction(account);
const updates = [
{
recipient,
},
{ amount },
];
if (Math.random() < 0.5) {
updates.push({
memo: (0, testUtils_1.getRandomTransferID)(),
});
}
return {
transaction,
updates,
};
},
test: ({ accountBeforeTransaction, operation, account, transaction, }) => {
(0, specs_1.botTest)("account spendable balance decreased with operation", () => (0, expect_1.default)(account.spendableBalance).toEqual(accountBeforeTransaction.spendableBalance
.minus(operation.value)
.minus(operation.extra.accountCreationFee)));
if (transaction.memo) {
(0, specs_1.botTest)("operation memo", () => (0, expect_1.default)(operation.extra).toMatchObject({
memo: transaction.memo,
}));
}
},
},
{
name: "Transfer Max",
feature: "sendMax",
maxRun: 1,
transaction: ({ account, siblings, bridge }) => {
const updates = [
{
recipient: (0, specs_1.pickSiblings)(siblings, maxAccount).freshAddress,
},
{
useAllAmount: true,
},
];
if (Math.random() < 0.5) {
updates.push({
memo: (0, testUtils_1.getRandomTransferID)(),
});
}
return {
transaction: bridge.createTransaction(account),
updates,
};
},
testDestination: specs_1.genericTestDestination,
test: ({ account, transaction, operation }) => {
(0, specs_1.botTest)("account spendable balance is zero", () => (0, expect_1.default)(account.spendableBalance.toString()).toBe("0"));
if (transaction.memo) {
(0, specs_1.botTest)("operation memo", () => (0, expect_1.default)(operation.extra).toMatchObject({
memo: transaction.memo,
}));
}
},
},
],
};
exports.default = {
minaSpecs,
};
//# sourceMappingURL=bot-specs.js.map