@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
103 lines • 3.74 kB
JavaScript
;
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/cryptoassets/index");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const rxjs_1 = require("rxjs");
const index_2 = require("./index");
const utils_1 = require("./utils");
const tron = (0, index_1.getCryptoCurrencyById)("tron");
const defaultSyncConfig = {
paginationConfig: {},
blacklistedTokenIds: [],
};
function syncAccount(bridge, account, syncConfig = defaultSyncConfig) {
return (0, rxjs_1.firstValueFrom)(bridge.sync(account, syncConfig).pipe((0, rxjs_1.reduce)((a, f) => f(a), account)));
}
const dummyAccount = {
type: "Account",
id: "",
derivationMode: "",
seedIdentifier: "",
used: false,
currency: tron,
index: 0,
freshAddress: "",
freshAddressPath: "",
swapHistory: [],
blockHeight: 0,
balance: new bignumber_js_1.default(0),
spendableBalance: new bignumber_js_1.default(0),
operationsCount: 0,
operations: [],
pendingOperations: [],
lastSyncDate: new Date(0),
creationDate: new Date(),
balanceHistoryCache: {
HOUR: {
balances: [],
latestDate: undefined,
},
DAY: {
balances: [],
latestDate: undefined,
},
WEEK: {
balances: [],
latestDate: undefined,
},
},
tronResources: {},
};
describe("Sync Accounts", () => {
let bridge;
beforeAll(() => {
const signer = jest.fn();
const coinConfig = () => ({
status: {
type: "active",
},
explorer: {
url: "https://tron.coin.ledger.com",
},
});
bridge = (0, index_2.createBridges)(signer, coinConfig);
});
it("should always have tronResources", async () => {
const account = await syncAccount(bridge.accountBridge, dummyAccount, defaultSyncConfig);
expect(account.tronResources).toEqual(utils_1.defaultTronResources);
});
it.skip("should always be sync without error", async () => {
// GIVEN
const id = "TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre";
// WHEN
const account = await syncAccount(bridge.accountBridge, {
...dummyAccount,
id: `js:2:tron:${id}:`,
freshAddress: id,
});
// THEN
expect(account.id).toEqual(`js:2:tron:${id}:`);
expect(account.freshAddress).toEqual("TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre");
expect(account.operations[account.operations.length - 1]).toEqual({
accountId: "js:2:tron:TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre:",
blockHash: null,
blockHeight: 24725965,
date: new Date("2020-11-04T14:36:33.000Z"),
extra: {},
fee: new bignumber_js_1.default("0"),
hasFailed: false,
hash: "22f871f18d39b6c39e3c1495ba529169bee3fbefd59b504dac15becaff264920",
id: "js:2:tron:TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre:-22f871f18d39b6c39e3c1495ba529169bee3fbefd59b504dac15becaff264920-IN",
recipients: ["TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre"],
senders: ["TNDoSUL32A2KRqbEKXZQuPWgfBcA42sCwM"],
type: "IN",
value: new bignumber_js_1.default("11234560"),
});
const separator = "%2F";
expect(account.subAccounts[0].id).toEqual(`js:2:tron:TL24LCps5FKwp3PoU1MvrYrwhi5LU1tHre:+tron${separator}trc10${separator}1002000`);
});
});
//# sourceMappingURL=synchronization.integ.test.js.map