Local Testing Setup of Ledger-Live (TypeScript/JS)

in tron •  3 years ago 

Repo: https://github.com/LedgerHQ/ledger-live

Background

Cloned the repo, made some changes, and wanted to test the hw-app-trx with the local modified version using the following script:

const AppTrx = require("@ledgerhq/hw-app-trx").default;
const Transport = require('@ledgerhq/hw-transport-node-hid').default;
const TronWeb = require('tronweb');
const account = "";
const fromAcc = "";
const toAcc = ""

const tronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
    privateKey: ''
});

(async function() {
    console.log('supported:', await Transport.isSupported());
    console.log('Devices:');
    console.log(await Transport.list());
    const transport = await Transport.create();
    const tronApp = new AppTrx(transport);
    const tradeobj = await tronWeb.transactionBuilder.sendTrx(fromAcc, 1, toAcc);
    const signature = await tronApp.signTransaction("44'/195'/0'/0/0", tradeobj.raw_data_hex, [], 105);
})();

Solution

test.js is not really related to the local hw-app-trx unless we link it with pnpm.

By simpling doing node test.js wewill run the script without any compilation of the package, that's why the require won't find any package e.g. tronweb.

We can try by adding a test on it and try to run

1 - first add to your hw-app-trx/package.json in theses dependencies

  "dependencies": {
    "@ledgerhq/errors": "workspace:^",
    "@ledgerhq/hw-transport": "workspace:^",
    "@ledgerhq/hw-transport-node-hid": "workspace:^",
    "tronweb": "4.3.0"
  },
  "devDependencies": {
    "@ledgerhq/hw-transport-mocker": "workspace:^"
  },

2 - then do a pnpm i
it will install the missing depencies

3 - change the Trx.test.ts

import Trx from "../src/Trx";
import Transport from "@ledgerhq/hw-transport-node-hid";

test("getAppConfiguration", async () => {
  console.log(await Transport.list());
  const transport = await Transport.create();
  const tronApp = new Trx(transport);
})

we should be able to test your modification starting with this

4 - pnpm ljs:hw-app-trx test will help run the code

Tutorial by https://steemyy.com

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!