@ledgerhq/coin-polkadot 0.1.1 → 0.1.2-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ledgerhq/coin-polkadot
2
2
 
3
+ ## 0.1.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`d5cf1abc6e`](https://github.com/LedgerHQ/ledger-live/commit/d5cf1abc6eb30d399c83b827452dc4bc61fd2253), [`3242a0a794`](https://github.com/LedgerHQ/ledger-live/commit/3242a0a7948c20fb0100ce3cc73e55e338534d32), [`be5589dac6`](https://github.com/LedgerHQ/ledger-live/commit/be5589dac675e2c8c1771b135bd0f330a868ed2d), [`d5cf1abc6e`](https://github.com/LedgerHQ/ledger-live/commit/d5cf1abc6eb30d399c83b827452dc4bc61fd2253)]:
8
+ - @ledgerhq/coin-framework@0.3.1-next.0
9
+ - @ledgerhq/cryptoassets@9.4.0-next.0
10
+ - @ledgerhq/types-live@6.32.1-next.0
11
+ - @ledgerhq/live-portfolio@0.0.3-next.0
12
+
3
13
  ## 0.1.1
4
14
 
5
15
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-polkadot",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-next.0",
4
4
  "description": "Ledger Polkadot Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -54,17 +54,17 @@
54
54
  "invariant": "^2.2.2",
55
55
  "lodash": "^4.17.21",
56
56
  "rxjs": "^6.6.7",
57
- "@ledgerhq/coin-framework": "^0.3.0",
58
- "@ledgerhq/cryptoassets": "^9.3.0",
57
+ "@ledgerhq/coin-framework": "^0.3.1-next.0",
58
+ "@ledgerhq/cryptoassets": "^9.4.0-next.0",
59
59
  "@ledgerhq/devices": "^8.0.1",
60
60
  "@ledgerhq/errors": "^6.12.4",
61
61
  "@ledgerhq/hw-app-polkadot": "^6.27.13",
62
62
  "@ledgerhq/live-env": "^0.1.0",
63
- "@ledgerhq/live-portfolio": "^0.0.2",
63
+ "@ledgerhq/live-portfolio": "^0.0.3-next.0",
64
64
  "@ledgerhq/live-promise": "^0.0.1",
65
65
  "@ledgerhq/logs": "^6.10.1",
66
66
  "@ledgerhq/types-cryptoassets": "^7.1.0",
67
- "@ledgerhq/types-live": "^6.32.0"
67
+ "@ledgerhq/types-live": "^6.32.1-next.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/invariant": "^2.2.2",
@@ -81,7 +81,7 @@
81
81
  "jest": "^28.1.1",
82
82
  "prettier": "^2.8.1",
83
83
  "ts-jest": "^28.0.5",
84
- "typescript": "^4.9.4"
84
+ "typescript": "^4.9.5"
85
85
  },
