@ledgerhq/coin-tester 0.2.0-nightly.4 → 0.2.1-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +13 -4
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +12 -22
- package/README.md +63 -12
- package/docker-compose.yml +2 -4
- package/lib/main.d.ts +16 -8
- package/lib/main.d.ts.map +1 -1
- package/lib/main.js +36 -30
- package/lib/main.js.map +1 -1
- package/lib/signers/speculos.d.ts +3 -4
- package/lib/signers/speculos.d.ts.map +1 -1
- package/lib/signers/speculos.js +108 -53
- package/lib/signers/speculos.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib-es/main.d.ts +16 -8
- package/lib-es/main.d.ts.map +1 -1
- package/lib-es/main.js +36 -30
- package/lib-es/main.js.map +1 -1
- package/lib-es/signers/speculos.d.ts +3 -4
- package/lib-es/signers/speculos.d.ts.map +1 -1
- package/lib-es/signers/speculos.js +84 -52
- package/lib-es/signers/speculos.js.map +1 -1
- package/lib-es/types.d.ts +1 -1
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/main.ts +33 -17
- package/src/signers/speculos.ts +70 -39
- package/src/types.ts +1 -1
package/.eslintrc.js
CHANGED
|
@@ -4,6 +4,10 @@ module.exports = {
|
|
|
4
4
|
es6: true,
|
|
5
5
|
},
|
|
6
6
|
ignorePatterns: ["lib", "lib-es", ".turbo"],
|
|
7
|
+
rules: {
|
|
8
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
9
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
10
|
+
},
|
|
7
11
|
overrides: [
|
|
8
12
|
{
|
|
9
13
|
files: ["src/**/*.test.{ts,tsx}"],
|
|
@@ -12,9 +16,14 @@ module.exports = {
|
|
|
12
16
|
},
|
|
13
17
|
plugins: ["jest"],
|
|
14
18
|
},
|
|
19
|
+
{
|
|
20
|
+
// allow, as warning, only in tests
|
|
21
|
+
files: ["*/__tests__/**/*.{ts,tsx}"],
|
|
22
|
+
rules: {
|
|
23
|
+
"no-console": "off",
|
|
24
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
25
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
15
28
|
],
|
|
16
|
-
rules: {
|
|
17
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
18
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
19
|
-
},
|
|
20
29
|
};
|
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
# @ledgerhq/coin-tester
|
|
2
2
|
|
|
3
|
-
## 0.2.
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- [#7030](https://github.com/LedgerHQ/ledger-live/pull/7030) [`12a74b9`](https://github.com/LedgerHQ/ledger-live/commit/12a74b9f2f27285e44a5dca665422b3b8ecd4028) Thanks [@lambertkevin](https://github.com/lambertkevin)! - Add a `beforeSync` hook in Scenario
|
|
3
|
+
## 0.2.1-nightly.0
|
|
8
4
|
|
|
9
5
|
### Patch Changes
|
|
10
6
|
|
|
11
7
|
- Updated dependencies []:
|
|
12
|
-
- @ledgerhq/hw-transport-node-speculos-http@6.29.
|
|
8
|
+
- @ledgerhq/hw-transport-node-speculos-http@6.29.1-nightly.0
|
|
13
9
|
|
|
14
|
-
## 0.
|
|
10
|
+
## 0.2.0
|
|
15
11
|
|
|
16
|
-
###
|
|
17
|
-
|
|
18
|
-
- Updated dependencies []:
|
|
19
|
-
- @ledgerhq/hw-transport-node-speculos-http@6.29.0-nightly.3
|
|
12
|
+
### Minor Changes
|
|
20
13
|
|
|
21
|
-
|
|
14
|
+
- [#7030](https://github.com/LedgerHQ/ledger-live/pull/7030) [`12a74b9`](https://github.com/LedgerHQ/ledger-live/commit/12a74b9f2f27285e44a5dca665422b3b8ecd4028) Thanks [@lambertkevin](https://github.com/lambertkevin)! - Add a `beforeSync` hook in Scenario
|
|
22
15
|
|
|
23
16
|
### Patch Changes
|
|
24
17
|
|
|
25
|
-
- Updated dependencies []:
|
|
26
|
-
- @ledgerhq/hw-transport-node-speculos-http@6.29.0
|
|
18
|
+
- Updated dependencies [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11), [`f363430`](https://github.com/LedgerHQ/ledger-live/commit/f363430fe1a261f8adb79d3bf30e457cba839783)]:
|
|
19
|
+
- @ledgerhq/hw-transport-node-speculos-http@6.29.0
|
|
27
20
|
|
|
28
|
-
## 0.
|
|
21
|
+
## 0.2.0-next.0
|
|
29
22
|
|
|
30
|
-
###
|
|
31
|
-
|
|
32
|
-
- Updated dependencies [[`f363430`](https://github.com/LedgerHQ/ledger-live/commit/f363430fe1a261f8adb79d3bf30e457cba839783)]:
|
|
33
|
-
- @ledgerhq/hw-transport-node-speculos-http@6.29.0-nightly.1
|
|
23
|
+
### Minor Changes
|
|
34
24
|
|
|
35
|
-
|
|
25
|
+
- [#7030](https://github.com/LedgerHQ/ledger-live/pull/7030) [`12a74b9`](https://github.com/LedgerHQ/ledger-live/commit/12a74b9f2f27285e44a5dca665422b3b8ecd4028) Thanks [@lambertkevin](https://github.com/lambertkevin)! - Add a `beforeSync` hook in Scenario
|
|
36
26
|
|
|
37
27
|
### Patch Changes
|
|
38
28
|
|
|
39
|
-
- Updated dependencies [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11)]:
|
|
40
|
-
- @ledgerhq/hw-transport-node-speculos-http@6.29.0-
|
|
29
|
+
- Updated dependencies [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11), [`f363430`](https://github.com/LedgerHQ/ledger-live/commit/f363430fe1a261f8adb79d3bf30e457cba839783)]:
|
|
30
|
+
- @ledgerhq/hw-transport-node-speculos-http@6.29.0-next.0
|
package/README.md
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
# Coin-tester
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- [Setup](#setup)
|
|
4
|
+
- [Run tests for a coin module](#runtests)
|
|
5
|
+
|
|
6
|
+
## Setup {#setup}
|
|
4
7
|
|
|
5
8
|
### Prerequisites
|
|
6
9
|
|
|
7
|
-
-
|
|
10
|
+
- Ledger Live development setup
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
git clone git@github.com:LedgerHQ/ledger-live.git
|
|
14
|
+
cd ledger-live
|
|
15
|
+
pnpm install
|
|
16
|
+
pnpm build:libs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- [Docker](https://docs.docker.com/engine/install)
|
|
8
20
|
|
|
9
21
|
### Build the speculos image
|
|
10
22
|
|
|
11
23
|
You only have to build speculos locally if you are on a Mac M1. Otherwise you can uncomment the image provided in the docker-compose.yml
|
|
12
24
|
|
|
13
|
-
1. Clone speculos
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
1. Clone speculos: `git clone git@github.com:LedgerHQ/speculos.git`
|
|
26
|
+
|
|
27
|
+
2. Patch Dockerfile:
|
|
28
|
+
|
|
16
29
|
```Dockerfile
|
|
17
30
|
# before
|
|
18
31
|
FROM ghcr.io/ledgerhq/speculos-builder:latest AS builder
|
|
@@ -20,14 +33,22 @@ FROM ghcr.io/ledgerhq/speculos-builder:latest AS builder
|
|
|
20
33
|
FROM speculos-builder:latest AS builder
|
|
21
34
|
```
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
3. Build image
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
cd speculos
|
|
40
|
+
docker build -f build.Dockerfile -t speculos-builder:latest .
|
|
41
|
+
docker build -f Dockerfile -t speculos:latest .
|
|
42
|
+
```
|
|
24
43
|
|
|
25
44
|
### Environment variables
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
- Generate a [Github token classic](https://github.com/settings/tokens) and give it full "repo" and "project" rights. Make sure to authorize Ledger SSO.
|
|
47
|
+
|
|
48
|
+
- Go in the coin-module you want to test and create a `.env` in the folder where your test resides.
|
|
49
|
+
For exemple for `coin-evm` create the file should be located in: `src/__test__/coin-tester/.env`.
|
|
29
50
|
|
|
30
|
-
|
|
51
|
+
Copy `.env.example`.
|
|
31
52
|
|
|
32
53
|
```bash
|
|
33
54
|
cp .env.example .env
|
|
@@ -36,8 +57,38 @@ cp .env.example .env
|
|
|
36
57
|
A `.env` should have at the very least the following attributes:
|
|
37
58
|
|
|
38
59
|
```conf
|
|
39
|
-
SEED=
|
|
60
|
+
SEED=chronic find success crew board merit elder life achieve scout gravity soul brief pen job
|
|
61
|
+
GH_TOKEN=
|
|
62
|
+
API_PORT=4040
|
|
63
|
+
SPECULOS_IMAGE=speculos
|
|
40
64
|
```
|
|
41
65
|
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
If you want you can generate a new seed using [this tool](https://iancoleman.io/bip39/)
|
|
67
|
+
|
|
68
|
+
### Coin Module Specific setup
|
|
69
|
+
|
|
70
|
+
#### Polkadot
|
|
71
|
+
|
|
72
|
+
To coin Polkadot Coin tester we will need to build the local test node Docker image.
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
cd libs/coin-modules/coin-polkadot/src/test/coin-tester
|
|
76
|
+
make build
|
|
77
|
+
```
|
|
78
|
+
## Run tests for a coin module {#runtests}
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
pnpm coin:<coin-module-name> coin-tester
|
|
82
|
+
|
|
83
|
+
# e.g
|
|
84
|
+
# pnpm coin:evm coin-tester
|
|
85
|
+
# pnpm coin:polkadot coin-tester
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Troubleshooting
|
|
89
|
+
|
|
90
|
+
### EVM Coin tester
|
|
91
|
+
|
|
92
|
+
> The \"RPC\" variable is not set. Defaulting to a blank string.
|
|
93
|
+
|
|
94
|
+
This error can safely be ignored. The RPC is passed as a variable env at runtime. Check [here](https://github.com/LedgerHQ/ledger-live/blob/develop/libs/coin-modules/coin-evm/src/__tests__/coin-tester/anvil.ts#L28) and [here](https://github.com/LedgerHQ/ledger-live/blob/develop/libs/coin-modules/coin-evm/src/__tests__/coin-tester/scenarios/ethereum.ts#L144)
|
package/docker-compose.yml
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
version: '2.4'
|
|
2
|
-
|
|
3
1
|
services:
|
|
4
2
|
speculos:
|
|
5
3
|
# Speculos isn't supported for Mac M1 yet. You have to build the image locally as described in the README.
|
|
@@ -9,7 +7,7 @@ services:
|
|
|
9
7
|
volumes:
|
|
10
8
|
- ./lib/signers/tmp:/speculos/apps
|
|
11
9
|
ports:
|
|
12
|
-
- "${
|
|
10
|
+
- "${SPECULOS_API_PORT}:${SPECULOS_API_PORT}"
|
|
13
11
|
build:
|
|
14
12
|
context: /speculos
|
|
15
|
-
command: --model nanox ./apps/app.elf --seed="${SEED}" --display headless --api-port ${
|
|
13
|
+
command: --model nanox ./apps/app.elf --seed="${SEED}" --display headless --api-port ${SPECULOS_API_PORT}
|
package/lib/main.d.ts
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
|
-
import { AccountBridge, Account, TransactionCommon, SignOperationEvent, CurrencyBridge } from "@ledgerhq/types-live";
|
|
2
|
-
export type ScenarioTransaction<T extends TransactionCommon> = Partial<T> & {
|
|
1
|
+
import { AccountBridge, Account, TransactionCommon, SignOperationEvent, CurrencyBridge, Operation } from "@ledgerhq/types-live";
|
|
2
|
+
export type ScenarioTransaction<T extends TransactionCommon, A extends Account> = Partial<T> & {
|
|
3
3
|
name: string;
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
|
+
* @description assert the account state after the transaction
|
|
6
7
|
* @param previousAccount previousAccount returned by the latest sync before broadcasting this transaction
|
|
7
8
|
* @param currentAccount currentAccount synced after broadcasting this transaction
|
|
8
9
|
* @returns void
|
|
9
10
|
*/
|
|
10
|
-
expect?: (previousAccount:
|
|
11
|
+
expect?: (previousAccount: A, currentAccount: A) => void;
|
|
12
|
+
/**
|
|
13
|
+
* FOR DEV ONLY
|
|
14
|
+
* if you want to temporarily disable the expect for a transaction
|
|
15
|
+
* You should push a transaction with a xexpect
|
|
16
|
+
*/
|
|
17
|
+
xexpect?: (previousAccount: A, currentAccount: A) => void;
|
|
11
18
|
};
|
|
12
|
-
export type Scenario<T extends TransactionCommon> = {
|
|
19
|
+
export type Scenario<T extends TransactionCommon, A extends Account> = {
|
|
13
20
|
name: string;
|
|
14
21
|
setup: () => Promise<{
|
|
15
|
-
accountBridge: AccountBridge<T>;
|
|
22
|
+
accountBridge: AccountBridge<T, A>;
|
|
16
23
|
currencyBridge: CurrencyBridge;
|
|
17
|
-
account:
|
|
24
|
+
account: A;
|
|
18
25
|
retryInterval?: number;
|
|
19
26
|
retryLimit?: number;
|
|
20
27
|
onSignerConfirmation?: (e?: SignOperationEvent) => Promise<void>;
|
|
21
28
|
}>;
|
|
22
|
-
getTransactions: (address: string) => ScenarioTransaction<T>[];
|
|
29
|
+
getTransactions: (address: string) => ScenarioTransaction<T, A>[];
|
|
23
30
|
beforeSync?: () => Promise<void> | void;
|
|
31
|
+
mockIndexer?: (account: Account, optimistic: Operation) => Promise<void>;
|
|
24
32
|
beforeAll?: (account: Account) => Promise<void> | void;
|
|
25
33
|
afterAll?: (account: Account) => Promise<void> | void;
|
|
26
34
|
beforeEach?: (account: Account) => Promise<void> | void;
|
|
27
35
|
afterEach?: (account: Account) => Promise<void> | void;
|
|
28
36
|
teardown?: () => Promise<void> | void;
|
|
29
37
|
};
|
|
30
|
-
export declare function executeScenario<T extends TransactionCommon>(scenario: Scenario<T>): Promise<void>;
|
|
38
|
+
export declare function executeScenario<T extends TransactionCommon, A extends Account>(scenario: Scenario<T, A>): Promise<void>;
|
|
31
39
|
//# sourceMappingURL=main.d.ts.map
|
package/lib/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACV,MAAM,sBAAsB,CAAC;AAI9B,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,iBAAiB,EAAE,CAAC,SAAS,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG;IAC7F,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,KAAK,IAAI,CAAC;IACzD;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,iBAAiB,EAAE,CAAC,SAAS,OAAO,IAAI;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC;QACnB,aAAa,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,cAAc,EAAE,cAAc,CAAC;QAC/B,OAAO,EAAE,CAAC,CAAC;QACX,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAClE,CAAC,CAAC;IACH,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAClE,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,wBAAsB,eAAe,CAAC,CAAC,SAAS,iBAAiB,EAAE,CAAC,SAAS,OAAO,EAClF,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,iBAgNzB"}
|
package/lib/main.js
CHANGED
|
@@ -17,7 +17,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
17
17
|
const rxjs_1 = require("rxjs");
|
|
18
18
|
function executeScenario(scenario) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
try {
|
|
22
22
|
const { accountBridge, currencyBridge, account, retryInterval, retryLimit, onSignerConfirmation, } = yield scenario.setup();
|
|
23
23
|
console.log("Setup completed ✓");
|
|
@@ -40,7 +40,7 @@ function executeScenario(scenario) {
|
|
|
40
40
|
for (const testTransaction of scenarioTransactions) {
|
|
41
41
|
console.log("\n");
|
|
42
42
|
console.log(chalk_1.default.cyan("Transaction:", chalk_1.default.bold(testTransaction.name), "◌"));
|
|
43
|
-
(_c = scenario.beforeEach) === null || _c === void 0 ? void 0 : _c.call(scenario, scenarioAccount);
|
|
43
|
+
yield ((_c = scenario.beforeEach) === null || _c === void 0 ? void 0 : _c.call(scenario, scenarioAccount));
|
|
44
44
|
console.log("Before each ✔️");
|
|
45
45
|
if (scenarioTransactions.indexOf(testTransaction) > 0) {
|
|
46
46
|
yield ((_d = scenario.beforeSync) === null || _d === void 0 ? void 0 : _d.call(scenario));
|
|
@@ -54,7 +54,7 @@ function executeScenario(scenario) {
|
|
|
54
54
|
console.log(" → ", "🧑🍳 ", chalk_1.default.bold("Prepared the transaction"), "✓");
|
|
55
55
|
const status = yield accountBridge.getTransactionStatus(scenarioAccount, transaction);
|
|
56
56
|
if (Object.entries(status.errors).length) {
|
|
57
|
-
throw new Error(
|
|
57
|
+
throw new Error(`${testTransaction.name} transaction\nError in transaction status: ${JSON.stringify(status.errors, null, 3)}`);
|
|
58
58
|
}
|
|
59
59
|
console.log(" → ", "🪲 ", chalk_1.default.bold("No status errors detected"), "✓");
|
|
60
60
|
const { signedOperation } = yield (0, rxjs_1.firstValueFrom)(accountBridge
|
|
@@ -71,51 +71,57 @@ function executeScenario(scenario) {
|
|
|
71
71
|
}), (0, rxjs_1.first)((e) => e.type === "signed")));
|
|
72
72
|
console.log(" → ", "🔏 ", chalk_1.default.bold("Signed the transaction"), "✓");
|
|
73
73
|
const optimisticOperation = yield accountBridge.broadcast({
|
|
74
|
-
account: scenarioAccount,
|
|
75
74
|
signedOperation,
|
|
75
|
+
account: scenarioAccount,
|
|
76
76
|
});
|
|
77
77
|
console.log(" → ", "🛫 ", chalk_1.default.bold("Broadcasted the transaction"), "✓");
|
|
78
78
|
const retry_limit = retryLimit !== null && retryLimit !== void 0 ? retryLimit : 10;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
function expectHandler(retry) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
var _a, _b, _c;
|
|
82
|
+
yield ((_a = scenario.beforeSync) === null || _a === void 0 ? void 0 : _a.call(scenario));
|
|
83
|
+
scenarioAccount = yield (0, rxjs_1.firstValueFrom)(accountBridge
|
|
84
|
+
.sync(Object.assign(Object.assign({}, scenarioAccount), { pendingOperations: [optimisticOperation] }), { paginationConfig: {} })
|
|
85
|
+
.pipe((0, rxjs_1.reduce)((acc, f) => f(acc), scenarioAccount)));
|
|
86
|
+
if (!testTransaction.expect) {
|
|
87
|
+
console.warn(chalk_1.default.yellow(`No expects in the transaction ${chalk_1.default.bold(testTransaction.name)}. You might want to add tests in this transaction.`));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
(_b = testTransaction.expect) === null || _b === void 0 ? void 0 : _b.call(testTransaction, previousAccount, scenarioAccount);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (!((_c = err === null || err === void 0 ? void 0 : err.matcherResult) === null || _c === void 0 ? void 0 : _c.pass)) {
|
|
95
|
+
if (retry === 0) {
|
|
96
|
+
console.error(chalk_1.default.red(`Retried ${retry_limit} time(s) and could not assert all expects for transaction ${chalk_1.default.bold(testTransaction.name)}`));
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
console.warn(chalk_1.default.magenta("Test asssertion failed. Retrying..."));
|
|
100
|
+
yield new Promise(resolve => setTimeout(resolve, retryInterval !== null && retryInterval !== void 0 ? retryInterval : 3 * 1000));
|
|
101
|
+
yield expectHandler(retry - 1);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
95
104
|
throw err;
|
|
96
105
|
}
|
|
97
|
-
console.warn(chalk_1.default.magenta("Test asssertion failed. Retrying..."));
|
|
98
|
-
yield new Promise(resolve => setTimeout(resolve, retryInterval !== null && retryInterval !== void 0 ? retryInterval : 5000));
|
|
99
|
-
yield expectHandler(retry - 1);
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
yield ((_e = scenario.mockIndexer) === null || _e === void 0 ? void 0 : _e.call(scenario, scenarioAccount, optimisticOperation));
|
|
104
110
|
yield expectHandler(retry_limit);
|
|
105
|
-
(
|
|
111
|
+
yield ((_f = scenario.afterEach) === null || _f === void 0 ? void 0 : _f.call(scenario, scenarioAccount));
|
|
106
112
|
console.log("After each ✔️");
|
|
107
113
|
console.log(chalk_1.default.green("Transaction:", chalk_1.default.bold(testTransaction.name), "completed ✓"));
|
|
108
114
|
}
|
|
109
115
|
console.log("\n");
|
|
110
|
-
yield ((
|
|
116
|
+
yield ((_g = scenario.afterAll) === null || _g === void 0 ? void 0 : _g.call(scenario, scenarioAccount));
|
|
111
117
|
console.log("afterAll completed ✓");
|
|
112
118
|
console.log("Stopping engine...");
|
|
113
|
-
yield ((
|
|
119
|
+
yield ((_h = scenario.teardown) === null || _h === void 0 ? void 0 : _h.call(scenario));
|
|
114
120
|
console.log("\n\n", chalk_1.default.bgGreen.black.bold(" ✧ "), " ", chalk_1.default.green(`Scenario: ${chalk_1.default.italic.bold(scenario.name)}`), " ", chalk_1.default.bgGreen.black.bold(" ✧ "), " → ", chalk_1.default.bold.green(" Completed 🎉"), "\n\n");
|
|
115
121
|
}
|
|
116
122
|
catch (err) {
|
|
117
123
|
console.error("\n\n", chalk_1.default.bgRed.black.bold(" ✧ "), " ", chalk_1.default.red(`Scenario: ${chalk_1.default.italic.bold(scenario.name)}`), " ", chalk_1.default.bgRed.black.bold(" ✧ "), " → ", chalk_1.default.bold.red(" Failed ❌"), "\n\n");
|
|
118
|
-
yield ((
|
|
124
|
+
yield ((_j = scenario.teardown) === null || _j === void 0 ? void 0 : _j.call(scenario));
|
|
119
125
|
throw err;
|
|
120
126
|
}
|
|
121
127
|
});
|
package/lib/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,kDAA0B;AAC1B,+BAA0D;AAwC1D,SAAsB,eAAe,CACnC,QAAwB;;;QAExB,IAAI,CAAC;YACH,MAAM,EACJ,aAAa,EACb,cAAc,EACd,OAAO,EACP,aAAa,EACb,UAAU,EACV,oBAAoB,GACrB,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;YAE3B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YAEjC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAClB,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CAAC,mBAAmB,CAAC,EACjC,KAAK,EACL,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EACrC,MAAM,CACP,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC5D,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;YAE7C,MAAM,CAAA,MAAA,QAAQ,CAAC,UAAU,wDAAI,CAAA,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;YAC3D,IAAI,eAAe,GAAG,MAAM,IAAA,qBAAc,EAC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AAG,EACH,eAAK,CAAC,GAAG,CAAC,aAAa,eAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAC1D,GAAG,EACH,eAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAC7B,KAAK,EACL,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAC5B,MAAM,CACP,CAAC;YAEF,MAAM,CAAA,MAAA,QAAQ,CAAC,QAAQ,wDAAI,CAAA,CAAC;YAE5B,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CAAA;AAjND,0CAiNC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
2
|
-
|
|
3
|
-
export declare const spawnSpeculos: (nanoAppEndpoint: `/${string}`) => Promise<{
|
|
2
|
+
export declare function spawnSpeculos(nanoAppEndpoint: `/${string}`): Promise<{
|
|
4
3
|
transport: SpeculosTransportHttp;
|
|
5
|
-
|
|
4
|
+
getOnSpeculosConfirmation: (approvalText?: string) => () => Promise<void>;
|
|
6
5
|
}>;
|
|
7
|
-
export declare
|
|
6
|
+
export declare function killSpeculos(): Promise<void>;
|
|
8
7
|
//# sourceMappingURL=speculos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAIA,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"speculos.d.ts","sourceRoot":"","sources":["../../src/signers/speculos.ts"],"names":[],"mappings":"AAIA,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;AA2B9E,wBAAsB,aAAa,CAAC,eAAe,EAAE,IAAI,MAAM,EAAE,GAAG,OAAO,CAAC;IAC1E,SAAS,EAAE,qBAAqB,CAAC;IACjC,yBAAyB,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3E,CAAC,CA4ED;AAED,wBAAsB,YAAY,kBAOjC"}
|
package/lib/signers/speculos.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -14,76 +37,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
38
|
exports.killSpeculos = exports.spawnSpeculos = void 0;
|
|
16
39
|
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const axios_1 =
|
|
40
|
+
const axios_1 = __importStar(require("axios"));
|
|
18
41
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
19
42
|
const docker_compose_1 = require("docker-compose");
|
|
20
43
|
const hw_transport_node_speculos_http_1 = __importDefault(require("@ledgerhq/hw-transport-node-speculos-http"));
|
|
21
44
|
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
-
const {
|
|
45
|
+
const { SPECULOS_API_PORT } = process.env;
|
|
23
46
|
const cwd = path_1.default.join(__dirname);
|
|
24
47
|
const delay = (timing) => new Promise(resolve => setTimeout(resolve, timing));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
yield promises_1.default.mkdir(path_1.default.resolve(cwd, "tmp"), { recursive: true });
|
|
36
|
-
yield promises_1.default.writeFile(path_1.default.resolve(cwd, "tmp/app.elf"), blob, "binary");
|
|
37
|
-
yield docker_compose_1.v2.upOne("speculos", {
|
|
38
|
-
cwd,
|
|
39
|
-
log: true,
|
|
40
|
-
env: process.env,
|
|
48
|
+
function ensureEnv() {
|
|
49
|
+
const mandatory_env_variables = ["SEED", "SPECULOS_API_PORT", "GH_TOKEN"];
|
|
50
|
+
const optional_env_variables = ["SPECULOS_IMAGE"];
|
|
51
|
+
if (!mandatory_env_variables.every(variable => !!process.env[variable])) {
|
|
52
|
+
throw new Error(`Missing env variables. Make sure that ${mandatory_env_variables.join(",")} are in your .env`);
|
|
53
|
+
}
|
|
54
|
+
optional_env_variables.forEach(envVariable => {
|
|
55
|
+
if (!process.env[envVariable]) {
|
|
56
|
+
console.warn(`Variable ${envVariable} missing from .env. Using default value.`);
|
|
57
|
+
}
|
|
41
58
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
}
|
|
60
|
+
function spawnSpeculos(nanoAppEndpoint) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
ensureEnv();
|
|
63
|
+
console.log(`Starting speculos...`);
|
|
64
|
+
try {
|
|
65
|
+
const { data: blob } = yield (0, axios_1.default)({
|
|
66
|
+
url: `https://raw.githubusercontent.com/LedgerHQ/coin-apps/master/nanox${nanoAppEndpoint}`,
|
|
67
|
+
method: "GET",
|
|
68
|
+
responseType: "stream",
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: `Bearer ${process.env.GH_TOKEN}`,
|
|
71
|
+
},
|
|
48
72
|
});
|
|
73
|
+
yield promises_1.default.mkdir(path_1.default.resolve(cwd, "tmp"), { recursive: true });
|
|
74
|
+
yield promises_1.default.writeFile(path_1.default.resolve(cwd, "tmp/app.elf"), blob, "binary");
|
|
49
75
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const onSpeculosConfirmation = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
if ((e === null || e === void 0 ? void 0 : e.type) === "device-signature-requested") {
|
|
55
|
-
const { data } = yield axios_1.default.get(`http://localhost:${process.env.API_PORT}/events?currentscreenonly=true`);
|
|
56
|
-
if (data.events[0].text !== "Accept") {
|
|
57
|
-
yield axios_1.default.post(`http://localhost:${process.env.API_PORT}/button/right`, {
|
|
58
|
-
action: "press-and-release",
|
|
59
|
-
});
|
|
60
|
-
onSpeculosConfirmation(e);
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof axios_1.AxiosError) {
|
|
78
|
+
throw new Error(`${err.status}: Failed to download the app.elf file from ${nanoAppEndpoint}\nMake sure that your GH_TOKEN is correct and has the right permissions.`);
|
|
61
79
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
yield docker_compose_1.v2.upOne("speculos", {
|
|
83
|
+
cwd,
|
|
84
|
+
log: true,
|
|
85
|
+
env: process.env,
|
|
86
|
+
});
|
|
87
|
+
function checkSpeculosLogs() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const { out } = yield docker_compose_1.v2.logs("speculos", { cwd, env: process.env });
|
|
90
|
+
if (out.includes("Running on all addresses (0.0.0.0)")) {
|
|
91
|
+
console.log(chalk_1.default.bgYellowBright.black(" - SPECULOS READY ✅ - "));
|
|
92
|
+
return hw_transport_node_speculos_http_1.default.open({
|
|
93
|
+
apiPort: SPECULOS_API_PORT,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
yield delay(200);
|
|
97
|
+
return checkSpeculosLogs();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function getOnSpeculosConfirmation(approvalText = "Accept") {
|
|
101
|
+
function onSpeculosConfirmation(e) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
if ((e === null || e === void 0 ? void 0 : e.type) === "device-signature-requested") {
|
|
104
|
+
const { data } = yield axios_1.default.get(`http://localhost:${SPECULOS_API_PORT}/events?currentscreenonly=true`);
|
|
105
|
+
if (data.events[0].text !== approvalText) {
|
|
106
|
+
yield axios_1.default.post(`http://localhost:${SPECULOS_API_PORT}/button/right`, {
|
|
107
|
+
action: "press-and-release",
|
|
108
|
+
});
|
|
109
|
+
onSpeculosConfirmation(e);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
yield axios_1.default.post(`http://localhost:${SPECULOS_API_PORT}/button/both`, {
|
|
113
|
+
action: "press-and-release",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
65
117
|
});
|
|
66
118
|
}
|
|
119
|
+
return onSpeculosConfirmation;
|
|
67
120
|
}
|
|
121
|
+
return checkSpeculosLogs().then(transport => {
|
|
122
|
+
return {
|
|
123
|
+
transport,
|
|
124
|
+
getOnSpeculosConfirmation,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
68
127
|
});
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
transport,
|
|
72
|
-
onSignerConfirmation: onSpeculosConfirmation,
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
});
|
|
128
|
+
}
|
|
76
129
|
exports.spawnSpeculos = spawnSpeculos;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
130
|
+
function killSpeculos() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
console.log("Stopping speculos...");
|
|
133
|
+
yield docker_compose_1.v2.down({
|
|
134
|
+
cwd,
|
|
135
|
+
log: true,
|
|
136
|
+
env: process.env,
|
|
137
|
+
});
|
|
83
138
|
});
|
|
84
|
-
}
|
|
139
|
+
}
|
|
85
140
|
exports.killSpeculos = killSpeculos;
|
|
86
141
|
["exit", "SIGINT", "SIGQUIT", "SIGTERM", "SIGUSR1", "SIGUSR2", "uncaughtException"].map(e => process.on(e, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
yield
|
|
142
|
+
yield killSpeculos();
|
|
88
143
|
})));
|
|
89
144
|
//# sourceMappingURL=speculos.js.map
|