@ledgerhq/coin-solana 0.35.0-nightly.8 → 0.35.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.
Files changed (199) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +28 -80
  3. package/lib/__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json +50 -0
  4. package/lib/__tests__/fixtures/helpers.fixture.d.ts +138 -0
  5. package/lib/__tests__/fixtures/helpers.fixture.d.ts.map +1 -0
  6. package/lib/__tests__/fixtures/helpers.fixture.js +124 -0
  7. package/lib/__tests__/fixtures/helpers.fixture.js.map +1 -0
  8. package/lib/__tests__/scan-accounts.test.d.ts +2 -0
  9. package/lib/__tests__/scan-accounts.test.d.ts.map +1 -0
  10. package/lib/__tests__/scan-accounts.test.js +426 -0
  11. package/lib/__tests__/scan-accounts.test.js.map +1 -0
  12. package/lib/__tests__/unit/hw-signMessage.unit.test.d.ts +2 -0
  13. package/lib/__tests__/unit/hw-signMessage.unit.test.d.ts.map +1 -0
  14. package/lib/__tests__/unit/hw-signMessage.unit.test.js +91 -0
  15. package/lib/__tests__/unit/hw-signMessage.unit.test.js.map +1 -0
  16. package/lib/__tests__/unit/nftResolvers.unit.test.d.ts +2 -0
  17. package/lib/__tests__/unit/nftResolvers.unit.test.d.ts.map +1 -0
  18. package/lib/__tests__/unit/nftResolvers.unit.test.js +147 -0
  19. package/lib/__tests__/unit/nftResolvers.unit.test.js.map +1 -0
  20. package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
  21. package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  22. package/lib/__tests__/unit/utils.unit.test.js +16 -0
  23. package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
  24. package/lib/__tests__/unit/validator-app.unit.test.d.ts +2 -0
  25. package/lib/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
  26. package/lib/__tests__/unit/validator-app.unit.test.js +169 -0
  27. package/lib/__tests__/unit/validator-app.unit.test.js.map +1 -0
  28. package/lib/bridge.integration.test.d.ts +4 -0
  29. package/lib/bridge.integration.test.d.ts.map +1 -0
  30. package/lib/bridge.integration.test.js +870 -0
  31. package/lib/bridge.integration.test.js.map +1 -0
  32. package/lib/buildTransaction.test.d.ts +2 -0
  33. package/lib/buildTransaction.test.d.ts.map +1 -0
  34. package/lib/buildTransaction.test.js +164 -0
  35. package/lib/buildTransaction.test.js.map +1 -0
  36. package/lib/cryptoAssetsStore.test.d.ts +2 -0
  37. package/lib/cryptoAssetsStore.test.d.ts.map +1 -0
  38. package/lib/cryptoAssetsStore.test.js +15 -0
  39. package/lib/cryptoAssetsStore.test.js.map +1 -0
  40. package/lib/network/chain/account/parser.d.ts +1 -1
  41. package/lib/network/chain/account/stake.d.ts +23 -23
  42. package/lib/network/chain/account/token.d.ts +7 -7
  43. package/lib/network/chain/instruction/stake/types.d.ts +8 -8
  44. package/lib/network/chain/instruction/system/types.d.ts +10 -10
  45. package/lib/network/chain/web3.integration.test.d.ts +2 -0
  46. package/lib/network/chain/web3.integration.test.d.ts.map +1 -0
  47. package/lib/network/chain/web3.integration.test.js +70 -0
  48. package/lib/network/chain/web3.integration.test.js.map +1 -0
  49. package/lib/offchainMessage/format.unit.test.d.ts +2 -0
  50. package/lib/offchainMessage/format.unit.test.d.ts.map +1 -0
  51. package/lib/offchainMessage/format.unit.test.js +124 -0
  52. package/lib/offchainMessage/format.unit.test.js.map +1 -0
  53. package/lib/preload.test.d.ts +2 -0
  54. package/lib/preload.test.d.ts.map +1 -0
  55. package/lib/preload.test.js +9 -0
  56. package/lib/preload.test.js.map +1 -0
  57. package/lib/prepareTransaction.d.ts.map +1 -1
  58. package/lib/prepareTransaction.js +0 -4
  59. package/lib/prepareTransaction.js.map +1 -1
  60. package/lib/prepareTransaction.test.d.ts +2 -0
  61. package/lib/prepareTransaction.test.d.ts.map +1 -0
  62. package/lib/prepareTransaction.test.js +139 -0
  63. package/lib/prepareTransaction.test.js.map +1 -0
  64. package/lib/signOperation.d.ts.map +1 -1
  65. package/lib/signOperation.js +0 -2
  66. package/lib/signOperation.js.map +1 -1
  67. package/lib/signOperation.test.d.ts +3 -0
  68. package/lib/signOperation.test.d.ts.map +1 -0
  69. package/lib/signOperation.test.js +139 -0
  70. package/lib/signOperation.test.js.map +1 -0
  71. package/lib/signer.d.ts +0 -1
  72. package/lib/signer.d.ts.map +1 -1
  73. package/lib/signer.js.map +1 -1
  74. package/lib/tests/preload.fixtures.d.ts +5 -0
  75. package/lib/tests/preload.fixtures.d.ts.map +1 -0
  76. package/lib/tests/preload.fixtures.js +28 -0
  77. package/lib/tests/preload.fixtures.js.map +1 -0
  78. package/lib/tests/preload.unit.test.d.ts +2 -0
  79. package/lib/tests/preload.unit.test.d.ts.map +1 -0
  80. package/lib/tests/preload.unit.test.js +175 -0
  81. package/lib/tests/preload.unit.test.js.map +1 -0
  82. package/lib/tests/stakes-bridge.unit.test.d.ts +2 -0
  83. package/lib/tests/stakes-bridge.unit.test.d.ts.map +1 -0
  84. package/lib/tests/stakes-bridge.unit.test.js +166 -0
  85. package/lib/tests/stakes-bridge.unit.test.js.map +1 -0
  86. package/lib/tests/test-onchain-data.fixture.d.ts +20 -0
  87. package/lib/tests/test-onchain-data.fixture.d.ts.map +1 -0
  88. package/lib/tests/test-onchain-data.fixture.js +34 -0
  89. package/lib/tests/test-onchain-data.fixture.js.map +1 -0
  90. package/lib/tests/tokens-bridge.unit.test.d.ts +2 -0
  91. package/lib/tests/tokens-bridge.unit.test.d.ts.map +1 -0
  92. package/lib/tests/tokens-bridge.unit.test.js +615 -0
  93. package/lib/tests/tokens-bridge.unit.test.js.map +1 -0
  94. package/lib/tx-fees.js +0 -2
  95. package/lib/tx-fees.js.map +1 -1
  96. package/lib/types.d.ts +1 -2
  97. package/lib/types.d.ts.map +1 -1
  98. package/lib-es/__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json +50 -0
  99. package/lib-es/__tests__/fixtures/helpers.fixture.d.ts +138 -0
  100. package/lib-es/__tests__/fixtures/helpers.fixture.d.ts.map +1 -0
  101. package/lib-es/__tests__/fixtures/helpers.fixture.js +110 -0
  102. package/lib-es/__tests__/fixtures/helpers.fixture.js.map +1 -0
  103. package/lib-es/__tests__/scan-accounts.test.d.ts +2 -0
  104. package/lib-es/__tests__/scan-accounts.test.d.ts.map +1 -0
  105. package/lib-es/__tests__/scan-accounts.test.js +398 -0
  106. package/lib-es/__tests__/scan-accounts.test.js.map +1 -0
  107. package/lib-es/__tests__/unit/hw-signMessage.unit.test.d.ts +2 -0
  108. package/lib-es/__tests__/unit/hw-signMessage.unit.test.d.ts.map +1 -0
  109. package/lib-es/__tests__/unit/hw-signMessage.unit.test.js +86 -0
  110. package/lib-es/__tests__/unit/hw-signMessage.unit.test.js.map +1 -0
  111. package/lib-es/__tests__/unit/nftResolvers.unit.test.d.ts +2 -0
  112. package/lib-es/__tests__/unit/nftResolvers.unit.test.d.ts.map +1 -0
  113. package/lib-es/__tests__/unit/nftResolvers.unit.test.js +142 -0
  114. package/lib-es/__tests__/unit/nftResolvers.unit.test.js.map +1 -0
  115. package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
  116. package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  117. package/lib-es/__tests__/unit/utils.unit.test.js +14 -0
  118. package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
  119. package/lib-es/__tests__/unit/validator-app.unit.test.d.ts +2 -0
  120. package/lib-es/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
  121. package/lib-es/__tests__/unit/validator-app.unit.test.js +144 -0
  122. package/lib-es/__tests__/unit/validator-app.unit.test.js.map +1 -0
  123. package/lib-es/bridge.integration.test.d.ts +4 -0
  124. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  125. package/lib-es/bridge.integration.test.js +864 -0
  126. package/lib-es/bridge.integration.test.js.map +1 -0
  127. package/lib-es/buildTransaction.test.d.ts +2 -0
  128. package/lib-es/buildTransaction.test.d.ts.map +1 -0
  129. package/lib-es/buildTransaction.test.js +162 -0
  130. package/lib-es/buildTransaction.test.js.map +1 -0
  131. package/lib-es/cryptoAssetsStore.test.d.ts +2 -0
  132. package/lib-es/cryptoAssetsStore.test.d.ts.map +1 -0
  133. package/lib-es/cryptoAssetsStore.test.js +13 -0
  134. package/lib-es/cryptoAssetsStore.test.js.map +1 -0
  135. package/lib-es/network/chain/account/parser.d.ts +1 -1
  136. package/lib-es/network/chain/account/stake.d.ts +23 -23
  137. package/lib-es/network/chain/account/token.d.ts +7 -7
  138. package/lib-es/network/chain/instruction/stake/types.d.ts +8 -8
  139. package/lib-es/network/chain/instruction/system/types.d.ts +10 -10
  140. package/lib-es/network/chain/web3.integration.test.d.ts +2 -0
  141. package/lib-es/network/chain/web3.integration.test.d.ts.map +1 -0
  142. package/lib-es/network/chain/web3.integration.test.js +68 -0
  143. package/lib-es/network/chain/web3.integration.test.js.map +1 -0
  144. package/lib-es/offchainMessage/format.unit.test.d.ts +2 -0
  145. package/lib-es/offchainMessage/format.unit.test.d.ts.map +1 -0
  146. package/lib-es/offchainMessage/format.unit.test.js +122 -0
  147. package/lib-es/offchainMessage/format.unit.test.js.map +1 -0
  148. package/lib-es/preload.test.d.ts +2 -0
  149. package/lib-es/preload.test.d.ts.map +1 -0
  150. package/lib-es/preload.test.js +7 -0
  151. package/lib-es/preload.test.js.map +1 -0
  152. package/lib-es/prepareTransaction.d.ts.map +1 -1
  153. package/lib-es/prepareTransaction.js +0 -4
  154. package/lib-es/prepareTransaction.js.map +1 -1
  155. package/lib-es/prepareTransaction.test.d.ts +2 -0
  156. package/lib-es/prepareTransaction.test.d.ts.map +1 -0
  157. package/lib-es/prepareTransaction.test.js +134 -0
  158. package/lib-es/prepareTransaction.test.js.map +1 -0
  159. package/lib-es/signOperation.d.ts.map +1 -1
  160. package/lib-es/signOperation.js +0 -2
  161. package/lib-es/signOperation.js.map +1 -1
  162. package/lib-es/signOperation.test.d.ts +3 -0
  163. package/lib-es/signOperation.test.d.ts.map +1 -0
  164. package/lib-es/signOperation.test.js +135 -0
  165. package/lib-es/signOperation.test.js.map +1 -0
  166. package/lib-es/signer.d.ts +0 -1
  167. package/lib-es/signer.d.ts.map +1 -1
  168. package/lib-es/signer.js.map +1 -1
  169. package/lib-es/tests/preload.fixtures.d.ts +5 -0
  170. package/lib-es/tests/preload.fixtures.d.ts.map +1 -0
  171. package/lib-es/tests/preload.fixtures.js +25 -0
  172. package/lib-es/tests/preload.fixtures.js.map +1 -0
  173. package/lib-es/tests/preload.unit.test.d.ts +2 -0
  174. package/lib-es/tests/preload.unit.test.d.ts.map +1 -0
  175. package/lib-es/tests/preload.unit.test.js +147 -0
  176. package/lib-es/tests/preload.unit.test.js.map +1 -0
  177. package/lib-es/tests/stakes-bridge.unit.test.d.ts +2 -0
  178. package/lib-es/tests/stakes-bridge.unit.test.d.ts.map +1 -0
  179. package/lib-es/tests/stakes-bridge.unit.test.js +161 -0
  180. package/lib-es/tests/stakes-bridge.unit.test.js.map +1 -0
  181. package/lib-es/tests/test-onchain-data.fixture.d.ts +20 -0
  182. package/lib-es/tests/test-onchain-data.fixture.d.ts.map +1 -0
  183. package/lib-es/tests/test-onchain-data.fixture.js +28 -0
  184. package/lib-es/tests/test-onchain-data.fixture.js.map +1 -0
  185. package/lib-es/tests/tokens-bridge.unit.test.d.ts +2 -0
  186. package/lib-es/tests/tokens-bridge.unit.test.d.ts.map +1 -0
  187. package/lib-es/tests/tokens-bridge.unit.test.js +610 -0
  188. package/lib-es/tests/tokens-bridge.unit.test.js.map +1 -0
  189. package/lib-es/tx-fees.js +0 -2
  190. package/lib-es/tx-fees.js.map +1 -1
  191. package/lib-es/types.d.ts +1 -2
  192. package/lib-es/types.d.ts.map +1 -1
  193. package/package.json +9 -9
  194. package/src/prepareTransaction.ts +0 -4
  195. package/src/signOperation.ts +0 -2
  196. package/src/signer.ts +0 -1
  197. package/src/tests/preload.fixtures.ts +1 -1
  198. package/src/tx-fees.ts +0 -2
  199. package/src/types.ts +1 -2
