@ledgerhq/coin-casper
Version:
Ledger Casper integration
111 lines • 4.67 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 currencies_1 = require("@ledgerhq/cryptoassets/currencies");
const specs_1 = require("@ledgerhq/coin-framework/bot/specs");
const speculos_deviceActions_1 = require("./speculos-deviceActions");
const consts_1 = require("../consts");
const common_logic_1 = require("../common-logic");
const MIN_SAFE = new bignumber_js_1.default(consts_1.CASPER_MINIMUM_VALID_AMOUNT_MOTES * 2);
const maxAccount = 6;
const casperSpecs = {
name: "Casper",
currency: (0, currencies_1.getCryptoCurrencyById)("casper"),
appQuery: {
model: devices_1.DeviceModelId.nanoSP,
appName: "Casper",
appVersion: "3.0.7",
},
genericDeviceAction: speculos_deviceActions_1.acceptTransaction,
testTimeout: 6 * 60 * 1000,
minViableAmount: MIN_SAFE,
transactionCheck: ({ maxSpendable }) => {
(0, invariant_1.default)(maxSpendable.gt(MIN_SAFE), "balance is too low");
},
mutations: [
{
name: "Send ~50%",
feature: "send",
maxRun: 1,
testDestination: specs_1.genericTestDestination,
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({
transferId: (0, common_logic_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)));
if (transaction.transferId) {
(0, specs_1.botTest)("operation transferId", () => (0, expect_1.default)(operation.extra).toMatchObject({
transferId: transaction.transferId,
}));
}
},
},
{
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({
transferId: (0, common_logic_1.getRandomTransferID)(),
});
}
return {
transaction: bridge.createTransaction(account),
updates,
};
},
expectStatusWarnings: _ => {
return {
amount: consts_1.MayBlockAccountError,
};
},
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.transferId) {
(0, specs_1.botTest)("operation transferId", () => (0, expect_1.default)(operation.extra).toMatchObject({
transferId: transaction.transferId,
}));
}
},
},
],
};
exports.default = {
casperSpecs,
};
//# sourceMappingURL=bot-specs.js.map