@ledgerhq/coin-tester-evm 1.8.0 → 1.8.1-nightly.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-tester-evm",
3
- "version": "1.8.0",
3
+ "version": "1.8.1-nightly.1",
4
4
  "description": "Ledger EVM Coin Tester",
5
5
  "main": "src/scenarii.test.ts",
6
6
  "keywords": [
@@ -51,15 +51,15 @@
51
51
  "dotenv": "^16.4.5",
52
52
  "ethers": "6.15.0",
53
53
  "msw": "^2.2.1",
54
- "@ledgerhq/coin-evm": "^2.31.0",
55
- "@ledgerhq/coin-framework": "^6.5.0",
54
+ "@ledgerhq/coin-evm": "^2.32.0-nightly.0",
55
+ "@ledgerhq/coin-framework": "^6.6.0-nightly.0",
56
56
  "@ledgerhq/coin-tester": "^0.10.0",
57
- "@ledgerhq/cryptoassets": "^13.29.0",
58
- "@ledgerhq/live-common": "^34.49.0",
57
+ "@ledgerhq/cryptoassets": "^13.30.0-nightly.0",
58
+ "@ledgerhq/live-common": "^34.50.0-nightly.1",
59
59
  "@ledgerhq/live-config": "^3.2.0",
60
- "@ledgerhq/live-signer-evm": "^0.8.0",
61
- "@ledgerhq/types-cryptoassets": "^7.27.0",
62
- "@ledgerhq/types-live": "^6.85.0"
60
+ "@ledgerhq/live-signer-evm": "^0.8.1-nightly.0",
61
+ "@ledgerhq/types-cryptoassets": "^7.28.0-nightly.0",
62
+ "@ledgerhq/types-live": "^6.86.0-nightly.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@swc/core": "1.4.11",
package/src/helpers.ts CHANGED
@@ -17,6 +17,7 @@ import { getAlpacaCurrencyBridge } from "@ledgerhq/live-common/bridge/generic-al
17
17
  import { getAlpacaAccountBridge } from "@ledgerhq/live-common/bridge/generic-alpaca/accountBridge";
18
18
 
19
19
  export const ethereum = getCryptoCurrencyById("ethereum");
20
+ export const core = getCryptoCurrencyById("core");
20
21
  export const sonic = getCryptoCurrencyById("sonic");
21
22
  export const polygon = getCryptoCurrencyById("polygon");
22
23
  export const scroll = getCryptoCurrencyById("scroll");
@@ -0,0 +1,170 @@
1
+ import { makeAccount } from "@ledgerhq/coin-evm/__tests__/fixtures/common.fixtures";
2
+ import { buildAccountBridge, buildCurrencyBridge } from "@ledgerhq/coin-evm/bridge/js";
3
+ import { getCoinConfig, setCoinConfig } from "@ledgerhq/coin-evm/config";
4
+ import resolver from "@ledgerhq/coin-evm/hw-getAddress";
5
+ import { EvmSigner } from "@ledgerhq/coin-evm/types/signer";
6
+ import { Transaction as EvmTransaction } from "@ledgerhq/coin-evm/types/transaction";
7
+ import { encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
8
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
+ import { Scenario, ScenarioTransaction } from "@ledgerhq/coin-tester/main";
10
+ import { killSpeculos, spawnSpeculos } from "@ledgerhq/coin-tester/signers/speculos";
11
+ import { getTokenById } from "@ledgerhq/cryptoassets/tokens";
12
+ import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
13
+ import { LegacySignerEth } from "@ledgerhq/live-signer-evm";
14
+ import { Account } from "@ledgerhq/types-live";
15
+ import { BigNumber } from "bignumber.js";
16
+ import { ethers } from "ethers";
17
+ import { killAnvil, spawnAnvil } from "../anvil";
18
+ import { VITALIK, core } from "../helpers";
19
+ import { indexBlocks, initMswHandlers, resetIndexer, setBlock } from "../indexer";
20
+ import { defaultNanoApp } from "../scenarii.test";
21
+
22
+ type CoreScenarioTransaction = ScenarioTransaction<EvmTransaction, Account>;
23
+
24
+ const STCORE_ON_CORE = getTokenById(
25
+ "core/erc20/liquid_staked_core_0xb3a8f0f0da9ffc65318aa39e55079796093029ad",
26
+ );
27
+
28
+ const makeScenarioTransactions = ({ address }: { address: string }): CoreScenarioTransaction[] => {
29
+ const scenarioSendSTransaction: CoreScenarioTransaction = {
30
+ name: "Send 1 CORE",
31
+ amount: new BigNumber(1e18),
32
+ recipient: VITALIK,
33
+ expect: (previousAccount, currentAccount) => {
34
+ const [latestOperation] = currentAccount.operations;
35
+ expect(currentAccount.operations.length - previousAccount.operations.length).toBe(1);
36
+ expect(latestOperation.type).toBe("OUT");
37
+ expect(latestOperation.value.toFixed()).toBe(latestOperation.fee.plus(1e18).toFixed());
38
+ expect(currentAccount.balance.toFixed()).toBe(
39
+ previousAccount.balance.minus(latestOperation.value).toFixed(),
40
+ );
41
+ },
42
+ };
43
+
44
+ // TODO: export when explorer is ready because last token operations come from explorer
45
+ const _scenarioSendSTCORETransaction: CoreScenarioTransaction = {
46
+ name: "Send STCORE",
47
+ amount: new BigNumber(ethers.parseUnits("80", STCORE_ON_CORE.units[0].magnitude).toString()),
48
+ recipient: VITALIK,
49
+ subAccountId: encodeTokenAccountId(`js:2:core:${address}:`, STCORE_ON_CORE),
50
+ expect: (previousAccount, currentAccount) => {
51
+ const [latestOperation] = currentAccount.operations;
52
+ expect(currentAccount.operations.length - previousAccount.operations.length).toBe(1);
53
+ expect(latestOperation.type).toBe("FEES");
54
+ expect(latestOperation.value.toFixed()).toBe(latestOperation.fee.toFixed());
55
+ expect(latestOperation.subOperations?.[0].type).toBe("OUT");
56
+ expect(latestOperation.subOperations?.[0].value.toFixed()).toBe(
57
+ ethers.parseUnits("80", STCORE_ON_CORE.units[0].magnitude).toString(),
58
+ );
59
+ expect(currentAccount.subAccounts?.[0].balance.toFixed()).toBe(
60
+ ethers.parseUnits("20", STCORE_ON_CORE.units[0].magnitude).toString(),
61
+ );
62
+ },
63
+ };
64
+
65
+ return [scenarioSendSTransaction];
66
+ };
67
+
68
+ export const scenarioCore: Scenario<EvmTransaction, Account> = {
69
+ name: "Ledger Live Basic CORE Transactions",
70
+ setup: async () => {
71
+ const [{ transport, getOnSpeculosConfirmation }] = await Promise.all([
72
+ spawnSpeculos(`/${defaultNanoApp.firmware}/Ethereum/app_${defaultNanoApp.version}.elf`),
73
+ spawnAnvil("https://rpc.ankr.com/core"),
74
+ ]);
75
+ const provider = new ethers.JsonRpcProvider("http://127.0.0.1:8545");
76
+ const signerContext: SignerContext<EvmSigner> = (_, fn) => fn(new LegacySignerEth(transport));
77
+
78
+ setCoinConfig(() => ({
79
+ info: {
80
+ status: {
81
+ type: "active",
82
+ },
83
+ node: {
84
+ type: "external",
85
+ uri: "http://127.0.0.1:8545",
86
+ },
87
+ explorer: {
88
+ type: "none",
89
+ },
90
+ showNfts: true,
91
+ },
92
+ }));
93
+ LiveConfig.setConfig({
94
+ config_currency_core: {
95
+ type: "object",
96
+ default: {
97
+ status: {
98
+ type: "active",
99
+ },
100
+ node: {
101
+ type: "external",
102
+ uri: "http://127.0.0.1:8545",
103
+ },
104
+ explorer: {
105
+ type: "none",
106
+ },
107
+ showNfts: false,
108
+ },
109
+ },
110
+ });
111
+
112
+ initMswHandlers(getCoinConfig(core).info);
113
+
114
+ const onSignerConfirmation = getOnSpeculosConfirmation();
115
+ const currencyBridge = buildCurrencyBridge(signerContext);
116
+ await currencyBridge.preload(core);
117
+ const accountBridge = buildAccountBridge(signerContext);
118
+ const getAddress = resolver(signerContext);
119
+ const { address } = await getAddress("", {
120
+ path: "44'/60'/0'/0/0",
121
+ currency: core,
122
+ derivationMode: "",
123
+ });
124
+
125
+ const scenarioAccount = makeAccount(address, core);
126
+
127
+ const lastBlockNumber = await provider.getBlockNumber();
128
+ // start indexing at next block
129
+ setBlock(lastBlockNumber + 1);
130
+
131
+ // Get STCORE
132
+ // TODO: uncomment when explorer is ready
133
+ // await callMyDealer({
134
+ // provider,
135
+ // drug: STCORE_ON_CORE,
136
+ // junkie: address,
137
+ // dose: ethers.parseUnits("100", STCORE_ON_CORE.units[0].magnitude),
138
+ // });
139
+
140
+ return {
141
+ currencyBridge,
142
+ accountBridge,
143
+ account: scenarioAccount,
144
+ onSignerConfirmation,
145
+ };
146
+ },
147
+ beforeAll: account => {
148
+ expect(account.balance.toFixed()).toBe(ethers.parseEther("10000").toString());
149
+ // TODO: uncomment when explorer is ready
150
+ // expect(account.subAccounts?.[0]?.type).toBe("TokenAccount");
151
+ // expect(account.subAccounts?.[0]?.balance?.toFixed()).toBe(
152
+ // ethers.parseUnits("100", STCORE_ON_CORE.units[0].magnitude).toString(),
153
+ // );
154
+ },
155
+ getTransactions: address => makeScenarioTransactions({ address }),
156
+ beforeSync: async () => {
157
+ await indexBlocks();
158
+ },
159
+ afterAll: _account => {
160
+ // TODO: uncomment when explorer is ready
161
+ // expect(account.subAccounts?.length).toBe(1);
162
+ // expect(account.subAccounts?.[0].balance.toFixed()).toBe(
163
+ // ethers.parseUnits("20", STCORE_ON_CORE.units[0].magnitude).toString(),
164
+ // );
165
+ },
166
+ teardown: async () => {
167
+ resetIndexer();
168
+ await Promise.all([killSpeculos(), killAnvil()]);
169
+ },
170
+ };
@@ -6,6 +6,7 @@ import { scenarioPolygon } from "./scenarii/polygon";
6
6
  import { scenarioScroll } from "./scenarii/scroll";
7
7
  import { scenarioBlast } from "./scenarii/blast";
8
8
  import { scenarioSonic } from "./scenarii/sonic";
9
+ import { scenarioCore } from "./scenarii/core";
9
10
  import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
10
11
  import type { CryptoAssetsStore } from "@ledgerhq/types-live";
11
12
  import * as legacy from "@ledgerhq/cryptoassets/tokens";
@@ -63,6 +64,17 @@ describe.each([["legacy"], ["generic-adapter"]] as const)(
63
64
  }
64
65
  });
65
66
 
67
+ it("scenario Core", async () => {
68
+ try {
69
+ await executeScenario(scenarioCore, strategy);
70
+ } catch (e) {
71
+ if (e != "done") {
72
+ await Promise.all([killSpeculos(), killAnvil()]);
73
+ throw e;
74
+ }
75
+ }
76
+ });
77
+
66
78
  it.skip("scenario scroll", async () => {
67
79
  try {
68
80
  await executeScenario(scenarioScroll);