@ledgerhq/coin-aptos 2.0.0-nightly.3 → 2.0.0-nightly.5
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +17 -0
- package/lib/__tests__/api/index.test.js +5 -61
- package/lib/__tests__/api/index.test.js.map +1 -1
- package/lib/__tests__/bridge/buildTransaction.test.js +2 -57
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +8 -109
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +37 -175
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +115 -889
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/signOperation.test.js +2 -128
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib/__tests__/bridge/synchronisation.test.js +67 -1214
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/api/graphql/queries.js +6 -6
- package/lib/api/graphql/types.d.ts +9 -9
- package/lib/api/graphql/types.d.ts.map +1 -1
- package/lib/api/index.d.ts +2 -5
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +4 -30
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/bridge.fixture.d.ts +0 -2
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +13 -85
- package/lib/bridge/bridge.fixture.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +3 -29
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +7 -12
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +14 -28
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/logic.d.ts +8 -13
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +54 -152
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +2 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +3 -17
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +0 -15
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +4 -127
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/constants.d.ts +1 -5
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +2 -6
- package/lib/constants.js.map +1 -1
- package/lib/test/bot-specs.d.ts.map +1 -1
- package/lib/test/bot-specs.js +1 -40
- package/lib/test/bot-specs.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +62 -43
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/speculos-deviceActions.d.ts +0 -1
- package/lib/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib/test/speculos-deviceActions.js +5 -37
- package/lib/test/speculos-deviceActions.js.map +1 -1
- package/lib/types/index.d.ts +7 -18
- package/lib/types/index.d.ts.map +1 -1
- package/lib-es/__tests__/api/index.test.js +5 -61
- package/lib-es/__tests__/api/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/buildTransaction.test.js +3 -58
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +9 -110
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +39 -177
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +117 -891
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/signOperation.test.js +2 -128
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
- package/lib-es/__tests__/bridge/synchronisation.test.js +69 -1213
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/api/graphql/queries.js +6 -6
- package/lib-es/api/graphql/types.d.ts +9 -9
- package/lib-es/api/graphql/types.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +2 -5
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +4 -30
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/bridge.fixture.d.ts +0 -2
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +12 -82
- package/lib-es/bridge/bridge.fixture.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +4 -30
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +8 -13
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +14 -28
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +8 -13
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +52 -146
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +2 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +3 -17
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +0 -15
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +3 -123
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/constants.d.ts +1 -5
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +1 -5
- package/lib-es/constants.js.map +1 -1
- package/lib-es/test/bot-specs.d.ts.map +1 -1
- package/lib-es/test/bot-specs.js +2 -41
- package/lib-es/test/bot-specs.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +59 -43
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/speculos-deviceActions.d.ts +0 -1
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/test/speculos-deviceActions.js +4 -36
- package/lib-es/test/speculos-deviceActions.js.map +1 -1
- package/lib-es/types/index.d.ts +7 -18
- package/lib-es/types/index.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/__tests__/api/index.test.ts +5 -75
- package/src/__tests__/bridge/buildTransaction.test.ts +3 -85
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +9 -144
- package/src/__tests__/bridge/getTransactionStatus.test.ts +38 -217
- package/src/__tests__/bridge/logic.test.ts +118 -922
- package/src/__tests__/bridge/signOperation.test.ts +2 -141
- package/src/__tests__/bridge/synchronisation.test.ts +71 -1265
- package/src/api/graphql/queries.ts +6 -6
- package/src/api/graphql/types.ts +9 -9
- package/src/api/index.ts +5 -32
- package/src/bridge/bridge.fixture.ts +12 -91
- package/src/bridge/buildTransaction.ts +6 -39
- package/src/bridge/estimateMaxSpendable.ts +1 -1
- package/src/bridge/getFeesForTransaction.ts +9 -14
- package/src/bridge/getTransactionStatus.ts +13 -35
- package/src/bridge/logic.ts +63 -202
- package/src/bridge/prepareTransaction.ts +3 -4
- package/src/bridge/signOperation.ts +3 -19
- package/src/bridge/synchronisation.ts +3 -170
- package/src/constants.ts +1 -12
- package/src/test/bot-specs.ts +3 -63
- package/src/test/bridgeDatasetTest.ts +59 -45
- package/src/test/speculos-deviceActions.ts +4 -40
- package/src/types/index.ts +1 -15
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import { APTOS_ASSET_ID, APTOS_COIN_CHANGE,
|
|
3
|
-
import { calculateAmount, compareAddress,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
jest.mock("@ledgerhq/cryptoassets");
|
|
8
|
-
jest.mock("@ledgerhq/coin-framework/account/index");
|
|
2
|
+
import { APTOS_ASSET_ID, APTOS_COIN_CHANGE, DIRECTION } from "../../constants";
|
|
3
|
+
import { calculateAmount, compareAddress, getAptosAmounts, getFunctionAddress, isChangeOfAptos, isTestnet, processRecipients, getMaxSendBalance, normalizeTransactionOptions, getBlankOperation, txsToOps, } from "../../bridge/logic";
|
|
4
|
+
jest.mock("@ledgerhq/cryptoassets", () => ({
|
|
5
|
+
getCryptoCurrencyById: jest.fn(),
|
|
6
|
+
}));
|
|
9
7
|
describe("Aptos logic ", () => {
|
|
10
8
|
describe("isTestnet", () => {
|
|
11
9
|
it("should return true for testnet currencies", () => {
|
|
@@ -18,44 +16,37 @@ describe("Aptos logic ", () => {
|
|
|
18
16
|
describe("getMaxSendBalance", () => {
|
|
19
17
|
it("should return the correct max send balance when amount is greater than total gas", () => {
|
|
20
18
|
const amount = new BigNumber(1000000);
|
|
21
|
-
const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
|
|
22
|
-
const transaction = createFixtureTransaction();
|
|
23
19
|
const gas = new BigNumber(200);
|
|
24
20
|
const gasPrice = new BigNumber(100);
|
|
25
|
-
const result = getMaxSendBalance(gas, gasPrice
|
|
21
|
+
const result = getMaxSendBalance(amount, gas, gasPrice);
|
|
26
22
|
expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
|
|
27
23
|
});
|
|
28
24
|
it("should return zero when amount is less than total gas", () => {
|
|
29
|
-
const
|
|
30
|
-
const transaction = createFixtureTransaction();
|
|
25
|
+
const amount = new BigNumber(1000);
|
|
31
26
|
const gas = new BigNumber(200);
|
|
32
27
|
const gasPrice = new BigNumber(100);
|
|
33
|
-
const result = getMaxSendBalance(gas, gasPrice
|
|
28
|
+
const result = getMaxSendBalance(amount, gas, gasPrice);
|
|
34
29
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
35
30
|
});
|
|
36
31
|
it("should return zero when amount is equal to total gas", () => {
|
|
37
|
-
const
|
|
38
|
-
const transaction = createFixtureTransaction();
|
|
32
|
+
const amount = new BigNumber(20000);
|
|
39
33
|
const gas = new BigNumber(200);
|
|
40
34
|
const gasPrice = new BigNumber(100);
|
|
41
|
-
const result = getMaxSendBalance(gas, gasPrice
|
|
35
|
+
const result = getMaxSendBalance(amount, gas, gasPrice);
|
|
42
36
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
43
37
|
});
|
|
44
38
|
it("should handle zero amount", () => {
|
|
45
|
-
const
|
|
46
|
-
const transaction = createFixtureTransaction();
|
|
39
|
+
const amount = new BigNumber(0);
|
|
47
40
|
const gas = new BigNumber(200);
|
|
48
41
|
const gasPrice = new BigNumber(100);
|
|
49
|
-
const result = getMaxSendBalance(gas, gasPrice
|
|
42
|
+
const result = getMaxSendBalance(amount, gas, gasPrice);
|
|
50
43
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
51
44
|
});
|
|
52
45
|
it("should handle zero gas and gas price", () => {
|
|
53
46
|
const amount = new BigNumber(1000000);
|
|
54
|
-
const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
|
|
55
|
-
const transaction = createFixtureTransaction();
|
|
56
47
|
const gas = new BigNumber(0);
|
|
57
48
|
const gasPrice = new BigNumber(0);
|
|
58
|
-
const result = getMaxSendBalance(gas, gasPrice
|
|
49
|
+
const result = getMaxSendBalance(amount, gas, gasPrice);
|
|
59
50
|
expect(result.isEqualTo(amount)).toBe(true);
|
|
60
51
|
});
|
|
61
52
|
});
|
|
@@ -89,7 +80,7 @@ describe("Aptos logic ", () => {
|
|
|
89
80
|
sequence_number: "1",
|
|
90
81
|
version: "1",
|
|
91
82
|
};
|
|
92
|
-
const id = "
|
|
83
|
+
const id = "test-id";
|
|
93
84
|
const result = getBlankOperation(tx, id);
|
|
94
85
|
expect(result).toEqual({
|
|
95
86
|
id: "",
|
|
@@ -114,7 +105,7 @@ describe("Aptos logic ", () => {
|
|
|
114
105
|
timestamp: "1000000",
|
|
115
106
|
sequence_number: "1",
|
|
116
107
|
};
|
|
117
|
-
const id = "
|
|
108
|
+
const id = "test-id";
|
|
118
109
|
const result = getBlankOperation(tx, id);
|
|
119
110
|
expect(result).toEqual({
|
|
120
111
|
id: "",
|
|
@@ -243,18 +234,9 @@ describe("Aptos sync logic ", () => {
|
|
|
243
234
|
processRecipients(payload, "0x11", op, "0x2");
|
|
244
235
|
expect(op.recipients).toContain("0x2");
|
|
245
236
|
});
|
|
246
|
-
it("should add recipient for fungible assets transfer-like functions", () => {
|
|
247
|
-
const payload = {
|
|
248
|
-
function: "0x1::primary_fungible_store::transfer",
|
|
249
|
-
typeArguments: [],
|
|
250
|
-
functionArguments: [["0xfff"], "0x13"],
|
|
251
|
-
};
|
|
252
|
-
processRecipients(payload, "0x13", op, "0x1");
|
|
253
|
-
expect(op.recipients).toContain("0x13");
|
|
254
|
-
});
|
|
255
237
|
});
|
|
256
|
-
describe("
|
|
257
|
-
it("should return
|
|
238
|
+
describe("isChangeOfAptos", () => {
|
|
239
|
+
it("should return true for a valid change of Aptos", () => {
|
|
258
240
|
const change = {
|
|
259
241
|
type: "write_resource",
|
|
260
242
|
data: {
|
|
@@ -271,14 +253,6 @@ describe("Aptos sync logic ", () => {
|
|
|
271
253
|
},
|
|
272
254
|
},
|
|
273
255
|
};
|
|
274
|
-
const tx = {
|
|
275
|
-
hash: "0x123",
|
|
276
|
-
block: { hash: "0xabc", height: 1 },
|
|
277
|
-
timestamp: "1000000",
|
|
278
|
-
sequence_number: "1",
|
|
279
|
-
version: "1",
|
|
280
|
-
changes: [change],
|
|
281
|
-
};
|
|
282
256
|
const event = {
|
|
283
257
|
guid: {
|
|
284
258
|
account_address: "0x11",
|
|
@@ -286,10 +260,10 @@ describe("Aptos sync logic ", () => {
|
|
|
286
260
|
},
|
|
287
261
|
type: "0x1::coin::WithdrawEvent",
|
|
288
262
|
};
|
|
289
|
-
const result =
|
|
290
|
-
expect(result).
|
|
263
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
264
|
+
expect(result).toBe(true);
|
|
291
265
|
});
|
|
292
|
-
it("should return
|
|
266
|
+
it("should return false for an invalid change of Aptos", () => {
|
|
293
267
|
const change = {
|
|
294
268
|
type: "write_resource",
|
|
295
269
|
data: {
|
|
@@ -306,14 +280,6 @@ describe("Aptos sync logic ", () => {
|
|
|
306
280
|
},
|
|
307
281
|
},
|
|
308
282
|
};
|
|
309
|
-
const tx = {
|
|
310
|
-
hash: "0x123",
|
|
311
|
-
block: { hash: "0xabc", height: 1 },
|
|
312
|
-
timestamp: "1000000",
|
|
313
|
-
sequence_number: "1",
|
|
314
|
-
version: "1",
|
|
315
|
-
changes: [change],
|
|
316
|
-
};
|
|
317
283
|
const event = {
|
|
318
284
|
guid: {
|
|
319
285
|
account_address: "0x11",
|
|
@@ -321,152 +287,94 @@ describe("Aptos sync logic ", () => {
|
|
|
321
287
|
},
|
|
322
288
|
type: "0x1::coin::WithdrawEvent",
|
|
323
289
|
};
|
|
324
|
-
const result =
|
|
325
|
-
expect(result).toBe(
|
|
290
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
291
|
+
expect(result).toBe(false);
|
|
326
292
|
});
|
|
327
|
-
it("should return
|
|
293
|
+
it("should return false for a change with a different WriteSet type", () => {
|
|
328
294
|
const change = {
|
|
329
|
-
type: "
|
|
330
|
-
data: {
|
|
331
|
-
type: APTOS_COIN_CHANGE,
|
|
332
|
-
data: {
|
|
333
|
-
other_events: {
|
|
334
|
-
guid: {
|
|
335
|
-
id: {
|
|
336
|
-
addr: "0x12",
|
|
337
|
-
creation_num: "2",
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
};
|
|
344
|
-
const tx = {
|
|
345
|
-
hash: "0x123",
|
|
346
|
-
block: { hash: "0xabc", height: 1 },
|
|
347
|
-
timestamp: "1000000",
|
|
348
|
-
sequence_number: "1",
|
|
349
|
-
version: "1",
|
|
350
|
-
changes: [change],
|
|
295
|
+
type: "write_module",
|
|
296
|
+
data: {},
|
|
351
297
|
};
|
|
352
298
|
const event = {
|
|
353
299
|
guid: {
|
|
354
|
-
account_address: "
|
|
300
|
+
account_address: "0x1",
|
|
355
301
|
creation_number: "1",
|
|
356
302
|
},
|
|
357
303
|
type: "0x1::coin::WithdrawEvent",
|
|
358
304
|
};
|
|
359
|
-
const result =
|
|
360
|
-
expect(result).toBe(
|
|
305
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
306
|
+
expect(result).toBe(false);
|
|
361
307
|
});
|
|
362
|
-
it("should return
|
|
308
|
+
it("should return false if no data in WriteSet Change", () => {
|
|
363
309
|
const change = {
|
|
364
310
|
type: "write_resource",
|
|
365
|
-
address: "0xsomeaddress",
|
|
366
|
-
data: {
|
|
367
|
-
type: APTOS_FUNGIBLE_STORE,
|
|
368
|
-
data: {
|
|
369
|
-
metadata: {
|
|
370
|
-
inner: "0xassetaddress",
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
};
|
|
375
|
-
const tx = {
|
|
376
|
-
hash: "0x123",
|
|
377
|
-
block: { hash: "0xabc", height: 1 },
|
|
378
|
-
timestamp: "1000000",
|
|
379
|
-
sequence_number: "1",
|
|
380
|
-
version: "1",
|
|
381
|
-
changes: [change],
|
|
382
311
|
};
|
|
383
312
|
const event = {
|
|
384
313
|
guid: {
|
|
385
|
-
account_address: "
|
|
386
|
-
creation_number: "
|
|
387
|
-
},
|
|
388
|
-
type: "0x1::fungible_asset::Deposit",
|
|
389
|
-
data: {
|
|
390
|
-
amount: "100",
|
|
391
|
-
store: "0xsomeaddress",
|
|
314
|
+
account_address: "0x11",
|
|
315
|
+
creation_number: "2",
|
|
392
316
|
},
|
|
317
|
+
type: "0x1::coin::WithdrawEvent",
|
|
393
318
|
};
|
|
394
|
-
const result =
|
|
395
|
-
expect(result).
|
|
319
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
320
|
+
expect(result).toBe(false);
|
|
396
321
|
});
|
|
397
|
-
it("should return
|
|
322
|
+
it("should return false if no type in change data", () => {
|
|
398
323
|
const change = {
|
|
399
324
|
type: "write_resource",
|
|
400
|
-
address: "0xsomeaddress",
|
|
401
325
|
data: {
|
|
402
|
-
type: APTOS_COIN_CHANGE,
|
|
403
326
|
data: {
|
|
404
|
-
|
|
405
|
-
|
|
327
|
+
withdraw_events: {
|
|
328
|
+
guid: {
|
|
329
|
+
id: {
|
|
330
|
+
addr: "0x11",
|
|
331
|
+
creation_num: "2",
|
|
332
|
+
},
|
|
333
|
+
},
|
|
406
334
|
},
|
|
407
335
|
},
|
|
408
336
|
},
|
|
409
337
|
};
|
|
410
|
-
const tx = {
|
|
411
|
-
hash: "0x123",
|
|
412
|
-
block: { hash: "0xabc", height: 1 },
|
|
413
|
-
timestamp: "1000000",
|
|
414
|
-
sequence_number: "1",
|
|
415
|
-
version: "1",
|
|
416
|
-
changes: [change],
|
|
417
|
-
};
|
|
418
338
|
const event = {
|
|
419
339
|
guid: {
|
|
420
|
-
account_address: "
|
|
421
|
-
creation_number: "
|
|
422
|
-
},
|
|
423
|
-
type: "0x1::fungible_asset::Deposit",
|
|
424
|
-
data: {
|
|
425
|
-
amount: "100",
|
|
426
|
-
store: "0xsomeaddress",
|
|
340
|
+
account_address: "0x11",
|
|
341
|
+
creation_number: "2",
|
|
427
342
|
},
|
|
343
|
+
type: "0x1::coin::WithdrawEvent",
|
|
428
344
|
};
|
|
429
|
-
const result =
|
|
430
|
-
expect(result).
|
|
345
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
346
|
+
expect(result).toBe(false);
|
|
431
347
|
});
|
|
432
|
-
it("should return
|
|
348
|
+
it("should return false for a change with a different WriteSet Change type", () => {
|
|
433
349
|
const change = {
|
|
434
350
|
type: "write_resource",
|
|
435
|
-
address: "0xsomeaddress",
|
|
436
351
|
data: {
|
|
437
|
-
type:
|
|
352
|
+
type: "0x1::coin::CoinStore<0x1::aptos_coin::ANY_OTHER_COIN>",
|
|
438
353
|
data: {
|
|
439
|
-
|
|
440
|
-
|
|
354
|
+
withdraw_events: {
|
|
355
|
+
guid: {
|
|
356
|
+
id: {
|
|
357
|
+
addr: "0x11",
|
|
358
|
+
creation_num: "2",
|
|
359
|
+
},
|
|
360
|
+
},
|
|
441
361
|
},
|
|
442
362
|
},
|
|
443
363
|
},
|
|
444
364
|
};
|
|
445
|
-
const tx = {
|
|
446
|
-
hash: "0x123",
|
|
447
|
-
block: { hash: "0xabc", height: 1 },
|
|
448
|
-
timestamp: "1000000",
|
|
449
|
-
sequence_number: "1",
|
|
450
|
-
version: "1",
|
|
451
|
-
changes: [change],
|
|
452
|
-
};
|
|
453
365
|
const event = {
|
|
454
366
|
guid: {
|
|
455
|
-
account_address: "
|
|
456
|
-
creation_number: "
|
|
457
|
-
},
|
|
458
|
-
type: "0x1::fungible_asset::Deposit",
|
|
459
|
-
data: {
|
|
460
|
-
amount: "100",
|
|
461
|
-
store: "0xwrongaddress",
|
|
367
|
+
account_address: "0x11",
|
|
368
|
+
creation_number: "2",
|
|
462
369
|
},
|
|
370
|
+
type: "0x1::coin::WithdrawEvent",
|
|
463
371
|
};
|
|
464
|
-
const result =
|
|
465
|
-
expect(result).
|
|
372
|
+
const result = isChangeOfAptos(change, event, "withdraw_events");
|
|
373
|
+
expect(result).toBe(false);
|
|
466
374
|
});
|
|
467
375
|
});
|
|
468
|
-
describe("
|
|
469
|
-
it("should calculate the correct
|
|
376
|
+
describe("getAptosAmounts", () => {
|
|
377
|
+
it("should calculate the correct amounts for withdraw and deposit events", () => {
|
|
470
378
|
const tx = {
|
|
471
379
|
events: [
|
|
472
380
|
{
|
|
@@ -518,76 +426,35 @@ describe("Aptos sync logic ", () => {
|
|
|
518
426
|
],
|
|
519
427
|
};
|
|
520
428
|
const address = "0x11";
|
|
521
|
-
const result =
|
|
429
|
+
const result = getAptosAmounts(tx, address);
|
|
522
430
|
expect(result.amount_in).toEqual(new BigNumber(50));
|
|
523
431
|
expect(result.amount_out).toEqual(new BigNumber(100));
|
|
524
|
-
expect(result.coin_id).toEqual(APTOS_ASSET_ID);
|
|
525
432
|
});
|
|
526
|
-
it("should
|
|
433
|
+
it("should return zero amounts if no matching events are found", () => {
|
|
527
434
|
const tx = {
|
|
528
435
|
events: [
|
|
529
436
|
{
|
|
530
|
-
type: "0x1::
|
|
437
|
+
type: "0x1::coin::WithdrawEvent",
|
|
531
438
|
guid: {
|
|
532
439
|
account_address: "0x11",
|
|
533
440
|
creation_number: "1",
|
|
534
441
|
},
|
|
535
442
|
data: {
|
|
536
443
|
amount: "100",
|
|
537
|
-
store: "0x22",
|
|
538
444
|
},
|
|
539
445
|
},
|
|
540
446
|
{
|
|
541
|
-
type: "0x1::
|
|
447
|
+
type: "0x1::coin::DepositEvent",
|
|
542
448
|
guid: {
|
|
543
449
|
account_address: "0x11",
|
|
544
450
|
creation_number: "2",
|
|
545
451
|
},
|
|
546
452
|
data: {
|
|
547
453
|
amount: "50",
|
|
548
|
-
store: "0x33",
|
|
549
454
|
},
|
|
550
455
|
},
|
|
551
456
|
],
|
|
552
457
|
changes: [
|
|
553
|
-
{
|
|
554
|
-
type: "write_resource",
|
|
555
|
-
address: "0x22",
|
|
556
|
-
data: {
|
|
557
|
-
type: APTOS_FUNGIBLE_STORE,
|
|
558
|
-
data: {
|
|
559
|
-
metadata: {
|
|
560
|
-
inner: "0x44",
|
|
561
|
-
},
|
|
562
|
-
transfer_events: {
|
|
563
|
-
guid: {
|
|
564
|
-
id: {
|
|
565
|
-
addr: "0x11",
|
|
566
|
-
creation_num: "2",
|
|
567
|
-
},
|
|
568
|
-
},
|
|
569
|
-
},
|
|
570
|
-
},
|
|
571
|
-
},
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
type: "write_resource",
|
|
575
|
-
address: "0x22",
|
|
576
|
-
data: {
|
|
577
|
-
type: APTOS_OBJECT_CORE,
|
|
578
|
-
data: {
|
|
579
|
-
owner: "0x11",
|
|
580
|
-
transfer_events: {
|
|
581
|
-
guid: {
|
|
582
|
-
id: {
|
|
583
|
-
addr: "0x22",
|
|
584
|
-
creation_num: "2",
|
|
585
|
-
},
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
},
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
458
|
{
|
|
592
459
|
type: "write_resource",
|
|
593
460
|
data: {
|
|
@@ -596,7 +463,7 @@ describe("Aptos sync logic ", () => {
|
|
|
596
463
|
withdraw_events: {
|
|
597
464
|
guid: {
|
|
598
465
|
id: {
|
|
599
|
-
addr: "
|
|
466
|
+
addr: "0x12", // should fail by address check
|
|
600
467
|
creation_num: "1",
|
|
601
468
|
},
|
|
602
469
|
},
|
|
@@ -605,7 +472,7 @@ describe("Aptos sync logic ", () => {
|
|
|
605
472
|
guid: {
|
|
606
473
|
id: {
|
|
607
474
|
addr: "0x11",
|
|
608
|
-
creation_num: "
|
|
475
|
+
creation_num: "3", // should fail by number check
|
|
609
476
|
},
|
|
610
477
|
},
|
|
611
478
|
},
|
|
@@ -615,10 +482,9 @@ describe("Aptos sync logic ", () => {
|
|
|
615
482
|
],
|
|
616
483
|
};
|
|
617
484
|
const address = "0x11";
|
|
618
|
-
const result =
|
|
485
|
+
const result = getAptosAmounts(tx, address);
|
|
619
486
|
expect(result.amount_in).toEqual(new BigNumber(0));
|
|
620
|
-
expect(result.amount_out).toEqual(new BigNumber(
|
|
621
|
-
expect(result.coin_id).toEqual("0x44");
|
|
487
|
+
expect(result.amount_out).toEqual(new BigNumber(0));
|
|
622
488
|
});
|
|
623
489
|
it("should handle transactions with other events", () => {
|
|
624
490
|
const tx = {
|
|
@@ -636,53 +502,56 @@ describe("Aptos sync logic ", () => {
|
|
|
636
502
|
],
|
|
637
503
|
};
|
|
638
504
|
const address = "0x1";
|
|
639
|
-
const result =
|
|
505
|
+
const result = getAptosAmounts(tx, address);
|
|
640
506
|
expect(result.amount_in).toEqual(new BigNumber(0));
|
|
641
507
|
expect(result.amount_out).toEqual(new BigNumber(0));
|
|
642
|
-
expect(result.coin_id).toEqual(null);
|
|
643
508
|
});
|
|
644
509
|
});
|
|
645
510
|
describe("calculateAmount", () => {
|
|
646
511
|
it("should calculate the correct amount when the address is the sender", () => {
|
|
647
512
|
const address = "0x11";
|
|
648
513
|
const sender = "0x11";
|
|
514
|
+
const fee = new BigNumber(10); // account pays fees
|
|
649
515
|
const amount_in = new BigNumber(50);
|
|
650
516
|
const amount_out = new BigNumber(100);
|
|
651
|
-
const result = calculateAmount(sender, address, amount_in, amount_out);
|
|
517
|
+
const result = calculateAmount(sender, address, fee, amount_in, amount_out);
|
|
652
518
|
// LL negates the amount for SEND transactions during output
|
|
653
|
-
expect(result).toEqual(new BigNumber(
|
|
519
|
+
expect(result).toEqual(new BigNumber(60)); // -(50 - 100 - 10)
|
|
654
520
|
});
|
|
655
521
|
it("should calculate the correct amount when the address is not the sender", () => {
|
|
656
522
|
const address = "0x11";
|
|
657
523
|
const sender = "0x12";
|
|
524
|
+
const fee = new BigNumber(10); // sender pays fees
|
|
658
525
|
const amount_in = new BigNumber(100);
|
|
659
526
|
const amount_out = new BigNumber(50);
|
|
660
|
-
const result = calculateAmount(sender, address, amount_in, amount_out);
|
|
527
|
+
const result = calculateAmount(sender, address, fee, amount_in, amount_out);
|
|
661
528
|
expect(result).toEqual(new BigNumber(50)); // 100 - 50
|
|
662
529
|
});
|
|
663
530
|
it("should handle transactions with zero amounts", () => {
|
|
664
531
|
const address = "0x11";
|
|
665
532
|
const sender = "0x11";
|
|
533
|
+
const fee = new BigNumber(10);
|
|
666
534
|
const amount_in = new BigNumber(0);
|
|
667
535
|
const amount_out = new BigNumber(0);
|
|
668
|
-
const result = calculateAmount(sender, address, amount_in, amount_out);
|
|
536
|
+
const result = calculateAmount(sender, address, fee, amount_in, amount_out);
|
|
669
537
|
// LL negates the amount for SEND transactions during output
|
|
670
|
-
expect(result).toEqual(new BigNumber(
|
|
538
|
+
expect(result).toEqual(new BigNumber(10)); // -(0 - 0 - 10)
|
|
671
539
|
});
|
|
672
540
|
it("should get negative numbers (for send tx with deposit to account)", () => {
|
|
673
541
|
const address = "0x11";
|
|
674
542
|
const sender = "0x11";
|
|
543
|
+
const fee = new BigNumber(10);
|
|
675
544
|
const amount_in = new BigNumber(100);
|
|
676
545
|
const amount_out = new BigNumber(0);
|
|
677
|
-
const result = calculateAmount(sender, address, amount_in, amount_out);
|
|
546
|
+
const result = calculateAmount(sender, address, fee, amount_in, amount_out);
|
|
678
547
|
// LL negates the amount for SEND transactions during output
|
|
679
|
-
expect(result).toEqual(new BigNumber(
|
|
548
|
+
expect(result).toEqual(new BigNumber(90).negated()); // 100 - 10
|
|
680
549
|
});
|
|
681
550
|
});
|
|
682
551
|
describe("txsToOps", () => {
|
|
683
|
-
it("should convert
|
|
552
|
+
it("should convert transactions to operations correctly", () => {
|
|
684
553
|
const address = "0x11";
|
|
685
|
-
const id = "
|
|
554
|
+
const id = "test-id";
|
|
686
555
|
const txs = [
|
|
687
556
|
{
|
|
688
557
|
hash: "0x123",
|
|
@@ -749,13 +618,13 @@ describe("Aptos sync logic ", () => {
|
|
|
749
618
|
sequence_number: "1",
|
|
750
619
|
},
|
|
751
620
|
];
|
|
752
|
-
const
|
|
621
|
+
const result = txsToOps({ address }, id, txs);
|
|
753
622
|
expect(result).toHaveLength(1);
|
|
754
623
|
expect(result[0]).toEqual({
|
|
755
624
|
id: expect.any(String),
|
|
756
625
|
hash: "0x123",
|
|
757
626
|
type: DIRECTION.OUT,
|
|
758
|
-
value: new BigNumber(
|
|
627
|
+
value: new BigNumber(20100),
|
|
759
628
|
fee: new BigNumber(20000),
|
|
760
629
|
blockHash: "0xabc",
|
|
761
630
|
blockHeight: 1,
|
|
@@ -770,7 +639,7 @@ describe("Aptos sync logic ", () => {
|
|
|
770
639
|
});
|
|
771
640
|
it("should skip transactions without functions in payload", () => {
|
|
772
641
|
const address = "0x11";
|
|
773
|
-
const id = "
|
|
642
|
+
const id = "test-id";
|
|
774
643
|
const txs = [
|
|
775
644
|
{
|
|
776
645
|
hash: "0x123",
|
|
@@ -779,6 +648,12 @@ describe("Aptos sync logic ", () => {
|
|
|
779
648
|
gas_unit_price: "100",
|
|
780
649
|
success: true,
|
|
781
650
|
payload: {},
|
|
651
|
+
// payload: {
|
|
652
|
+
// type: "entry_function_payload",
|
|
653
|
+
// function: "0x1::coin::transfer",
|
|
654
|
+
// type_arguments: [],
|
|
655
|
+
// arguments: ["0x12", 100],
|
|
656
|
+
// } as EntryFunctionPayloadResponse,
|
|
782
657
|
events: [],
|
|
783
658
|
changes: [],
|
|
784
659
|
block: { hash: "0xabc", height: 1 },
|
|
@@ -786,12 +661,12 @@ describe("Aptos sync logic ", () => {
|
|
|
786
661
|
sequence_number: "1",
|
|
787
662
|
},
|
|
788
663
|
];
|
|
789
|
-
const
|
|
664
|
+
const result = txsToOps({ address }, id, txs);
|
|
790
665
|
expect(result).toHaveLength(0);
|
|
791
666
|
});
|
|
792
667
|
it("should skip transactions that result in no Aptos change", () => {
|
|
793
668
|
const address = "0x11";
|
|
794
|
-
const id = "
|
|
669
|
+
const id = "test-id";
|
|
795
670
|
const txs = [
|
|
796
671
|
{
|
|
797
672
|
hash: "0x123",
|
|
@@ -812,704 +687,71 @@ describe("Aptos sync logic ", () => {
|
|
|
812
687
|
sequence_number: "1",
|
|
813
688
|
},
|
|
814
689
|
];
|
|
815
|
-
const
|
|
690
|
+
const result = txsToOps({ address }, id, txs);
|
|
816
691
|
expect(result).toHaveLength(0);
|
|
817
692
|
});
|
|
818
693
|
it("should handle failed transactions", () => {
|
|
819
|
-
const address = "
|
|
820
|
-
const id = "
|
|
821
|
-
const txs = [
|
|
822
|
-
{
|
|
823
|
-
hash: "0x0189",
|
|
824
|
-
sender: "0xa0d8",
|
|
825
|
-
gas_used: "200",
|
|
826
|
-
gas_unit_price: "100",
|
|
827
|
-
success: false,
|
|
828
|
-
payload: {
|
|
829
|
-
function: "0x1::coin::transfer",
|
|
830
|
-
type_arguments: ["0xd111::staked_coin::StakedAptos"],
|
|
831
|
-
arguments: ["0x4e5e", "50000000"],
|
|
832
|
-
type: "entry_function_payload",
|
|
833
|
-
},
|
|
834
|
-
events: [
|
|
835
|
-
{
|
|
836
|
-
guid: {
|
|
837
|
-
creation_number: "0",
|
|
838
|
-
account_address: "0x0",
|
|
839
|
-
},
|
|
840
|
-
sequence_number: "0",
|
|
841
|
-
type: "0x1::transaction_fee::FeeStatement",
|
|
842
|
-
data: {
|
|
843
|
-
execution_gas_units: "5",
|
|
844
|
-
io_gas_units: "4",
|
|
845
|
-
storage_fee_octas: "0",
|
|
846
|
-
storage_fee_refund_octas: "0",
|
|
847
|
-
total_charge_gas_units: "8",
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
],
|
|
851
|
-
changes: [
|
|
852
|
-
{
|
|
853
|
-
address: "0xa0d8",
|
|
854
|
-
state_key_hash: "0x1709",
|
|
855
|
-
data: {
|
|
856
|
-
type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
|
|
857
|
-
data: {
|
|
858
|
-
coin: {
|
|
859
|
-
value: "573163341",
|
|
860
|
-
},
|
|
861
|
-
deposit_events: {
|
|
862
|
-
counter: "45",
|
|
863
|
-
guid: {
|
|
864
|
-
id: {
|
|
865
|
-
addr: "0xa0d8",
|
|
866
|
-
creation_num: "2",
|
|
867
|
-
},
|
|
868
|
-
},
|
|
869
|
-
},
|
|
870
|
-
frozen: false,
|
|
871
|
-
withdraw_events: {
|
|
872
|
-
counter: "82",
|
|
873
|
-
guid: {
|
|
874
|
-
id: {
|
|
875
|
-
addr: "0xa0d8",
|
|
876
|
-
creation_num: "3",
|
|
877
|
-
},
|
|
878
|
-
},
|
|
879
|
-
},
|
|
880
|
-
},
|
|
881
|
-
},
|
|
882
|
-
type: "write_resource",
|
|
883
|
-
},
|
|
884
|
-
{
|
|
885
|
-
address: "0xa0d8",
|
|
886
|
-
state_key_hash: "0x6f1e",
|
|
887
|
-
data: {
|
|
888
|
-
type: "0x1::account::Account",
|
|
889
|
-
data: {
|
|
890
|
-
authentication_key: "0xa0d8",
|
|
891
|
-
coin_register_events: {
|
|
892
|
-
counter: "5",
|
|
893
|
-
guid: {
|
|
894
|
-
id: {
|
|
895
|
-
addr: "0xa0d8",
|
|
896
|
-
creation_num: "0",
|
|
897
|
-
},
|
|
898
|
-
},
|
|
899
|
-
},
|
|
900
|
-
guid_creation_num: "12",
|
|
901
|
-
key_rotation_events: {
|
|
902
|
-
counter: "0",
|
|
903
|
-
guid: {
|
|
904
|
-
id: {
|
|
905
|
-
addr: "0xa0d8",
|
|
906
|
-
creation_num: "1",
|
|
907
|
-
},
|
|
908
|
-
},
|
|
909
|
-
},
|
|
910
|
-
rotation_capability_offer: {
|
|
911
|
-
for: {
|
|
912
|
-
vec: [],
|
|
913
|
-
},
|
|
914
|
-
},
|
|
915
|
-
sequence_number: "83",
|
|
916
|
-
signer_capability_offer: {
|
|
917
|
-
for: {
|
|
918
|
-
vec: [],
|
|
919
|
-
},
|
|
920
|
-
},
|
|
921
|
-
},
|
|
922
|
-
},
|
|
923
|
-
type: "write_resource",
|
|
924
|
-
},
|
|
925
|
-
{
|
|
926
|
-
state_key_hash: "0x6e4b",
|
|
927
|
-
handle: "0x1b85",
|
|
928
|
-
key: "0x0619",
|
|
929
|
-
value: "0x72c5e483c25c96010000000000000000",
|
|
930
|
-
data: null,
|
|
931
|
-
type: "write_table_item",
|
|
932
|
-
},
|
|
933
|
-
],
|
|
934
|
-
block: {
|
|
935
|
-
hash: "0xc496",
|
|
936
|
-
height: 1,
|
|
937
|
-
},
|
|
938
|
-
timestamp: "1000000",
|
|
939
|
-
sequence_number: "1",
|
|
940
|
-
},
|
|
941
|
-
];
|
|
942
|
-
const [result] = txsToOps({ address }, id, txs);
|
|
943
|
-
expect(result).toHaveLength(1);
|
|
944
|
-
expect(result[0]).toEqual({
|
|
945
|
-
id: expect.any(String),
|
|
946
|
-
hash: "0x0189",
|
|
947
|
-
type: DIRECTION.OUT,
|
|
948
|
-
value: new BigNumber(20000),
|
|
949
|
-
fee: new BigNumber(20000),
|
|
950
|
-
blockHash: "0xc496",
|
|
951
|
-
blockHeight: 1,
|
|
952
|
-
senders: ["0xa0d8"],
|
|
953
|
-
recipients: ["0x4e5e"],
|
|
954
|
-
accountId: id,
|
|
955
|
-
date: new Date(1000),
|
|
956
|
-
extra: { version: undefined },
|
|
957
|
-
transactionSequenceNumber: 1,
|
|
958
|
-
hasFailed: true,
|
|
959
|
-
});
|
|
960
|
-
});
|
|
961
|
-
it("should convert Aptos token transactions to operations correctly", () => {
|
|
962
|
-
findTokenByAddressInCurrency.mockReturnValue({
|
|
963
|
-
type: "TokenCurrency",
|
|
964
|
-
id: "aptos/coin/dstapt::staked_coin::stakedaptos",
|
|
965
|
-
contractAddress: "0xd111::staked_coin::StakedAptos",
|
|
966
|
-
parentCurrency: {
|
|
967
|
-
type: "CryptoCurrency",
|
|
968
|
-
id: "aptos",
|
|
969
|
-
coinType: 637,
|
|
970
|
-
name: "Aptos",
|
|
971
|
-
managerAppName: "Aptos",
|
|
972
|
-
ticker: "APT",
|
|
973
|
-
scheme: "aptos",
|
|
974
|
-
color: "#231F20",
|
|
975
|
-
family: "aptos",
|
|
976
|
-
units: [
|
|
977
|
-
{
|
|
978
|
-
name: "APT",
|
|
979
|
-
code: "APT",
|
|
980
|
-
magnitude: 8,
|
|
981
|
-
},
|
|
982
|
-
],
|
|
983
|
-
explorerViews: [
|
|
984
|
-
{
|
|
985
|
-
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
986
|
-
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
987
|
-
},
|
|
988
|
-
],
|
|
989
|
-
},
|
|
990
|
-
name: "dstAPT",
|
|
991
|
-
tokenType: "coin",
|
|
992
|
-
ticker: "dstAPT",
|
|
993
|
-
disableCountervalue: false,
|
|
994
|
-
delisted: false,
|
|
995
|
-
units: [
|
|
996
|
-
{
|
|
997
|
-
name: "dstAPT",
|
|
998
|
-
code: "dstAPT",
|
|
999
|
-
magnitude: 8,
|
|
1000
|
-
},
|
|
1001
|
-
],
|
|
1002
|
-
});
|
|
1003
|
-
jest.mock("../../bridge/logic", () => ({
|
|
1004
|
-
...jest.requireActual("../../bridge/logic"),
|
|
1005
|
-
getResourceAddress: jest.fn().mockReturnValue("0xd111::staked_coin::StakedAptos"),
|
|
1006
|
-
}));
|
|
1007
|
-
decodeTokenAccountId.mockReturnValue({
|
|
1008
|
-
accountId: "token_account_id",
|
|
1009
|
-
});
|
|
1010
|
-
const address = "0xa0d";
|
|
1011
|
-
const id = "test_id";
|
|
694
|
+
const address = "0x11";
|
|
695
|
+
const id = "test-id";
|
|
1012
696
|
const txs = [
|
|
1013
697
|
{
|
|
1014
698
|
hash: "0x123",
|
|
1015
|
-
sender:
|
|
699
|
+
sender: "0x11",
|
|
1016
700
|
gas_used: "200",
|
|
1017
701
|
gas_unit_price: "100",
|
|
1018
|
-
success:
|
|
702
|
+
success: false,
|
|
1019
703
|
payload: {
|
|
1020
|
-
function: "0x1::aptos_account::transfer_coins",
|
|
1021
|
-
type_arguments: ["0xd111::staked_coin::StakedAptos"],
|
|
1022
|
-
arguments: ["0x4e5", "1500000"],
|
|
1023
704
|
type: "entry_function_payload",
|
|
705
|
+
function: "0x1::coin::transfer",
|
|
706
|
+
type_arguments: [],
|
|
707
|
+
arguments: ["0x12", 100],
|
|
1024
708
|
},
|
|
1025
709
|
events: [
|
|
1026
710
|
{
|
|
1027
|
-
guid: {
|
|
1028
|
-
creation_number: "11",
|
|
1029
|
-
account_address: "0xa0d",
|
|
1030
|
-
},
|
|
1031
|
-
sequence_number: "12",
|
|
1032
711
|
type: "0x1::coin::WithdrawEvent",
|
|
1033
|
-
data: {
|
|
1034
|
-
amount: "1500000",
|
|
1035
|
-
},
|
|
1036
|
-
},
|
|
1037
|
-
{
|
|
1038
712
|
guid: {
|
|
1039
|
-
|
|
1040
|
-
|
|
713
|
+
account_address: "0x11",
|
|
714
|
+
creation_number: "1",
|
|
1041
715
|
},
|
|
1042
|
-
sequence_number: "8",
|
|
1043
|
-
type: "0x1::coin::DepositEvent",
|
|
1044
716
|
data: {
|
|
1045
|
-
amount: "
|
|
717
|
+
amount: "100",
|
|
1046
718
|
},
|
|
1047
719
|
},
|
|
1048
720
|
{
|
|
721
|
+
type: "0x1::coin::DepositEvent",
|
|
1049
722
|
guid: {
|
|
1050
|
-
|
|
1051
|
-
|
|
723
|
+
account_address: "0x12",
|
|
724
|
+
creation_number: "2",
|
|
1052
725
|
},
|
|
1053
|
-
sequence_number: "0",
|
|
1054
|
-
type: "0x1::transaction_fee::FeeStatement",
|
|
1055
726
|
data: {
|
|
1056
|
-
|
|
1057
|
-
io_gas_units: "6",
|
|
1058
|
-
storage_fee_octas: "0",
|
|
1059
|
-
storage_fee_refund_octas: "0",
|
|
1060
|
-
total_charge_gas_units: "12",
|
|
727
|
+
amount: "100",
|
|
1061
728
|
},
|
|
1062
729
|
},
|
|
1063
730
|
],
|
|
1064
731
|
changes: [
|
|
1065
732
|
{
|
|
1066
|
-
address: "0x4e5",
|
|
1067
|
-
state_key_hash: "0x3c0",
|
|
1068
|
-
data: {
|
|
1069
|
-
type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
|
|
1070
|
-
data: {
|
|
1071
|
-
coin: {
|
|
1072
|
-
value: "4000000",
|
|
1073
|
-
},
|
|
1074
|
-
deposit_events: {
|
|
1075
|
-
counter: "9",
|
|
1076
|
-
guid: {
|
|
1077
|
-
id: {
|
|
1078
|
-
addr: "0x4e5",
|
|
1079
|
-
creation_num: "4",
|
|
1080
|
-
},
|
|
1081
|
-
},
|
|
1082
|
-
},
|
|
1083
|
-
frozen: false,
|
|
1084
|
-
withdraw_events: {
|
|
1085
|
-
counter: "6",
|
|
1086
|
-
guid: {
|
|
1087
|
-
id: {
|
|
1088
|
-
addr: "0x4e5",
|
|
1089
|
-
creation_num: "5",
|
|
1090
|
-
},
|
|
1091
|
-
},
|
|
1092
|
-
},
|
|
1093
|
-
},
|
|
1094
|
-
},
|
|
1095
|
-
type: "write_resource",
|
|
1096
|
-
},
|
|
1097
|
-
{
|
|
1098
|
-
address: "0xa0d",
|
|
1099
|
-
state_key_hash: "0x1709",
|
|
1100
|
-
data: {
|
|
1101
|
-
type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
|
|
1102
|
-
data: {
|
|
1103
|
-
coin: {
|
|
1104
|
-
value: "68254118",
|
|
1105
|
-
},
|
|
1106
|
-
deposit_events: {
|
|
1107
|
-
counter: "46",
|
|
1108
|
-
guid: {
|
|
1109
|
-
id: {
|
|
1110
|
-
addr: "0xa0d",
|
|
1111
|
-
creation_num: "2",
|
|
1112
|
-
},
|
|
1113
|
-
},
|
|
1114
|
-
},
|
|
1115
|
-
frozen: false,
|
|
1116
|
-
withdraw_events: {
|
|
1117
|
-
counter: "89",
|
|
1118
|
-
guid: {
|
|
1119
|
-
id: {
|
|
1120
|
-
addr: "0xa0d",
|
|
1121
|
-
creation_num: "3",
|
|
1122
|
-
},
|
|
1123
|
-
},
|
|
1124
|
-
},
|
|
1125
|
-
},
|
|
1126
|
-
},
|
|
1127
733
|
type: "write_resource",
|
|
1128
|
-
},
|
|
1129
|
-
{
|
|
1130
|
-
address: "0xa0d",
|
|
1131
|
-
state_key_hash: "0x5520",
|
|
1132
734
|
data: {
|
|
1133
|
-
type:
|
|
735
|
+
type: APTOS_COIN_CHANGE,
|
|
1134
736
|
data: {
|
|
1135
|
-
coin: {
|
|
1136
|
-
value: "1000000",
|
|
1137
|
-
},
|
|
1138
|
-
deposit_events: {
|
|
1139
|
-
counter: "7",
|
|
1140
|
-
guid: {
|
|
1141
|
-
id: {
|
|
1142
|
-
addr: "0xa0d",
|
|
1143
|
-
creation_num: "10",
|
|
1144
|
-
},
|
|
1145
|
-
},
|
|
1146
|
-
},
|
|
1147
|
-
frozen: false,
|
|
1148
737
|
withdraw_events: {
|
|
1149
|
-
counter: "13",
|
|
1150
738
|
guid: {
|
|
1151
739
|
id: {
|
|
1152
|
-
addr: "
|
|
1153
|
-
creation_num: "11",
|
|
1154
|
-
},
|
|
1155
|
-
},
|
|
1156
|
-
},
|
|
1157
|
-
},
|
|
1158
|
-
},
|
|
1159
|
-
type: "write_resource",
|
|
1160
|
-
},
|
|
1161
|
-
{
|
|
1162
|
-
address: "0xa0d",
|
|
1163
|
-
state_key_hash: "0x6f1e",
|
|
1164
|
-
data: {
|
|
1165
|
-
type: "0x1::account::Account",
|
|
1166
|
-
data: {
|
|
1167
|
-
authentication_key: "0xa0d",
|
|
1168
|
-
coin_register_events: {
|
|
1169
|
-
counter: "5",
|
|
1170
|
-
guid: {
|
|
1171
|
-
id: {
|
|
1172
|
-
addr: "0xa0d",
|
|
1173
|
-
creation_num: "0",
|
|
1174
|
-
},
|
|
1175
|
-
},
|
|
1176
|
-
},
|
|
1177
|
-
guid_creation_num: "12",
|
|
1178
|
-
key_rotation_events: {
|
|
1179
|
-
counter: "0",
|
|
1180
|
-
guid: {
|
|
1181
|
-
id: {
|
|
1182
|
-
addr: "0xa0d",
|
|
740
|
+
addr: "0x11",
|
|
1183
741
|
creation_num: "1",
|
|
1184
742
|
},
|
|
1185
743
|
},
|
|
1186
744
|
},
|
|
1187
|
-
rotation_capability_offer: {
|
|
1188
|
-
for: {
|
|
1189
|
-
vec: [],
|
|
1190
|
-
},
|
|
1191
|
-
},
|
|
1192
|
-
sequence_number: "122",
|
|
1193
|
-
signer_capability_offer: {
|
|
1194
|
-
for: {
|
|
1195
|
-
vec: [],
|
|
1196
|
-
},
|
|
1197
|
-
},
|
|
1198
|
-
},
|
|
1199
|
-
},
|
|
1200
|
-
type: "write_resource",
|
|
1201
|
-
},
|
|
1202
|
-
{
|
|
1203
|
-
state_key_hash: "0x6e4b",
|
|
1204
|
-
handle: "0x1b85",
|
|
1205
|
-
key: "0x0619",
|
|
1206
|
-
value: "0x1ddaf8da3b1497010000000000000000",
|
|
1207
|
-
data: null,
|
|
1208
|
-
type: "write_table_item",
|
|
1209
|
-
},
|
|
1210
|
-
],
|
|
1211
|
-
block: { hash: "0xabc", height: 1 },
|
|
1212
|
-
timestamp: "1000000",
|
|
1213
|
-
sequence_number: "1",
|
|
1214
|
-
},
|
|
1215
|
-
];
|
|
1216
|
-
const [ops, tokenOps] = txsToOps({ address }, id, txs);
|
|
1217
|
-
expect(ops).toHaveLength(1);
|
|
1218
|
-
expect(ops[0]).toEqual({
|
|
1219
|
-
id: expect.any(String),
|
|
1220
|
-
hash: "0x123",
|
|
1221
|
-
type: "FEES",
|
|
1222
|
-
value: new BigNumber(20000),
|
|
1223
|
-
fee: new BigNumber(20000),
|
|
1224
|
-
blockHash: "0xabc",
|
|
1225
|
-
blockHeight: 1,
|
|
1226
|
-
senders: ["0xa0d"],
|
|
1227
|
-
recipients: ["0x4e5"],
|
|
1228
|
-
accountId: "token_account_id",
|
|
1229
|
-
date: new Date(1000),
|
|
1230
|
-
extra: { version: undefined },
|
|
1231
|
-
transactionSequenceNumber: 1,
|
|
1232
|
-
hasFailed: false,
|
|
1233
|
-
});
|
|
1234
|
-
expect(tokenOps).toHaveLength(1);
|
|
1235
|
-
expect(tokenOps[0]).toEqual({
|
|
1236
|
-
id: expect.any(String),
|
|
1237
|
-
hash: "0x123",
|
|
1238
|
-
type: DIRECTION.OUT,
|
|
1239
|
-
value: new BigNumber(1500000),
|
|
1240
|
-
fee: new BigNumber(20000),
|
|
1241
|
-
blockHash: "0xabc",
|
|
1242
|
-
blockHeight: 1,
|
|
1243
|
-
senders: ["0xa0d"],
|
|
1244
|
-
recipients: ["0x4e5"],
|
|
1245
|
-
date: new Date(1000),
|
|
1246
|
-
extra: { version: undefined },
|
|
1247
|
-
transactionSequenceNumber: 1,
|
|
1248
|
-
hasFailed: false,
|
|
1249
|
-
});
|
|
1250
|
-
});
|
|
1251
|
-
it("should convert Aptos token transactions to operations correctly", () => {
|
|
1252
|
-
findTokenByAddressInCurrency.mockReturnValue({
|
|
1253
|
-
type: "TokenCurrency",
|
|
1254
|
-
id: "aptos/fungible_asset/cellana_0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
|
|
1255
|
-
contractAddress: "0x2ebb",
|
|
1256
|
-
parentCurrency: {
|
|
1257
|
-
type: "CryptoCurrency",
|
|
1258
|
-
id: "aptos",
|
|
1259
|
-
coinType: 637,
|
|
1260
|
-
name: "Aptos",
|
|
1261
|
-
managerAppName: "Aptos",
|
|
1262
|
-
ticker: "APT",
|
|
1263
|
-
scheme: "aptos",
|
|
1264
|
-
color: "#231F20",
|
|
1265
|
-
family: "aptos",
|
|
1266
|
-
units: [
|
|
1267
|
-
{
|
|
1268
|
-
name: "APT",
|
|
1269
|
-
code: "APT",
|
|
1270
|
-
magnitude: 8,
|
|
1271
|
-
},
|
|
1272
|
-
],
|
|
1273
|
-
explorerViews: [
|
|
1274
|
-
{
|
|
1275
|
-
address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
|
|
1276
|
-
tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
|
|
1277
|
-
},
|
|
1278
|
-
],
|
|
1279
|
-
},
|
|
1280
|
-
name: "CELLANA",
|
|
1281
|
-
tokenType: "fungible_asset",
|
|
1282
|
-
ticker: "CELL",
|
|
1283
|
-
disableCountervalue: false,
|
|
1284
|
-
delisted: false,
|
|
1285
|
-
units: [
|
|
1286
|
-
{
|
|
1287
|
-
name: "CELLANA",
|
|
1288
|
-
code: "CELL",
|
|
1289
|
-
magnitude: 8,
|
|
1290
|
-
},
|
|
1291
|
-
],
|
|
1292
|
-
});
|
|
1293
|
-
jest.mock("../../bridge/logic", () => ({
|
|
1294
|
-
...jest.requireActual("../../bridge/logic"),
|
|
1295
|
-
getResourceAddress: jest.fn().mockReturnValue("0x2ebb"),
|
|
1296
|
-
}));
|
|
1297
|
-
encodeTokenAccountId.mockReturnValue("token_account_id");
|
|
1298
|
-
const txs = [
|
|
1299
|
-
{
|
|
1300
|
-
hash: "0x10c9",
|
|
1301
|
-
sender: "0xa0d8",
|
|
1302
|
-
gas_used: "200",
|
|
1303
|
-
gas_unit_price: "100",
|
|
1304
|
-
success: true,
|
|
1305
|
-
payload: {
|
|
1306
|
-
function: "0x1::primary_fungible_store::transfer",
|
|
1307
|
-
type_arguments: ["0x1::fungible_asset::Metadata"],
|
|
1308
|
-
arguments: [
|
|
1309
|
-
{
|
|
1310
|
-
inner: "0x2ebb",
|
|
1311
|
-
},
|
|
1312
|
-
"0x6b8c",
|
|
1313
|
-
"193",
|
|
1314
|
-
],
|
|
1315
|
-
type: "entry_function_payload",
|
|
1316
|
-
},
|
|
1317
|
-
events: [
|
|
1318
|
-
{
|
|
1319
|
-
guid: {
|
|
1320
|
-
creation_number: "0",
|
|
1321
|
-
account_address: "0x0",
|
|
1322
|
-
},
|
|
1323
|
-
sequence_number: "0",
|
|
1324
|
-
type: "0x1::fungible_asset::Withdraw",
|
|
1325
|
-
data: {
|
|
1326
|
-
amount: "193",
|
|
1327
|
-
store: "0xd475",
|
|
1328
|
-
},
|
|
1329
|
-
},
|
|
1330
|
-
{
|
|
1331
|
-
guid: {
|
|
1332
|
-
creation_number: "0",
|
|
1333
|
-
account_address: "0x0",
|
|
1334
|
-
},
|
|
1335
|
-
sequence_number: "0",
|
|
1336
|
-
type: "0x1::fungible_asset::Deposit",
|
|
1337
|
-
data: {
|
|
1338
|
-
amount: "193",
|
|
1339
|
-
store: "0xaaa9",
|
|
1340
|
-
},
|
|
1341
|
-
},
|
|
1342
|
-
{
|
|
1343
|
-
guid: {
|
|
1344
|
-
creation_number: "0",
|
|
1345
|
-
account_address: "0x0",
|
|
1346
|
-
},
|
|
1347
|
-
sequence_number: "0",
|
|
1348
|
-
type: "0x1::transaction_fee::FeeStatement",
|
|
1349
|
-
data: {
|
|
1350
|
-
execution_gas_units: "4",
|
|
1351
|
-
io_gas_units: "6",
|
|
1352
|
-
storage_fee_octas: "0",
|
|
1353
|
-
storage_fee_refund_octas: "0",
|
|
1354
|
-
total_charge_gas_units: "10",
|
|
1355
|
-
},
|
|
1356
|
-
},
|
|
1357
|
-
],
|
|
1358
|
-
changes: [
|
|
1359
|
-
{
|
|
1360
|
-
address: "0xaaa9",
|
|
1361
|
-
state_key_hash: "0x9a17",
|
|
1362
|
-
data: {
|
|
1363
|
-
type: "0x1::fungible_asset::FungibleStore",
|
|
1364
|
-
data: {
|
|
1365
|
-
balance: "10044959",
|
|
1366
|
-
frozen: false,
|
|
1367
|
-
metadata: {
|
|
1368
|
-
inner: "0x2ebb",
|
|
1369
|
-
},
|
|
1370
|
-
},
|
|
1371
|
-
},
|
|
1372
|
-
type: "write_resource",
|
|
1373
|
-
},
|
|
1374
|
-
{
|
|
1375
|
-
address: "0xaaa9",
|
|
1376
|
-
state_key_hash: "0x9a17",
|
|
1377
|
-
data: {
|
|
1378
|
-
type: "0x1::object::ObjectCore",
|
|
1379
|
-
data: {
|
|
1380
|
-
allow_ungated_transfer: false,
|
|
1381
|
-
guid_creation_num: "1125899906842625",
|
|
1382
|
-
owner: "0x6b8c",
|
|
1383
|
-
transfer_events: {
|
|
1384
|
-
counter: "0",
|
|
1385
|
-
guid: {
|
|
1386
|
-
id: {
|
|
1387
|
-
addr: "0xaaa9",
|
|
1388
|
-
creation_num: "1125899906842624",
|
|
1389
|
-
},
|
|
1390
|
-
},
|
|
1391
|
-
},
|
|
1392
|
-
},
|
|
1393
|
-
},
|
|
1394
|
-
type: "write_resource",
|
|
1395
|
-
},
|
|
1396
|
-
{
|
|
1397
|
-
address: "0xa0d8",
|
|
1398
|
-
state_key_hash: "0x1709",
|
|
1399
|
-
data: {
|
|
1400
|
-
type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
|
|
1401
|
-
data: {
|
|
1402
|
-
coin: {
|
|
1403
|
-
value: "98423118",
|
|
1404
|
-
},
|
|
1405
745
|
deposit_events: {
|
|
1406
|
-
counter: "46",
|
|
1407
746
|
guid: {
|
|
1408
747
|
id: {
|
|
1409
|
-
addr: "
|
|
748
|
+
addr: "0x12",
|
|
1410
749
|
creation_num: "2",
|
|
1411
750
|
},
|
|
1412
751
|
},
|
|
1413
752
|
},
|
|
1414
|
-
frozen: false,
|
|
1415
|
-
withdraw_events: {
|
|
1416
|
-
counter: "88",
|
|
1417
|
-
guid: {
|
|
1418
|
-
id: {
|
|
1419
|
-
addr: "0xa0d8",
|
|
1420
|
-
creation_num: "3",
|
|
1421
|
-
},
|
|
1422
|
-
},
|
|
1423
|
-
},
|
|
1424
|
-
},
|
|
1425
|
-
},
|
|
1426
|
-
type: "write_resource",
|
|
1427
|
-
},
|
|
1428
|
-
{
|
|
1429
|
-
address: "0xa0d8",
|
|
1430
|
-
state_key_hash: "0x6f1e",
|
|
1431
|
-
data: {
|
|
1432
|
-
type: "0x1::account::Account",
|
|
1433
|
-
data: {
|
|
1434
|
-
authentication_key: "0xa0d8",
|
|
1435
|
-
coin_register_events: {
|
|
1436
|
-
counter: "5",
|
|
1437
|
-
guid: {
|
|
1438
|
-
id: {
|
|
1439
|
-
addr: "0xa0d8",
|
|
1440
|
-
creation_num: "0",
|
|
1441
|
-
},
|
|
1442
|
-
},
|
|
1443
|
-
},
|
|
1444
|
-
guid_creation_num: "12",
|
|
1445
|
-
key_rotation_events: {
|
|
1446
|
-
counter: "0",
|
|
1447
|
-
guid: {
|
|
1448
|
-
id: {
|
|
1449
|
-
addr: "0xa0d8",
|
|
1450
|
-
creation_num: "1",
|
|
1451
|
-
},
|
|
1452
|
-
},
|
|
1453
|
-
},
|
|
1454
|
-
rotation_capability_offer: {
|
|
1455
|
-
for: {
|
|
1456
|
-
vec: [],
|
|
1457
|
-
},
|
|
1458
|
-
},
|
|
1459
|
-
sequence_number: "108",
|
|
1460
|
-
signer_capability_offer: {
|
|
1461
|
-
for: {
|
|
1462
|
-
vec: [],
|
|
1463
|
-
},
|
|
1464
|
-
},
|
|
1465
753
|
},
|
|
1466
754
|
},
|
|
1467
|
-
type: "write_resource",
|
|
1468
|
-
},
|
|
1469
|
-
{
|
|
1470
|
-
address: "0xd475",
|
|
1471
|
-
state_key_hash: "0x7567",
|
|
1472
|
-
data: {
|
|
1473
|
-
type: "0x1::fungible_asset::FungibleStore",
|
|
1474
|
-
data: {
|
|
1475
|
-
balance: "14000",
|
|
1476
|
-
frozen: false,
|
|
1477
|
-
metadata: {
|
|
1478
|
-
inner: "0x2ebb",
|
|
1479
|
-
},
|
|
1480
|
-
},
|
|
1481
|
-
},
|
|
1482
|
-
type: "write_resource",
|
|
1483
|
-
},
|
|
1484
|
-
{
|
|
1485
|
-
address: "0xd475",
|
|
1486
|
-
state_key_hash: "0x7567",
|
|
1487
|
-
data: {
|
|
1488
|
-
type: "0x1::object::ObjectCore",
|
|
1489
|
-
data: {
|
|
1490
|
-
allow_ungated_transfer: false,
|
|
1491
|
-
guid_creation_num: "1125899906842625",
|
|
1492
|
-
owner: "0xa0d8",
|
|
1493
|
-
transfer_events: {
|
|
1494
|
-
counter: "0",
|
|
1495
|
-
guid: {
|
|
1496
|
-
id: {
|
|
1497
|
-
addr: "0xd475",
|
|
1498
|
-
creation_num: "1125899906842624",
|
|
1499
|
-
},
|
|
1500
|
-
},
|
|
1501
|
-
},
|
|
1502
|
-
},
|
|
1503
|
-
},
|
|
1504
|
-
type: "write_resource",
|
|
1505
|
-
},
|
|
1506
|
-
{
|
|
1507
|
-
state_key_hash: "0x6e4b",
|
|
1508
|
-
handle: "0x1b85",
|
|
1509
|
-
key: "0x0619",
|
|
1510
|
-
value: "0xad4388dc7daf96010000000000000000",
|
|
1511
|
-
data: null,
|
|
1512
|
-
type: "write_table_item",
|
|
1513
755
|
},
|
|
1514
756
|
],
|
|
1515
757
|
block: { hash: "0xabc", height: 1 },
|
|
@@ -1517,25 +759,9 @@ describe("Aptos sync logic ", () => {
|
|
|
1517
759
|
sequence_number: "1",
|
|
1518
760
|
},
|
|
1519
761
|
];
|
|
1520
|
-
const
|
|
1521
|
-
expect(
|
|
1522
|
-
expect(
|
|
1523
|
-
expect(tokenOps[0]).toEqual({
|
|
1524
|
-
id: expect.any(String),
|
|
1525
|
-
accountId: "token_account_id",
|
|
1526
|
-
hash: "0x10c9",
|
|
1527
|
-
type: DIRECTION.IN,
|
|
1528
|
-
value: new BigNumber(193),
|
|
1529
|
-
fee: new BigNumber(20000),
|
|
1530
|
-
blockHash: "0xabc",
|
|
1531
|
-
blockHeight: 1,
|
|
1532
|
-
senders: ["0xa0d8"],
|
|
1533
|
-
recipients: ["0x6b8c"],
|
|
1534
|
-
date: new Date(1000),
|
|
1535
|
-
extra: { version: undefined },
|
|
1536
|
-
transactionSequenceNumber: 1,
|
|
1537
|
-
hasFailed: false,
|
|
1538
|
-
});
|
|
762
|
+
const result = txsToOps({ address }, id, txs);
|
|
763
|
+
expect(result).toHaveLength(1);
|
|
764
|
+
expect(result[0].hasFailed).toBe(true);
|
|
1539
765
|
});
|
|
1540
766
|
});
|
|
1541
767
|
});
|