86
86
  "scripts": {
87
87
  "clean": "rimraf lib lib-es",
@@ -0,0 +1,189 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { cryptocurrenciesById } from "@ledgerhq/cryptoassets";
3
+ import { PolkadotAccount, PolkadotOperationMode, Transaction } from "./types";
4
+ import { buildTransaction } from "./js-buildTransaction";
5
+ import { PolkadotAPI } from "./api";
6
+ import { TypeRegistry } from "@polkadot/types";
7
+ import { NetworkRequestCall } from "@ledgerhq/coin-framework/network";
8
+ import { makeNoCache } from "@ledgerhq/coin-framework/cache";
9
+
10
+ const registry = new TypeRegistry();
11
+
12
+ const extrinsicsMethod = jest.fn().mockImplementation(() => ({
13
+ toHex: () => "Hex 4 extrinsicsMethod",
14
+ }));
15
+ (extrinsicsMethod as any).meta = {
16
+ args: [],
17
+ };
18
+
19
+ const transactionParams = {
20
+ blockHash: "0xb10c4a54",
21
+ genesisHash: "0x83835154a54",
22
+ blockNumber: 12,
23
+ specVersion: 42,
24
+ tip: 8,
25
+ transactionVersion: 22,
26
+ };
27
+ jest.mock("./api", () => ({
28
+ PolkadotAPI: jest.fn().mockImplementation(() => {
29
+ return {
30
+ getRegistry: () => {
31
+ return Promise.resolve({
32
+ registry: registry,
33
+ extrinsics: {
34
+ balances: {
35
+ transferKeepAlive: extrinsicsMethod,
36
+ },
37
+ },
38
+ });
39
+ },
40
+ getTransactionParams: (): Promise<Record<string, any>> => {
41
+ return Promise.resolve(transactionParams);
42
+ },
43
+ };
44
+ }),
45
+ }));
46
+
47
+ describe("buildTransaction", () => {
48
+ const mockCodec = jest.fn();
49
+ const mockRegistry = jest.spyOn(registry, "createType");
50
+
51
+ beforeEach(() => {
52
+ mockRegistry.mockImplementation((type: string, ..._params: unknown[]) => {
53
+ mockCodec.mockReturnValueOnce({
54
+ toHex: () => `HexCodec 4 ${type}`,
55
+ });
56
+ return new mockCodec();
57
+ });
58
+ });
59
+
60
+ afterEach(() => {
61
+ mockRegistry.mockClear();
62
+ });
63
+
64
+ it("returns unsigned with account address provided", async () => {
65
+ // GIVEN
66
+ const account = createAccount();
67
+ const transaction = createTransaction();
68
+ const mockNetwork: NetworkRequestCall = (_): Promise<any> => {
69
+ return Promise.resolve();
70
+ };
71
+ const polkadotAPI = new PolkadotAPI(mockNetwork, makeNoCache);
72
+
73
+ // WHEN
74
+ const result = await buildTransaction(polkadotAPI)(account, transaction);
75
+
76
+ // THEN
77
+ expect(mockRegistry).toHaveBeenCalledTimes(6);
78
+ expect(mockRegistry).toHaveBeenCalledWith("BlockNumber", 12);
79
+ expect(mockRegistry).toHaveBeenCalledWith("ExtrinsicEra", {
80
+ current: 12,
81
+ period: 64,
82
+ });
83
+ expect(mockRegistry).toHaveBeenCalledWith("u32", 42);
84
+ expect(mockRegistry).toHaveBeenCalledWith("Compact<Balance>", 8);
85
+ expect(mockRegistry).toHaveBeenCalledWith("u32", 22);
86
+ expect(mockCodec).toHaveBeenCalledTimes(6);
87
+ const expectedResult = {
88
+ registry: registry,
89
+ unsigned: {
90
+ address: account.freshAddress,
91
+ blockHash: "0xb10c4a54",
92
+ genesisHash: "0x83835154a54",
93
+ method: "Hex 4 extrinsicsMethod",
94
+ signedExtensions: [
95
+ "CheckVersion",
96
+ "CheckGenesis",
97
+ "CheckEra",
98
+ "CheckNonce",
99
+ "CheckWeight",
100
+ "ChargeTransactionPayment",
101
+ "CheckBlockGasLimit",
102
+ ],
103
+ blockNumber: "HexCodec 4 BlockNumber",
104
+ era: "HexCodec 4 ExtrinsicEra",
105
+ nonce: "HexCodec 4 Compact<Index>",
106
+ specVersion: "HexCodec 4 u32",
107
+ tip: "HexCodec 4 Compact<Balance>",
108
+ transactionVersion: "HexCodec 4 u32",
109
+ version: 4,
110
+ },
111
+ };
112
+ expect(result).toEqual(expectedResult);
113
+ });
114
+ });
115
+
116
+ function createAccount(): PolkadotAccount {
117
+ return {
118
+ type: "Account",
119
+ id: "12",
120
+ seedIdentifier: "seed",
121
+ derivationMode: "mode",
122
+ index: 0,
123
+ freshAddress: "0xff",
124
+ freshAddressPath: "/path/to",
125
+ // freshAddressPath: "44'/60'/0'/0/0",
126
+ freshAddresses: [],
127
+ name: "polkadot account",
128
+ starred: false,
129
+ used: false,
130
+ balance: BigNumber("0"),
131
+ spendableBalance: BigNumber("0"),
132
+ creationDate: new Date(),
133
+ blockHeight: 0,
134
+ currency: cryptocurrenciesById["polkadot"],
135
+ unit: {
136
+ name: "dot",
137
+ code: "DOT",
138
+ magnitude: 5,
139
+ },
140
+ operationsCount: 0,
141
+ operations: [],
142
+ pendingOperations: [],
143
+ lastSyncDate: new Date(),
144
+ balanceHistoryCache: {
145
+ HOUR: {
146
+ balances: [],
147
+ latestDate: undefined,
148
+ },
149
+ DAY: {
150
+ balances: [],
151
+ latestDate: undefined,
152
+ },
153
+ WEEK: {
154
+ balances: [],
155
+ latestDate: undefined,
156
+ },
157
+ },
158
+ swapHistory: [],
159
+ polkadotResources: {
160
+ controller: null,
161
+ stash: null,
162
+ nonce: 0,
163
+ lockedBalance: BigNumber("0"),
164
+ unlockedBalance: BigNumber("0"),
165
+ unlockingBalance: BigNumber("0"),
166
+ unlockings: null,
167
+ nominations: null,
168
+ numSlashingSpans: 0,
169
+ },
170
+ };
171
+ }
172
+
173
+ function createTransaction(mode: PolkadotOperationMode = "send"): Transaction {
174
+ return {
175
+ amount: BigNumber("0"),
176
+ recipient: "",
177
+ // useAllAmount?: boolean;
178
+ // subAccountId?: string | null | undefined;
179
+ // feesStrategy?: "slow" | "medium" | "fast" | "custom" | null;
180
+
181
+ mode: mode,
182
+ family: "polkadot",
183
+ fees: null,
184
+ validators: null,
185
+ era: null,
186
+ rewardDestination: null,
187
+ numSlashingSpans: null,
188
+ };
189
+ }