@@ -0,0 +1,870 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dataset = void 0;
7
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ const solana_scanAccounts_1_1 = __importDefault(require("./datasets/solana.scanAccounts.1"));
9
+ const errors_1 = require("@ledgerhq/errors");
10
+ const errors_2 = require("./errors");
11
+ const logic_1 = require("./logic");
12
+ const createTransaction_1 = __importDefault(require("./createTransaction"));
13
+ const fp_1 = require("lodash/fp");
14
+ const utils_1 = require("./utils");
15
+ const live_env_1 = require("@ledgerhq/live-env");
16
+ const accountId_1 = require("@ledgerhq/coin-framework/lib/account/accountId");
17
+ const test_onchain_data_fixture_1 = require("./tests/test-onchain-data.fixture");
18
+ const cryptoAssetsStore_1 = require("./cryptoAssetsStore");
19
+ const mainAccId = (0, accountId_1.encodeAccountId)({
20
+ type: "js",
21
+ version: "2",
22
+ currencyId: "solana",
23
+ xpubOrAddress: test_onchain_data_fixture_1.testOnChainData.fundedSenderAddress,
24
+ derivationMode: "solanaMain",
25
+ });
26
+ const wSolSubAccId = (0, logic_1.encodeAccountIdWithTokenAccountAddress)(mainAccId, test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccAddress);
27
+ const wSolToken = (0, cryptoAssetsStore_1.getCryptoAssetsStore)().findTokenByAddressInCurrency("So11111111111111111111111111111111111111112", "solana");
28
+ const fees = (signatureCount) => new bignumber_js_1.default(signatureCount * test_onchain_data_fixture_1.testOnChainData.fees.lamportsPerSignature);
29
+ const zero = new bignumber_js_1.default(0);
30
+ const solana = {
31
+ scanAccounts: [solana_scanAccounts_1_1.default],
32
+ // FIXME Ordering of validators must be always the same, for this test to be stable:
33
+ // https://github.com/LedgerHQ/ledger-live-common/blob/develop/src/__tests__/test-helpers/bridge.ts#L171-L188
34
+ FIXME_ignorePreloadFields: ["validators", "splTokens"],
35
+ accounts: [
36
+ {
37
+ raw: makeAccount(test_onchain_data_fixture_1.testOnChainData.fundedSenderAddress),
38
+ /*
39
+ Solana integration is written in such a way that requires
40
+ prepareTransaction to be called before any meaningfull status
41
+ can be calculated. The general bridge tests do not run prepareTransaction
42
+ on all tests, so skip them in the general runner, but make alternatives for them.
43
+ */
44
+ FIXME_tests: [
45
+ "balance is sum of ops",
46
+ "Default empty recipient have a recipientError",
47
+ "invalid recipient have a recipientError",
48
+ "can be called on an empty transaction",
49
+ ],
50
+ transactions: [
51
+ ...recipientRequired(),
52
+ ...recipientNotValid(),
53
+ ...recipientIsSameAsSender(),
54
+ ...memoIsTooLong(),
55
+ {
56
+ name: "status is error: called on an empty transaction",
57
+ transaction: (0, createTransaction_1.default)({}),
58
+ expectedStatus: {
59
+ errors: {
60
+ recipient: new errors_1.RecipientRequired(),
61
+ },
62
+ warnings: {},
63
+ estimatedFees: fees(1),
64
+ amount: zero,
65
+ totalSpent: fees(1),
66
+ },
67
+ },
68
+ ...transferTests(),
69
+ ...stakingTests(),
70
+ ...tokenTests(),
71
+ ],
72
+ },
73
+ ],
74
+ };
75
+ exports.dataset = {
76
+ implementations: [(0, live_env_1.getEnv)("MOCK") ? "mock" : "js"], // FIXME we should actually put both mock and js like other dataset do
77
+ currencies: {
78
+ solana,
79
+ },
80
+ };
81
+ function makeAccount(freshAddress) {
82
+ return {
83
+ id: mainAccId,
84
+ seedIdentifier: "",
85
+ derivationMode: "solanaMain",
86
+ index: 0,
87
+ freshAddress,
88
+ freshAddressPath: "",
89
+ blockHeight: 0,
90
+ operations: [],
91
+ pendingOperations: [],
92
+ currencyId: "solana",
93
+ lastSyncDate: "",
94
+ balance: "0",
95
+ subAccounts: [makeSubTokenAccount()],
96
+ };
97
+ }
98
+ function makeSubTokenAccount() {
99
+ return {
100
+ type: "TokenAccountRaw",
101
+ id: wSolSubAccId,
102
+ parentId: mainAccId,
103
+ tokenId: wSolToken.id,
104
+ balance: "0",
105
+ operations: [],
106
+ pendingOperations: [],
107
+ };
108
+ }
109
+ function recipientRequired() {
110
+ const models = [
111
+ {
112
+ kind: "token.transfer",
113
+ uiState: {
114
+ subAccountId: wSolSubAccId,
115
+ },
116
+ },
117
+ {
118
+ kind: "transfer",
119
+ uiState: {},
120
+ },
121
+ ];
122
+ return models.map(model => {
123
+ return {
124
+ name: `${model.kind} :: status is error: recipient required`,
125
+ transaction: {
126
+ model,
127
+ amount: zero,
128
+ recipient: "",
129
+ family: "solana",
130
+ },
131
+ expectedStatus: {
132
+ errors: {
133
+ recipient: new errors_1.RecipientRequired(),
134
+ },
135
+ warnings: {},
136
+ estimatedFees: fees(1),
137
+ amount: zero,
138
+ totalSpent: model.kind === "transfer" ? fees(1) : zero,
139
+ },
140
+ };
141
+ });
142
+ }
143
+ function recipientNotValid() {
144
+ return recipientRequired().map(spec => {
145
+ return {
146
+ ...spec,
147
+ transaction: {
148
+ ...spec.transaction,
149
+ recipient: "invalid address",
150
+ },
151
+ expectedStatus: {
152
+ ...spec.expectedStatus,
153
+ errors: {
154
+ recipient: new errors_1.InvalidAddress(),
155
+ },
156
+ },
157
+ };
158
+ });
159
+ }
160
+ function recipientIsSameAsSender() {
161
+ return recipientRequired().map(spec => {
162
+ return {
163
+ ...spec,
164
+ transaction: {
165
+ ...spec.transaction,
166
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedSenderAddress,
167
+ },
168
+ expectedStatus: {
169
+ ...spec.expectedStatus,
170
+ errors: {
171
+ recipient: new errors_1.InvalidAddressBecauseDestinationIsAlsoSource(),
172
+ },
173
+ },
174
+ };
175
+ });
176
+ }
177
+ function memoIsTooLong() {
178
+ return (0, fp_1.compact)(recipientRequired().map(spec => {
179
+ const tx = spec.transaction;
180
+ switch (tx.model.kind) {
181
+ case "transfer":
182
+ case "token.transfer":
183
+ tx.model.uiState.memo = "c".repeat(logic_1.MAX_MEMO_LENGTH + 1);
184
+ return {
185
+ ...spec,
186
+ transaction: {
187
+ ...spec.transaction,
188
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
189
+ },
190
+ expectedStatus: {
191
+ ...spec.expectedStatus,
192
+ errors: {
193
+ memo: new errors_2.SolanaMemoIsTooLong(),
194
+ },
195
+ },
196
+ };
197
+ case "token.createATA":
198
+ case "token.approve":
199
+ case "token.revoke":
200
+ case "stake.createAccount":
201
+ case "stake.delegate":
202
+ case "stake.undelegate":
203
+ case "stake.withdraw":
204
+ case "stake.split":
205
+ case "raw":
206
+ return undefined;
207
+ default:
208
+ return (0, utils_1.assertUnreachable)(tx.model);
209
+ }
210
+ }));
211
+ }
212
+ function transferTests() {
213
+ return [
214
+ {
215
+ name: "transfer :: status is success: not all amount",
216
+ transaction: {
217
+ model: {
218
+ kind: "transfer",
219
+ uiState: {},
220
+ },
221
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance.dividedBy(2),
222
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
223
+ family: "solana",
224
+ },
225
+ expectedStatus: {
226
+ errors: {},
227
+ warnings: {},
228
+ estimatedFees: fees(1),
229
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance.dividedBy(2),
230
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance.dividedBy(2).plus(fees(1)),
231
+ },
232
+ },
233
+ {
234
+ name: "transfer :: status is success: all amount",
235
+ transaction: {
236
+ model: {
237
+ kind: "transfer",
238
+ uiState: {},
239
+ },
240
+ useAllAmount: true,
241
+ amount: zero,
242
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
243
+ family: "solana",
244
+ },
245
+ expectedStatus: {
246
+ errors: {},
247
+ warnings: {},
248
+ estimatedFees: fees(1),
249
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance
250
+ .minus(fees(1))
251
+ .minus(test_onchain_data_fixture_1.testOnChainData.fees.systemAccountRentExempt),
252
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance.minus(test_onchain_data_fixture_1.testOnChainData.fees.systemAccountRentExempt),
253
+ },
254
+ },
255
+ {
256
+ name: "transfer :: status is error: not enough balance, not all amount",
257
+ transaction: {
258
+ model: {
259
+ kind: "transfer",
260
+ uiState: {},
261
+ },
262
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance,
263
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
264
+ family: "solana",
265
+ },
266
+ expectedStatus: {
267
+ errors: {
268
+ amount: new errors_1.NotEnoughBalance(),
269
+ },
270
+ warnings: {},
271
+ estimatedFees: fees(1),
272
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance,
273
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance.plus(fees(1)),
274
+ },
275
+ },
276
+ {
277
+ name: "transfer :: status is error: amount is 0",
278
+ transaction: {
279
+ model: {
280
+ kind: "transfer",
281
+ uiState: {},
282
+ },
283
+ amount: zero,
284
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
285
+ family: "solana",
286
+ },
287
+ expectedStatus: {
288
+ errors: {
289
+ amount: new errors_1.AmountRequired(),
290
+ },
291
+ warnings: {},
292
+ estimatedFees: fees(1),
293
+ amount: zero,
294
+ totalSpent: fees(1),
295
+ },
296
+ },
297
+ {
298
+ name: "transfer :: status is error: amount is negative",
299
+ transaction: {
300
+ model: {
301
+ kind: "transfer",
302
+ uiState: {},
303
+ },
304
+ amount: new bignumber_js_1.default(-1),
305
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
306
+ family: "solana",
307
+ },
308
+ expectedStatus: {
309
+ errors: {
310
+ amount: new errors_1.AmountRequired(),
311
+ },
312
+ warnings: {},
313
+ estimatedFees: fees(1),
314
+ amount: new bignumber_js_1.default(-1),
315
+ totalSpent: zero,
316
+ },
317
+ },
318
+ {
319
+ name: "transfer :: status is warning: recipient wallet not funded",
320
+ transaction: {
321
+ model: {
322
+ kind: "transfer",
323
+ uiState: {},
324
+ },
325
+ amount: new bignumber_js_1.default(1),
326
+ recipient: test_onchain_data_fixture_1.testOnChainData.unfundedAddress,
327
+ family: "solana",
328
+ },
329
+ expectedStatus: {
330
+ errors: {},
331
+ warnings: {
332
+ recipient: new errors_2.SolanaAccountNotFunded(),
333
+ },
334
+ estimatedFees: fees(1),
335
+ amount: new bignumber_js_1.default(1),
336
+ totalSpent: fees(1).plus(1),
337
+ },
338
+ },
339
+ {
340
+ name: "transfer :: status is warning: recipient address is off ed25519",
341
+ transaction: {
342
+ model: {
343
+ kind: "transfer",
344
+ uiState: {},
345
+ },
346
+ amount: new bignumber_js_1.default(1),
347
+ recipient: test_onchain_data_fixture_1.testOnChainData.offEd25519Address,
348
+ family: "solana",
349
+ },
350
+ expectedStatus: {
351
+ errors: {},
352
+ warnings: {
353
+ recipient: new errors_2.SolanaAccountNotFunded(),
354
+ recipientOffCurve: new errors_2.SolanaAddressOffEd25519(),
355
+ },
356
+ estimatedFees: fees(1),
357
+ amount: new bignumber_js_1.default(1),
358
+ totalSpent: fees(1).plus(1),
359
+ },
360
+ },
361
+ ];
362
+ }
363
+ function tokenTests() {
364
+ return [
365
+ {
366
+ name: "token.transfer :: status is success: recipient is funded wallet, assoc token acc exists",
367
+ transaction: {
368
+ model: {
369
+ kind: "token.transfer",
370
+ uiState: {
371
+ subAccountId: wSolSubAccId,
372
+ },
373
+ },
374
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
375
+ recipient: test_onchain_data_fixture_1.testOnChainData.fundedAddress,
376
+ family: "solana",
377
+ },
378
+ expectedStatus: {
379
+ errors: {},
380
+ warnings: {},
381
+ estimatedFees: fees(1),
382
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
383
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
384
+ },
385
+ },
386
+ {
387
+ name: "token.transfer :: status is success: recipient is correct mint token acc",
388
+ transaction: {
389
+ model: {
390
+ kind: "token.transfer",
391
+ uiState: {
392
+ subAccountId: wSolSubAccId,
393
+ },
394
+ },
395
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
396
+ recipient: test_onchain_data_fixture_1.testOnChainData.wSolFundedAccountAssocTokenAccAddress,
397
+ family: "solana",
398
+ },
399
+ expectedStatus: {
400
+ errors: {},
401
+ warnings: {},
402
+ estimatedFees: fees(1),
403
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
404
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
405
+ },
406
+ },
407
+ {
408
+ name: "token.transfer :: status is error: recipient is another mint token acc",
409
+ transaction: {
410
+ model: {
411
+ kind: "token.transfer",
412
+ uiState: {
413
+ subAccountId: wSolSubAccId,
414
+ },
415
+ },
416
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
417
+ recipient: test_onchain_data_fixture_1.testOnChainData.notWSolTokenAccAddress,
418
+ family: "solana",
419
+ },
420
+ expectedStatus: {
421
+ errors: {
422
+ recipient: new errors_2.SolanaTokenAccountHoldsAnotherToken(),
423
+ },
424
+ warnings: {},
425
+ estimatedFees: fees(1),
426
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
427
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
428
+ },
429
+ },
430
+ {
431
+ name: "token.transfer :: status is warning: recipient is off curve",
432
+ transaction: {
433
+ model: {
434
+ kind: "token.transfer",
435
+ uiState: {
436
+ subAccountId: wSolSubAccId,
437
+ },
438
+ },
439
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
440
+ recipient: test_onchain_data_fixture_1.testOnChainData.offEd25519Address,
441
+ family: "solana",
442
+ },
443
+ expectedStatus: {
444
+ errors: {
445
+ recipient: new errors_2.SolanaAddressOffEd25519(),
446
+ },
447
+ warnings: {},
448
+ estimatedFees: fees(1),
449
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
450
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
451
+ },
452
+ },
453
+ {
454
+ name: "token.transfer :: status is success: recipient is wallet and no assoc token acc exists (will be created)",
455
+ transaction: {
456
+ model: {
457
+ kind: "token.transfer",
458
+ uiState: {
459
+ subAccountId: wSolSubAccId,
460
+ },
461
+ },
462
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
463
+ recipient: test_onchain_data_fixture_1.testOnChainData.unfundedAddress,
464
+ family: "solana",
465
+ },
466
+ expectedStatus: {
467
+ errors: {},
468
+ warnings: {
469
+ recipient: new errors_2.SolanaRecipientAssociatedTokenAccountWillBeFunded(),
470
+ },
471
+ // this fee is dynamic, skip
472
+ //estimatedFees: new BigNumber(2044280),
473
+ amount: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
474
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.wSolSenderAssocTokenAccBalance.dividedBy(2),
475
+ },
476
+ },
477
+ ];
478
+ }
479
+ function stakingTests() {
480
+ return [
481
+ {
482
+ name: "stake.createAccount :: status is error: amount is negative",
483
+ transaction: {
484
+ family: "solana",
485
+ model: {
486
+ kind: "stake.createAccount",
487
+ uiState: {
488
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.validatorAddress },
489
+ },
490
+ },
491
+ recipient: "",
492
+ amount: new bignumber_js_1.default(-1),
493
+ },
494
+ expectedStatus: {
495
+ amount: new bignumber_js_1.default(-1),
496
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
497
+ totalSpent: zero,
498
+ errors: {
499
+ amount: new errors_1.AmountRequired(),
500
+ },
501
+ },
502
+ },
503
+ {
504
+ name: "stake.createAccount :: status is error: amount is zero",
505
+ transaction: {
506
+ family: "solana",
507
+ model: {
508
+ kind: "stake.createAccount",
509
+ uiState: {
510
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.validatorAddress },
511
+ },
512
+ },
513
+ recipient: "",
514
+ amount: zero,
515
+ },
516
+ expectedStatus: {
517
+ amount: zero,
518
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
519
+ totalSpent: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
520
+ errors: {
521
+ amount: new errors_1.AmountRequired(),
522
+ },
523
+ },
524
+ },
525
+ {
526
+ name: "stake.createAccount :: status is error: not enough balance, not all amount",
527
+ transaction: {
528
+ family: "solana",
529
+ model: {
530
+ kind: "stake.createAccount",
531
+ uiState: {
532
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.validatorAddress },
533
+ },
534
+ },
535
+ recipient: "",
536
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance,
537
+ },
538
+ expectedStatus: {
539
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance,
540
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
541
+ totalSpent: fees(1)
542
+ .plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt)
543
+ .plus(test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance),
544
+ errors: {
545
+ amount: new errors_1.NotEnoughBalance(),
546
+ },
547
+ },
548
+ },
549
+ {
550
+ name: "stake.createAccount :: status is error: validator required",
551
+ transaction: {
552
+ family: "solana",
553
+ model: {
554
+ kind: "stake.createAccount",
555
+ uiState: {
556
+ delegate: { voteAccAddress: "" },
557
+ },
558
+ },
559
+ recipient: "",
560
+ amount: new bignumber_js_1.default(1),
561
+ },
562
+ expectedStatus: {
563
+ amount: new bignumber_js_1.default(1),
564
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
565
+ totalSpent: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt).plus(1),
566
+ errors: {
567
+ voteAccAddr: new errors_2.SolanaValidatorRequired(),
568
+ },
569
+ },
570
+ },
571
+ {
572
+ name: "stake.createAccount :: status is error: validator has invalid address",
573
+ transaction: {
574
+ family: "solana",
575
+ model: {
576
+ kind: "stake.createAccount",
577
+ uiState: {
578
+ delegate: { voteAccAddress: "invalid address" },
579
+ },
580
+ },
581
+ recipient: "",
582
+ amount: new bignumber_js_1.default(1),
583
+ },
584
+ expectedStatus: {
585
+ amount: new bignumber_js_1.default(1),
586
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
587
+ totalSpent: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt).plus(1),
588
+ errors: {
589
+ voteAccAddr: new errors_1.InvalidAddress(),
590
+ },
591
+ },
592
+ },
593
+ {
594
+ name: "stake.createAccount :: status is error: validator invalid",
595
+ transaction: {
596
+ family: "solana",
597
+ model: {
598
+ kind: "stake.createAccount",
599
+ uiState: {
600
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.fundedSenderAddress },
601
+ },
602
+ },
603
+ recipient: "",
604
+ amount: new bignumber_js_1.default(1),
605
+ },
606
+ expectedStatus: {
607
+ amount: new bignumber_js_1.default(1),
608
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
609
+ totalSpent: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt).plus(1),
610
+ errors: {
611
+ voteAccAddr: new errors_2.SolanaInvalidValidator(),
612
+ },
613
+ },
614
+ },
615
+ {
616
+ name: "stake.createAccount :: status is success, not all amount",
617
+ transaction: {
618
+ family: "solana",
619
+ model: {
620
+ kind: "stake.createAccount",
621
+ uiState: {
622
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.validatorAddress },
623
+ },
624
+ },
625
+ recipient: "",
626
+ amount: new bignumber_js_1.default(1),
627
+ },
628
+ expectedStatus: {
629
+ amount: new bignumber_js_1.default(1),
630
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
631
+ totalSpent: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt).plus(1),
632
+ errors: {},
633
+ },
634
+ },
635
+ {
636
+ name: "stake.createAccount :: status is success, all amount",
637
+ transaction: {
638
+ family: "solana",
639
+ model: {
640
+ kind: "stake.createAccount",
641
+ uiState: {
642
+ delegate: { voteAccAddress: test_onchain_data_fixture_1.testOnChainData.validatorAddress },
643
+ },
644
+ },
645
+ recipient: "",
646
+ useAllAmount: true,
647
+ amount: zero,
648
+ },
649
+ expectedStatus: {
650
+ amount: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance
651
+ .minus(fees(1)) // transaction fee
652
+ .minus(fees(1).multipliedBy(2)) // undelegate + withdraw fees reserve
653
+ .minus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt)
654
+ .minus(test_onchain_data_fixture_1.testOnChainData.fees.systemAccountRentExempt),
655
+ estimatedFees: fees(1).plus(test_onchain_data_fixture_1.testOnChainData.fees.stakeAccountRentExempt),
656
+ totalSpent: test_onchain_data_fixture_1.testOnChainData.fundedSenderBalance
657
+ .minus(test_onchain_data_fixture_1.testOnChainData.fees.systemAccountRentExempt)
658
+ .minus(fees(1).multipliedBy(2)), // undelegate + withdraw fees reserve,
659
+ errors: {},
660
+ },
661
+ },
662
+ {
663
+ name: "stake.delegate :: status is error: stake account address and validator address required",
664
+ transaction: {
665
+ family: "solana",
666
+ model: {
667
+ kind: "stake.delegate",
668
+ uiState: {
669
+ stakeAccAddr: "",
670
+ voteAccAddr: "",
671
+ },
672
+ },
673
+ recipient: "",
674
+ amount: zero,
675
+ },
676
+ expectedStatus: {
677
+ amount: zero,
678
+ estimatedFees: fees(1),
679
+ totalSpent: fees(1),
680
+ errors: {
681
+ stakeAccAddr: new errors_2.SolanaStakeAccountRequired(),
682
+ voteAccAddr: new errors_2.SolanaValidatorRequired(),
683
+ },
684
+ },
685
+ },
686
+ {
687
+ name: "stake.delegate :: status is error: stake account address and validator address are invalid",
688
+ transaction: {
689
+ family: "solana",
690
+ model: {
691
+ kind: "stake.delegate",
692
+ uiState: {
693
+ stakeAccAddr: "invalid address",
694
+ voteAccAddr: "invalid address",
695
+ },
696
+ },
697
+ recipient: "",
698
+ amount: zero,
699
+ },
700
+ expectedStatus: {
701
+ amount: zero,
702
+ estimatedFees: fees(1),
703
+ totalSpent: fees(1),
704
+ errors: {
705
+ stakeAccAddr: new errors_1.InvalidAddress(),
706
+ voteAccAddr: new errors_1.InvalidAddress(),
707
+ },
708
+ },
709
+ },
710
+ {
711
+ name: "stake.delegate :: status is error: stake account not found",
712
+ transaction: {
713
+ family: "solana",
714
+ model: {
715
+ kind: "stake.delegate",
716
+ uiState: {
717
+ stakeAccAddr: test_onchain_data_fixture_1.testOnChainData.unfundedAddress,
718
+ voteAccAddr: test_onchain_data_fixture_1.testOnChainData.validatorAddress,
719
+ },
720
+ },
721
+ recipient: "",
722
+ amount: zero,
723
+ },
724
+ expectedStatus: {
725
+ amount: zero,
726
+ estimatedFees: fees(1),
727
+ totalSpent: fees(1),
728
+ errors: {
729
+ stakeAccAddr: new errors_2.SolanaStakeAccountNotFound(),
730
+ },
731
+ },
732
+ },
733
+ {
734
+ name: "stake.undelegate :: status is error: stake account required",
735
+ transaction: {
736
+ family: "solana",
737
+ model: {
738
+ kind: "stake.undelegate",
739
+ uiState: {
740
+ stakeAccAddr: "",
741
+ },
742
+ },
743
+ recipient: "",
744
+ amount: zero,
745
+ },
746
+ expectedStatus: {
747
+ amount: zero,
748
+ estimatedFees: fees(1),
749
+ totalSpent: fees(1),
750
+ errors: {
751
+ stakeAccAddr: new errors_2.SolanaStakeAccountRequired(),
752
+ },
753
+ },
754
+ },
755
+ {
756
+ name: "stake.undelegate :: status is error: stake account invalid",
757
+ transaction: {
758
+ family: "solana",
759
+ model: {
760
+ kind: "stake.undelegate",
761
+ uiState: {
762
+ stakeAccAddr: "invalid address",
763
+ },
764
+ },
765
+ recipient: "",
766
+ amount: zero,
767
+ },
768
+ expectedStatus: {
769
+ amount: zero,
770
+ estimatedFees: fees(1),
771
+ totalSpent: fees(1),
772
+ errors: {
773
+ stakeAccAddr: new errors_1.InvalidAddress(),
774
+ },
775
+ },
776
+ },
777
+ {
778
+ name: "stake.undelegate :: status is error: stake account not found",
779
+ transaction: {
780
+ family: "solana",
781
+ model: {
782
+ kind: "stake.undelegate",
783
+ uiState: {
784
+ stakeAccAddr: test_onchain_data_fixture_1.testOnChainData.unfundedAddress,
785
+ },
786
+ },
787
+ recipient: "",
788
+ amount: zero,
789
+ },
790
+ expectedStatus: {
791
+ amount: zero,
792
+ estimatedFees: fees(1),
793
+ totalSpent: fees(1),
794
+ errors: {
795
+ stakeAccAddr: new errors_2.SolanaStakeAccountNotFound(),
796
+ },
797
+ },
798
+ },
799
+ {
800
+ name: "stake.withdraw :: status is error: stake account required",
801
+ transaction: {
802
+ family: "solana",
803
+ model: {
804
+ kind: "stake.withdraw",
805
+ uiState: {
806
+ stakeAccAddr: "",
807
+ },
808
+ },
809
+ recipient: "",
810
+ amount: zero,
811
+ },
812
+ expectedStatus: {
813
+ amount: zero,
814
+ estimatedFees: fees(1),
815
+ totalSpent: fees(1),
816
+ errors: {
817
+ stakeAccAddr: new errors_2.SolanaStakeAccountRequired(),
818
+ },
819
+ },
820
+ },
821
+ {
822
+ name: "stake.withdraw :: status is error: stake account address invalid",
823
+ transaction: {
824
+ family: "solana",
825
+ model: {
826
+ kind: "stake.withdraw",
827
+ uiState: {
828
+ stakeAccAddr: "invalid address",
829
+ },
830
+ },
831
+ recipient: "",
832
+ amount: zero,
833
+ },
834
+ expectedStatus: {
835
+ amount: zero,
836
+ estimatedFees: fees(1),
837
+ totalSpent: fees(1),
838
+ errors: {
839
+ stakeAccAddr: new errors_1.InvalidAddress(),
840
+ },
841
+ },
842
+ },
843
+ {
844
+ name: "stake.withdraw :: status is error: stake account not found",
845
+ transaction: {
846
+ family: "solana",
847
+ model: {
848
+ kind: "stake.withdraw",
849
+ uiState: {
850
+ stakeAccAddr: test_onchain_data_fixture_1.testOnChainData.unfundedAddress,
851
+ },
852
+ },
853
+ recipient: "",
854
+ amount: zero,
855
+ },
856
+ expectedStatus: {
857
+ amount: zero,
858
+ estimatedFees: fees(1),
859
+ totalSpent: fees(1),
860
+ errors: {
861
+ stakeAccAddr: new errors_2.SolanaStakeAccountNotFound(),
862
+ },
863
+ },
864
+ },
865
+ ];
866
+ }
867
+ describe("Solana bridge", () => {
868
+ test.todo("This is an empty test to make jest command pass. Remove it once there is a real test.");
869
+ });
870
+ //# sourceMappingURL=bridge.integration.test.js.map