@ledgerhq/coin-sui 0.10.1-nightly.2 → 0.12.0-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -0
- package/CHANGELOG.md +34 -22
- package/index.d.ts +0 -1
- package/jest.config.js +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +3 -0
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +31 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/buildTransaction.d.ts +1 -1
- package/lib/bridge/buildTransaction.d.ts.map +1 -1
- package/lib/bridge/buildTransaction.js +3 -1
- package/lib/bridge/buildTransaction.js.map +1 -1
- package/lib/bridge/buildTransaction.test.js +4 -0
- package/lib/bridge/buildTransaction.test.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +14 -2
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.test.js +27 -0
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +13 -1
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getOperationExtra.d.ts +2 -0
- package/lib/bridge/getOperationExtra.d.ts.map +1 -0
- package/lib/bridge/getOperationExtra.js +6 -0
- package/lib/bridge/getOperationExtra.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +45 -20
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/preload.d.ts.map +1 -1
- package/lib/bridge/preload.js +5 -3
- package/lib/bridge/preload.js.map +1 -1
- package/lib/bridge/preload.test.js +13 -217
- package/lib/bridge/preload.test.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +5 -2
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/synchronisation.test.js +355 -7
- package/lib/bridge/synchronisation.test.js.map +1 -1
- package/lib/bridge/utils.d.ts +1 -1
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +22 -0
- package/lib/bridge/utils.js.map +1 -1
- package/lib/constants.d.ts +4 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +7 -0
- package/lib/constants.js.map +1 -0
- package/lib/errors.d.ts +13 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +21 -0
- package/lib/errors.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +5 -10
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +14 -2
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/index.d.ts +2 -1
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +3 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/stake.d.ts +3 -0
- package/lib/logic/stake.d.ts.map +1 -0
- package/lib/logic/stake.js +12 -0
- package/lib/logic/stake.js.map +1 -0
- package/lib/network/index.d.ts +5 -4
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +5 -3
- package/lib/network/index.js.map +1 -1
- package/lib/network/sdk.d.ts +5 -3
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +144 -22
- package/lib/network/sdk.js.map +1 -1
- package/lib/network/sdk.test.js +491 -6
- package/lib/network/sdk.test.js.map +1 -1
- package/lib/types/bridge.d.ts +33 -6
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +3 -0
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +31 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/buildTransaction.d.ts +1 -1
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
- package/lib-es/bridge/buildTransaction.js +3 -1
- package/lib-es/bridge/buildTransaction.js.map +1 -1
- package/lib-es/bridge/buildTransaction.test.js +4 -0
- package/lib-es/bridge/buildTransaction.test.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +14 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.test.js +27 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +13 -1
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getOperationExtra.d.ts +2 -0
- package/lib-es/bridge/getOperationExtra.d.ts.map +1 -0
- package/lib-es/bridge/getOperationExtra.js +2 -0
- package/lib-es/bridge/getOperationExtra.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +46 -21
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/preload.d.ts.map +1 -1
- package/lib-es/bridge/preload.js +5 -3
- package/lib-es/bridge/preload.js.map +1 -1
- package/lib-es/bridge/preload.test.js +14 -218
- package/lib-es/bridge/preload.test.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +6 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/synchronisation.test.js +332 -7
- package/lib-es/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +1 -1
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +22 -0
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/constants.d.ts +4 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +4 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/errors.d.ts +13 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +18 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +5 -10
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +14 -2
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -1
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +1 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/stake.d.ts +3 -0
- package/lib-es/logic/stake.d.ts.map +1 -0
- package/lib-es/logic/stake.js +8 -0
- package/lib-es/logic/stake.js.map +1 -0
- package/lib-es/network/index.d.ts +5 -4
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +4 -3
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/sdk.d.ts +5 -3
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +140 -21
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/network/sdk.test.js +491 -6
- package/lib-es/network/sdk.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts +33 -6
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +15 -7
- package/src/bridge/broadcast.ts +3 -0
- package/src/bridge/buildOptimisticOperation.ts +47 -4
- package/src/bridge/buildTransaction.test.ts +4 -0
- package/src/bridge/buildTransaction.ts +3 -1
- package/src/bridge/estimateMaxSpendable.test.ts +33 -0
- package/src/bridge/estimateMaxSpendable.ts +16 -2
- package/src/bridge/getFeesForTransaction.ts +14 -1
- package/src/bridge/getOperationExtra.ts +1 -0
- package/src/bridge/getTransactionStatus.ts +53 -21
- package/src/bridge/preload.test.ts +13 -279
- package/src/bridge/preload.ts +5 -3
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/synchronisation.test.ts +389 -7
- package/src/bridge/synchronisation.ts +6 -3
- package/src/bridge/utils.ts +25 -1
- package/src/constants.ts +4 -0
- package/src/errors.ts +21 -0
- package/src/logic/craftTransaction.ts +6 -9
- package/src/logic/estimateFees.ts +16 -1
- package/src/logic/index.ts +2 -1
- package/src/logic/stake.ts +9 -0
- package/src/network/index.ts +6 -3
- package/src/network/sdk.test.ts +538 -10
- package/src/network/sdk.ts +175 -27
- package/src/types/bridge.ts +32 -6
package/lib/network/sdk.test.js
CHANGED
|
@@ -67,6 +67,20 @@ jest.mock("@mysten/sui/client", () => {
|
|
|
67
67
|
},
|
|
68
68
|
}),
|
|
69
69
|
getReferenceGasPrice: jest.fn().mockResolvedValue("1000"),
|
|
70
|
+
getTransactionBlock: jest.fn().mockResolvedValue({
|
|
71
|
+
transaction: {
|
|
72
|
+
data: {
|
|
73
|
+
transaction: {
|
|
74
|
+
kind: "ProgrammableTransaction",
|
|
75
|
+
inputs: [],
|
|
76
|
+
transactions: [],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
effects: {
|
|
81
|
+
status: { status: "success" },
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
70
84
|
})),
|
|
71
85
|
getFullnodeUrl: jest.fn().mockReturnValue("https://mockapi.sui.io"),
|
|
72
86
|
};
|
|
@@ -85,7 +99,14 @@ jest.mock("@mysten/sui/transactions", () => {
|
|
|
85
99
|
setSender: jest.fn(),
|
|
86
100
|
splitCoins: jest.fn().mockReturnValue(["0xmock_coin"]),
|
|
87
101
|
transferObjects: jest.fn(),
|
|
102
|
+
moveCall: jest.fn(),
|
|
103
|
+
object: jest.fn(),
|
|
104
|
+
pure: {
|
|
105
|
+
address: jest.fn(),
|
|
106
|
+
u64: jest.fn(),
|
|
107
|
+
},
|
|
88
108
|
build: jest.fn().mockResolvedValue(mockTxb),
|
|
109
|
+
setGasBudgetIfNotSet: jest.fn(),
|
|
89
110
|
};
|
|
90
111
|
}),
|
|
91
112
|
};
|
|
@@ -188,6 +209,8 @@ const mockTransaction = {
|
|
|
188
209
|
checkpoint: "313024",
|
|
189
210
|
};
|
|
190
211
|
const mockApi = new client_1.SuiClient({ url: "mock" });
|
|
212
|
+
// Add getTransactionBlock method to mockApi
|
|
213
|
+
mockApi.getTransactionBlock = jest.fn();
|
|
191
214
|
// Helper function to generate mock coins from an array of balances
|
|
192
215
|
const createMockCoins = (balances) => {
|
|
193
216
|
return balances.map((balance, index) => ({
|
|
@@ -243,11 +266,11 @@ describe("SDK Functions", () => {
|
|
|
243
266
|
});
|
|
244
267
|
test("getOperationType should return IN for incoming tx", () => {
|
|
245
268
|
const address = "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164";
|
|
246
|
-
expect(sdk.getOperationType(address, mockTransaction
|
|
269
|
+
expect(sdk.getOperationType(address, mockTransaction)).toBe("IN");
|
|
247
270
|
});
|
|
248
271
|
test("getOperationType should return OUT for outgoing tx", () => {
|
|
249
272
|
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
250
|
-
expect(sdk.getOperationType(address, mockTransaction
|
|
273
|
+
expect(sdk.getOperationType(address, mockTransaction)).toBe("OUT");
|
|
251
274
|
});
|
|
252
275
|
test("getOperationSenders should return sender address", () => {
|
|
253
276
|
expect(sdk.getOperationSenders(mockTransaction.transaction?.data)).toEqual(["0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24"]);
|
|
@@ -473,6 +496,470 @@ describe("SDK Functions", () => {
|
|
|
473
496
|
}
|
|
474
497
|
});
|
|
475
498
|
});
|
|
499
|
+
describe("Staking Operations", () => {
|
|
500
|
+
describe("Operation Type Detection", () => {
|
|
501
|
+
test("getOperationType should return DELEGATE for staking transaction", () => {
|
|
502
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
503
|
+
// Create a mock staking transaction
|
|
504
|
+
const mockStakingTx = {
|
|
505
|
+
digest: "delegate_tx_digest_123",
|
|
506
|
+
transaction: {
|
|
507
|
+
data: {
|
|
508
|
+
sender: address,
|
|
509
|
+
transaction: {
|
|
510
|
+
kind: "ProgrammableTransaction",
|
|
511
|
+
inputs: [],
|
|
512
|
+
transactions: [
|
|
513
|
+
{
|
|
514
|
+
MoveCall: {
|
|
515
|
+
function: "request_add_stake",
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
effects: {
|
|
523
|
+
status: { status: "success" },
|
|
524
|
+
gasUsed: {
|
|
525
|
+
computationCost: "1000000",
|
|
526
|
+
storageCost: "500000",
|
|
527
|
+
storageRebate: "450000",
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
balanceChanges: [
|
|
531
|
+
{
|
|
532
|
+
owner: { AddressOwner: address },
|
|
533
|
+
coinType: "0x2::sui::SUI",
|
|
534
|
+
amount: "-1000000000",
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
timestampMs: "1742294454878",
|
|
538
|
+
checkpoint: "313024",
|
|
539
|
+
};
|
|
540
|
+
expect(sdk.getOperationType(address, mockStakingTx)).toBe("DELEGATE");
|
|
541
|
+
});
|
|
542
|
+
test("getOperationType should return UNDELEGATE for unstaking transaction", () => {
|
|
543
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
544
|
+
// Create a mock unstaking transaction
|
|
545
|
+
const mockUnstakingTx = {
|
|
546
|
+
digest: "undelegate_tx_digest_456",
|
|
547
|
+
transaction: {
|
|
548
|
+
data: {
|
|
549
|
+
sender: address,
|
|
550
|
+
transaction: {
|
|
551
|
+
kind: "ProgrammableTransaction",
|
|
552
|
+
inputs: [],
|
|
553
|
+
transactions: [
|
|
554
|
+
{
|
|
555
|
+
MoveCall: {
|
|
556
|
+
function: "request_withdraw_stake",
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
],
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
effects: {
|
|
564
|
+
status: { status: "success" },
|
|
565
|
+
gasUsed: {
|
|
566
|
+
computationCost: "1000000",
|
|
567
|
+
storageCost: "500000",
|
|
568
|
+
storageRebate: "450000",
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
balanceChanges: [
|
|
572
|
+
{
|
|
573
|
+
owner: { AddressOwner: address },
|
|
574
|
+
coinType: "0x2::sui::SUI",
|
|
575
|
+
amount: "0",
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
timestampMs: "1742294454878",
|
|
579
|
+
checkpoint: "313024",
|
|
580
|
+
};
|
|
581
|
+
expect(sdk.getOperationType(address, mockUnstakingTx)).toBe("UNDELEGATE");
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
describe("Operation Amount Calculation", () => {
|
|
585
|
+
test("getOperationAmount should calculate staking amount correctly", () => {
|
|
586
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
587
|
+
const mockStakingTx = {
|
|
588
|
+
transaction: {
|
|
589
|
+
data: {
|
|
590
|
+
transaction: {
|
|
591
|
+
kind: "ProgrammableTransaction",
|
|
592
|
+
transactions: [
|
|
593
|
+
{
|
|
594
|
+
MoveCall: {
|
|
595
|
+
function: "request_add_stake",
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
],
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
balanceChanges: [
|
|
603
|
+
{
|
|
604
|
+
owner: { AddressOwner: address },
|
|
605
|
+
coinType: "0x2::sui::SUI",
|
|
606
|
+
amount: "-1000000000",
|
|
607
|
+
},
|
|
608
|
+
],
|
|
609
|
+
};
|
|
610
|
+
const amount = sdk.getOperationAmount(address, mockStakingTx, sdk.DEFAULT_COIN_TYPE);
|
|
611
|
+
expect(amount).toEqual(new bignumber_js_1.BigNumber("1000000000")); // The function returns minus of the balance change
|
|
612
|
+
});
|
|
613
|
+
test("getOperationAmount should calculate unstaking amount correctly", () => {
|
|
614
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
615
|
+
const mockUnstakingTx = {
|
|
616
|
+
transaction: {
|
|
617
|
+
data: {
|
|
618
|
+
transaction: {
|
|
619
|
+
kind: "ProgrammableTransaction",
|
|
620
|
+
transactions: [
|
|
621
|
+
{
|
|
622
|
+
MoveCall: {
|
|
623
|
+
function: "request_withdraw_stake",
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
],
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
balanceChanges: [
|
|
631
|
+
{
|
|
632
|
+
owner: { AddressOwner: address },
|
|
633
|
+
coinType: "0x2::sui::SUI",
|
|
634
|
+
amount: "0",
|
|
635
|
+
},
|
|
636
|
+
],
|
|
637
|
+
};
|
|
638
|
+
const amount = sdk.getOperationAmount(address, mockUnstakingTx, sdk.DEFAULT_COIN_TYPE);
|
|
639
|
+
expect(amount).toEqual(new bignumber_js_1.BigNumber("0"));
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
describe("Operation Recipients", () => {
|
|
643
|
+
test("getOperationRecipients should return empty array for staking transaction", () => {
|
|
644
|
+
const mockStakingTx = {
|
|
645
|
+
transaction: {
|
|
646
|
+
data: {
|
|
647
|
+
transaction: {
|
|
648
|
+
kind: "ProgrammableTransaction",
|
|
649
|
+
inputs: [],
|
|
650
|
+
transactions: [
|
|
651
|
+
{
|
|
652
|
+
MoveCall: {
|
|
653
|
+
function: "request_add_stake",
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
],
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
};
|
|
661
|
+
const recipients = sdk.getOperationRecipients(mockStakingTx.transaction?.data);
|
|
662
|
+
expect(recipients).toEqual([]);
|
|
663
|
+
});
|
|
664
|
+
test("getOperationRecipients should return empty array for unstaking transaction", () => {
|
|
665
|
+
const mockUnstakingTx = {
|
|
666
|
+
transaction: {
|
|
667
|
+
data: {
|
|
668
|
+
transaction: {
|
|
669
|
+
kind: "ProgrammableTransaction",
|
|
670
|
+
inputs: [],
|
|
671
|
+
transactions: [
|
|
672
|
+
{
|
|
673
|
+
MoveCall: {
|
|
674
|
+
function: "request_withdraw_stake",
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
],
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
const recipients = sdk.getOperationRecipients(mockUnstakingTx.transaction?.data);
|
|
683
|
+
expect(recipients).toEqual([]);
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
describe("Transaction Creation", () => {
|
|
687
|
+
test("createTransaction should build delegate transaction", async () => {
|
|
688
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
689
|
+
const transaction = {
|
|
690
|
+
mode: "delegate",
|
|
691
|
+
coinType: sdk.DEFAULT_COIN_TYPE,
|
|
692
|
+
amount: new bignumber_js_1.BigNumber(1000000000), // 1 SUI
|
|
693
|
+
recipient: "0xvalidator_address_123",
|
|
694
|
+
};
|
|
695
|
+
const tx = await sdk.createTransaction(address, transaction);
|
|
696
|
+
expect(tx).toBeDefined();
|
|
697
|
+
});
|
|
698
|
+
test("createTransaction should build undelegate transaction with specific amount", async () => {
|
|
699
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
700
|
+
const transaction = {
|
|
701
|
+
mode: "undelegate",
|
|
702
|
+
coinType: sdk.DEFAULT_COIN_TYPE,
|
|
703
|
+
amount: new bignumber_js_1.BigNumber(500000000), // 0.5 SUI
|
|
704
|
+
stakedSuiId: "0xstaked_sui_object_123",
|
|
705
|
+
useAllAmount: false,
|
|
706
|
+
recipient: "0xvalidator_address_123", // Required by type but not used for undelegate
|
|
707
|
+
};
|
|
708
|
+
const tx = await sdk.createTransaction(address, transaction);
|
|
709
|
+
expect(tx).toBeDefined();
|
|
710
|
+
});
|
|
711
|
+
test("createTransaction should build undelegate transaction with all amount", async () => {
|
|
712
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
713
|
+
const transaction = {
|
|
714
|
+
mode: "undelegate",
|
|
715
|
+
coinType: sdk.DEFAULT_COIN_TYPE,
|
|
716
|
+
amount: new bignumber_js_1.BigNumber(0),
|
|
717
|
+
stakedSuiId: "0xstaked_sui_object_123",
|
|
718
|
+
useAllAmount: true,
|
|
719
|
+
recipient: "0xvalidator_address_123", // Required by type but not used for undelegate
|
|
720
|
+
};
|
|
721
|
+
const tx = await sdk.createTransaction(address, transaction);
|
|
722
|
+
expect(tx).toBeDefined();
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
describe("Payment Info for Staking", () => {
|
|
726
|
+
test("paymentInfo should return gas budget and fees for delegate transaction", async () => {
|
|
727
|
+
const sender = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
728
|
+
const fakeTransaction = {
|
|
729
|
+
mode: "delegate",
|
|
730
|
+
coinType: sdk.DEFAULT_COIN_TYPE,
|
|
731
|
+
family: "sui",
|
|
732
|
+
amount: new bignumber_js_1.BigNumber(1000000000), // 1 SUI
|
|
733
|
+
recipient: "0xvalidator_address_123",
|
|
734
|
+
errors: {},
|
|
735
|
+
};
|
|
736
|
+
const info = await sdk.paymentInfo(sender, fakeTransaction);
|
|
737
|
+
expect(info).toHaveProperty("gasBudget");
|
|
738
|
+
expect(info).toHaveProperty("totalGasUsed");
|
|
739
|
+
expect(info).toHaveProperty("fees");
|
|
740
|
+
});
|
|
741
|
+
test("paymentInfo should return gas budget and fees for undelegate transaction", async () => {
|
|
742
|
+
const sender = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
743
|
+
const fakeTransaction = {
|
|
744
|
+
mode: "undelegate",
|
|
745
|
+
coinType: sdk.DEFAULT_COIN_TYPE,
|
|
746
|
+
family: "sui",
|
|
747
|
+
amount: new bignumber_js_1.BigNumber(500000000), // 0.5 SUI
|
|
748
|
+
stakedSuiId: "0xstaked_sui_object_123",
|
|
749
|
+
useAllAmount: false,
|
|
750
|
+
recipient: "0xvalidator_address_123", // Required by type but not used for undelegate
|
|
751
|
+
errors: {},
|
|
752
|
+
};
|
|
753
|
+
const info = await sdk.paymentInfo(sender, fakeTransaction);
|
|
754
|
+
expect(info).toHaveProperty("gasBudget");
|
|
755
|
+
expect(info).toHaveProperty("totalGasUsed");
|
|
756
|
+
expect(info).toHaveProperty("fees");
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
describe("Transaction to Operation Mapping", () => {
|
|
760
|
+
test("transactionToOperation should map staking transaction correctly", () => {
|
|
761
|
+
const accountId = "mockAccountId";
|
|
762
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
763
|
+
const mockStakingTx = {
|
|
764
|
+
digest: "delegate_tx_digest_123",
|
|
765
|
+
transaction: {
|
|
766
|
+
data: {
|
|
767
|
+
sender: address,
|
|
768
|
+
transaction: {
|
|
769
|
+
kind: "ProgrammableTransaction",
|
|
770
|
+
inputs: [],
|
|
771
|
+
transactions: [
|
|
772
|
+
{
|
|
773
|
+
MoveCall: {
|
|
774
|
+
function: "request_add_stake",
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
],
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
},
|
|
781
|
+
effects: {
|
|
782
|
+
status: { status: "success" },
|
|
783
|
+
gasUsed: {
|
|
784
|
+
computationCost: "1000000",
|
|
785
|
+
storageCost: "500000",
|
|
786
|
+
storageRebate: "450000",
|
|
787
|
+
},
|
|
788
|
+
},
|
|
789
|
+
balanceChanges: [
|
|
790
|
+
{
|
|
791
|
+
owner: { AddressOwner: address },
|
|
792
|
+
coinType: "0x2::sui::SUI",
|
|
793
|
+
amount: "-1000000000",
|
|
794
|
+
},
|
|
795
|
+
],
|
|
796
|
+
timestampMs: "1742294454878",
|
|
797
|
+
checkpoint: "313024",
|
|
798
|
+
};
|
|
799
|
+
const operation = sdk.transactionToOperation(accountId, address, mockStakingTx);
|
|
800
|
+
expect(operation).toHaveProperty("id");
|
|
801
|
+
expect(operation).toHaveProperty("accountId", accountId);
|
|
802
|
+
expect(operation).toHaveProperty("type", "DELEGATE");
|
|
803
|
+
expect(operation).toHaveProperty("hash", "delegate_tx_digest_123");
|
|
804
|
+
expect(operation).toHaveProperty("extra");
|
|
805
|
+
expect(operation.extra.coinType).toBe(sdk.DEFAULT_COIN_TYPE);
|
|
806
|
+
expect(operation.value).toEqual(new bignumber_js_1.BigNumber("1000000000")); // The function returns minus of the balance change
|
|
807
|
+
expect(operation.recipients).toEqual([]);
|
|
808
|
+
expect(operation.senders).toEqual([address]);
|
|
809
|
+
});
|
|
810
|
+
test("transactionToOperation should map unstaking transaction correctly", () => {
|
|
811
|
+
const accountId = "mockAccountId";
|
|
812
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
813
|
+
const mockUnstakingTx = {
|
|
814
|
+
digest: "undelegate_tx_digest_456",
|
|
815
|
+
transaction: {
|
|
816
|
+
data: {
|
|
817
|
+
sender: address,
|
|
818
|
+
transaction: {
|
|
819
|
+
kind: "ProgrammableTransaction",
|
|
820
|
+
inputs: [],
|
|
821
|
+
transactions: [
|
|
822
|
+
{
|
|
823
|
+
MoveCall: {
|
|
824
|
+
function: "request_withdraw_stake",
|
|
825
|
+
},
|
|
826
|
+
},
|
|
827
|
+
],
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
effects: {
|
|
832
|
+
status: { status: "success" },
|
|
833
|
+
gasUsed: {
|
|
834
|
+
computationCost: "1000000",
|
|
835
|
+
storageCost: "500000",
|
|
836
|
+
storageRebate: "450000",
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
balanceChanges: [
|
|
840
|
+
{
|
|
841
|
+
owner: { AddressOwner: address },
|
|
842
|
+
coinType: "0x2::sui::SUI",
|
|
843
|
+
amount: "0",
|
|
844
|
+
},
|
|
845
|
+
],
|
|
846
|
+
timestampMs: "1742294454878",
|
|
847
|
+
checkpoint: "313024",
|
|
848
|
+
};
|
|
849
|
+
const operation = sdk.transactionToOperation(accountId, address, mockUnstakingTx);
|
|
850
|
+
expect(operation).toHaveProperty("id");
|
|
851
|
+
expect(operation).toHaveProperty("accountId", accountId);
|
|
852
|
+
expect(operation).toHaveProperty("type", "UNDELEGATE");
|
|
853
|
+
expect(operation).toHaveProperty("hash", "undelegate_tx_digest_456");
|
|
854
|
+
expect(operation).toHaveProperty("extra");
|
|
855
|
+
expect(operation.extra.coinType).toBe(sdk.DEFAULT_COIN_TYPE);
|
|
856
|
+
expect(operation.value).toEqual(new bignumber_js_1.BigNumber("0"));
|
|
857
|
+
expect(operation.recipients).toEqual([]);
|
|
858
|
+
expect(operation.senders).toEqual([address]);
|
|
859
|
+
});
|
|
860
|
+
test("transactionToOp should map staking transaction correctly", () => {
|
|
861
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
862
|
+
const mockStakingTx = {
|
|
863
|
+
digest: "delegate_tx_digest_123",
|
|
864
|
+
transaction: {
|
|
865
|
+
data: {
|
|
866
|
+
sender: address,
|
|
867
|
+
transaction: {
|
|
868
|
+
kind: "ProgrammableTransaction",
|
|
869
|
+
inputs: [],
|
|
870
|
+
transactions: [
|
|
871
|
+
{
|
|
872
|
+
MoveCall: {
|
|
873
|
+
function: "request_add_stake",
|
|
874
|
+
},
|
|
875
|
+
},
|
|
876
|
+
],
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
effects: {
|
|
881
|
+
status: { status: "success" },
|
|
882
|
+
gasUsed: {
|
|
883
|
+
computationCost: "1000000",
|
|
884
|
+
storageCost: "500000",
|
|
885
|
+
storageRebate: "450000",
|
|
886
|
+
},
|
|
887
|
+
},
|
|
888
|
+
balanceChanges: [
|
|
889
|
+
{
|
|
890
|
+
owner: { AddressOwner: address },
|
|
891
|
+
coinType: "0x2::sui::SUI",
|
|
892
|
+
amount: "-1000000000",
|
|
893
|
+
},
|
|
894
|
+
],
|
|
895
|
+
timestampMs: "1742294454878",
|
|
896
|
+
checkpoint: "313024",
|
|
897
|
+
};
|
|
898
|
+
const operation = sdk.transactionToOp(address, mockStakingTx);
|
|
899
|
+
expect(operation.id).toEqual("delegate_tx_digest_123");
|
|
900
|
+
expect(operation.type).toEqual("DELEGATE");
|
|
901
|
+
expect(operation.senders).toEqual([address]);
|
|
902
|
+
expect(operation.recipients).toEqual([]);
|
|
903
|
+
expect(operation.value).toEqual(1000000000n); // The function returns minus of the balance change
|
|
904
|
+
expect(operation.asset).toEqual({ type: "native" });
|
|
905
|
+
});
|
|
906
|
+
test("transactionToOp should map unstaking transaction correctly", () => {
|
|
907
|
+
const address = "0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24";
|
|
908
|
+
const mockUnstakingTx = {
|
|
909
|
+
digest: "undelegate_tx_digest_456",
|
|
910
|
+
transaction: {
|
|
911
|
+
data: {
|
|
912
|
+
sender: address,
|
|
913
|
+
transaction: {
|
|
914
|
+
kind: "ProgrammableTransaction",
|
|
915
|
+
inputs: [],
|
|
916
|
+
transactions: [
|
|
917
|
+
{
|
|
918
|
+
MoveCall: {
|
|
919
|
+
function: "request_withdraw_stake",
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
],
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
},
|
|
926
|
+
effects: {
|
|
927
|
+
status: { status: "success" },
|
|
928
|
+
gasUsed: {
|
|
929
|
+
computationCost: "1000000",
|
|
930
|
+
storageCost: "500000",
|
|
931
|
+
storageRebate: "450000",
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
balanceChanges: [
|
|
935
|
+
{
|
|
936
|
+
owner: { AddressOwner: address },
|
|
937
|
+
coinType: "0x2::sui::SUI",
|
|
938
|
+
amount: "0",
|
|
939
|
+
},
|
|
940
|
+
],
|
|
941
|
+
timestampMs: "1742294454878",
|
|
942
|
+
checkpoint: "313024",
|
|
943
|
+
};
|
|
944
|
+
const operation = sdk.transactionToOp(address, mockUnstakingTx);
|
|
945
|
+
expect(operation.id).toEqual("undelegate_tx_digest_456");
|
|
946
|
+
expect(operation.type).toEqual("UNDELEGATE");
|
|
947
|
+
expect(operation.senders).toEqual([address]);
|
|
948
|
+
expect(operation.recipients).toEqual([]);
|
|
949
|
+
expect(operation.value).toEqual(0n);
|
|
950
|
+
expect(operation.asset).toEqual({ type: "native" });
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
describe("Operation Extra Information", () => {
|
|
954
|
+
test("getOperationExtra should be a function", () => {
|
|
955
|
+
expect(typeof sdk.getOperationExtra).toBe("function");
|
|
956
|
+
});
|
|
957
|
+
test("getOperationExtra should return a Promise", () => {
|
|
958
|
+
const result = sdk.getOperationExtra("test_digest");
|
|
959
|
+
expect(result).toBeInstanceOf(Promise);
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
});
|
|
476
963
|
describe("queryTransactions", () => {
|
|
477
964
|
it("should call api.queryTransactionBlocks with correct params for IN", async () => {
|
|
478
965
|
mockApi.queryTransactionBlocks.mockResolvedValueOnce({
|
|
@@ -1145,10 +1632,8 @@ describe("filterOperations", () => {
|
|
|
1145
1632
|
test("toBlockOperation should ignore transfers from consensus owner", () => {
|
|
1146
1633
|
expect(sdk.toBlockOperation({
|
|
1147
1634
|
owner: {
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
SingleOwner: "test",
|
|
1151
|
-
},
|
|
1635
|
+
ConsensusAddressOwner: {
|
|
1636
|
+
owner: "test",
|
|
1152
1637
|
start_version: "1",
|
|
1153
1638
|
},
|
|
1154
1639
|
},
|