@ledgerhq/coin-sui 0.8.0-nightly.2 → 0.8.0-nightly.3

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.
@@ -1,126 +1,118 @@
1
- // TODO: re-enable tests once the reverse proxy for SUI is back online
1
+ import type { AlpacaApi, FeeEstimation, Operation } from "@ledgerhq/coin-framework/api/types";
2
+ import { createApi } from ".";
3
+ import { getFullnodeUrl } from "@mysten/sui/client";
4
+
5
+ describe("Sui Api", () => {
6
+ let module: AlpacaApi;
7
+ const SENDER = "0xc6dcb5b920f2fdb751b4a8bad800a4ee04257020d8d6e493c8103b760095016e";
8
+ const RECIPIENT = "0xba7080172a6d957b9ed2e3eb643529860be963cf4af896fb84f1cde00f46b561";
9
+
10
+ beforeAll(() => {
11
+ module = createApi({
12
+ node: {
13
+ url: getFullnodeUrl("mainnet"),
14
+ },
15
+ });
16
+ });
2
17
 
3
- describe("sui api integration test", () => {
4
- it("is disabled", () => {
5
- expect(true).toBeTruthy();
18
+ describe("estimateFees", () => {
19
+ it("returns a default value", async () => {
20
+ // Given
21
+ const amount = BigInt(100_000);
22
+
23
+ // When
24
+ const result: FeeEstimation = await module.estimateFees({
25
+ asset: { type: "native" },
26
+ type: "send",
27
+ sender: SENDER,
28
+ recipient: RECIPIENT,
29
+ amount: amount,
30
+ });
31
+
32
+ // Then
33
+ expect(result.value).toBeGreaterThan(0);
34
+ });
35
+ });
36
+
37
+ describe("listOperations", () => {
38
+ let txs: Operation[];
39
+
40
+ beforeAll(async () => {
41
+ [txs] = await module.listOperations(SENDER, { minHeight: 0 });
42
+ });
43
+
44
+ it("returns a list regarding address parameter", async () => {
45
+ expect(txs.length).toBeGreaterThanOrEqual(10);
46
+ txs.forEach(operation => {
47
+ const isSenderOrReceipt =
48
+ operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
49
+ expect(isSenderOrReceipt).toBeTruthy();
50
+ });
51
+ });
52
+
53
+ it("returns all operations", async () => {
54
+ expect(txs.length).toBeGreaterThanOrEqual(10);
55
+ const checkSet = new Set(txs.map(elt => elt.tx.hash));
56
+ expect(checkSet.size).toBeLessThanOrEqual(txs.length);
57
+ });
58
+
59
+ it("at least operation should be IN", async () => {
60
+ expect(txs.length).toBeGreaterThanOrEqual(10);
61
+ expect(txs.some(t => t.type === "IN")).toBeTruthy();
62
+ });
63
+
64
+ it("at least operation should be OUT", async () => {
65
+ expect(txs.length).toBeGreaterThanOrEqual(10);
66
+ expect(txs.some(t => t.type === "OUT")).toBeTruthy();
67
+ });
68
+
69
+ it("uses the minHeight to filter", async () => {
70
+ const minHeightTxs = await module.listOperations(SENDER, { minHeight: 154925948 });
71
+ expect(txs.length).toBeGreaterThanOrEqual(minHeightTxs.length);
72
+ });
73
+ });
74
+
75
+ describe("getBalance", () => {
76
+ it("returns a list regarding address parameter", async () => {
77
+ // When
78
+ const [acc] = await module.getBalance(SENDER);
79
+
80
+ // Then
81
+ expect(acc.value).toBeGreaterThan(0);
82
+ });
6
83
  });
7
- });
8
84
 
9
- // import type { AlpacaApi, FeeEstimation, Operation } from "@ledgerhq/coin-framework/api/types";
10
- // import { getEnv } from "@ledgerhq/live-env";
11
- // import { SuiAsset } from "./types";
12
- // import { createApi } from ".";
13
-
14
- // describe("Sui Api", () => {
15
- // let module: AlpacaApi<SuiAsset>;
16
- // const SENDER = "0xc6dcb5b920f2fdb751b4a8bad800a4ee04257020d8d6e493c8103b760095016e";
17
- // const RECIPIENT = "0xba7080172a6d957b9ed2e3eb643529860be963cf4af896fb84f1cde00f46b561";
18
-
19
- // beforeAll(() => {
20
- // module = createApi({
21
- // node: {
22
- // url: getEnv("API_SUI_NODE_PROXY"),
23
- // },
24
- // });
25
- // });
26
-
27
- // describe("estimateFees", () => {
28
- // it("returns a default value", async () => {
29
- // // Given
30
- // const amount = BigInt(100_000);
31
-
32
- // // When
33
- // const result: FeeEstimation = await module.estimateFees({
34
- // asset: { type: "native" },
35
- // type: "send",
36
- // sender: SENDER,
37
- // recipient: RECIPIENT,
38
- // amount: amount,
39
- // });
40
-
41
- // // Then
42
- // expect(result.value).toBeGreaterThan(0);
43
- // });
44
- // });
45
-
46
- // describe("listOperations", () => {
47
- // let txs: Operation<SuiAsset>[];
48
-
49
- // beforeAll(async () => {
50
- // [txs] = await module.listOperations(SENDER, { minHeight: 0 });
51
- // });
52
-
53
- // it("returns a list regarding address parameter", async () => {
54
- // expect(txs.length).toBeGreaterThanOrEqual(10);
55
- // txs.forEach(operation => {
56
- // const isSenderOrReceipt =
57
- // operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
58
- // expect(isSenderOrReceipt).toBeTruthy();
59
- // });
60
- // });
61
-
62
- // it("returns all operations", async () => {
63
- // expect(txs.length).toBeGreaterThanOrEqual(10);
64
- // const checkSet = new Set(txs.map(elt => elt.tx.hash));
65
- // expect(checkSet.size).toBeLessThanOrEqual(txs.length);
66
- // });
67
-
68
- // it("at least operation should be IN", async () => {
69
- // expect(txs.length).toBeGreaterThanOrEqual(10);
70
- // expect(txs.some(t => t.type === "IN")).toBeTruthy();
71
- // });
72
-
73
- // it("at least operation should be OUT", async () => {
74
- // expect(txs.length).toBeGreaterThanOrEqual(10);
75
- // expect(txs.some(t => t.type === "OUT")).toBeTruthy();
76
- // });
77
-
78
- // it("uses the minHeight to filter", async () => {
79
- // const minHeightTxs = await module.listOperations(SENDER, { minHeight: 154925948 });
80
- // expect(txs.length).toBeGreaterThanOrEqual(minHeightTxs.length);
81
- // });
82
- // });
83
-
84
- // describe("getBalance", () => {
85
- // it("returns a list regarding address parameter", async () => {
86
- // // When
87
- // const [acc] = await module.getBalance(SENDER);
88
-
89
- // // Then
90
- // expect(acc.value).toBeGreaterThan(0);
91
- // });
92
- // });
93
-
94
- // describe("getLastBlock", () => {
95
- // it("returns the last block", async () => {
96
- // // When
97
- // const result = await module.lastBlock();
98
- // // Then
99
- // expect(result.hash).toBeDefined();
100
- // expect(result.height).toBeDefined();
101
- // expect(result.time).toBeInstanceOf(Date);
102
- // });
103
- // });
104
-
105
- // describe("getBlockInfo", () => {
106
- // test("getBlockInfo should get block info by id or sequence number", async () => {
107
- // const block = await module.getBlockInfo(164167623);
108
- // expect(block.height).toEqual(164167623);
109
- // expect(block.hash).toEqual("3Q4zW4ieWnNgKLEq6kvVfP35PX2tBDUJERTWYyyz4eyS");
110
- // expect(block.time).toEqual(new Date(1751696298663));
111
- // expect(block.parent?.height).toEqual(164167622);
112
- // expect(block.parent?.hash).toEqual("TODO");
113
- // });
114
- // });
115
-
116
- // describe("getBlock", () => {
117
- // test("getBlock should get block by id or sequence number", async () => {
118
- // const block = await module.getBlock(164167623);
119
- // expect(block.info.height).toEqual(164167623);
120
- // expect(block.info.hash).toEqual("3Q4zW4ieWnNgKLEq6kvVfP35PX2tBDUJERTWYyyz4eyS");
121
- // expect(block.info.time).toEqual(new Date(1751696298663));
122
- // expect(block.info.parent?.height).toEqual(164167622);
123
- // expect(block.info.parent?.hash).toEqual("TODO");
124
- // expect(block.transactions.length).toEqual(19);
125
- // });
126
- // });
85
+ describe("getLastBlock", () => {
86
+ it("returns the last block", async () => {
87
+ // When
88
+ const result = await module.lastBlock();
89
+ // Then
90
+ expect(result.hash).toBeDefined();
91
+ expect(result.height).toBeDefined();
92
+ expect(result.time).toBeInstanceOf(Date);
93
+ });
94
+ });
95
+
96
+ describe("getBlockInfo", () => {
97
+ test("getBlockInfo should get block info by id or sequence number", async () => {
98
+ const block = await module.getBlockInfo(164167623);
99
+ expect(block.height).toEqual(164167623);
100
+ expect(block.hash).toEqual("3Q4zW4ieWnNgKLEq6kvVfP35PX2tBDUJERTWYyyz4eyS");
101
+ expect(block.time).toEqual(new Date(1751696298663));
102
+ expect(block.parent?.height).toEqual(164167622);
103
+ // expect(block.parent?.hash).toEqual("TODO");
104
+ });
105
+ });
106
+
107
+ describe("getBlock", () => {
108
+ test("getBlock should get block by id or sequence number", async () => {
109
+ const block = await module.getBlock(164167623);
110
+ expect(block.info.height).toEqual(164167623);
111
+ expect(block.info.hash).toEqual("3Q4zW4ieWnNgKLEq6kvVfP35PX2tBDUJERTWYyyz4eyS");
112
+ expect(block.info.time).toEqual(new Date(1751696298663));
113
+ expect(block.info.parent?.height).toEqual(164167622);
114
+ // expect(block.info.parent?.hash).toEqual("TODO");
115
+ expect(block.transactions.length).toEqual(19);
116
+ });
117
+ });
118
+ });