Skip to content

Commit bc95236

Browse files
committed
feat(apt): untracked chaanges
Ticket: COIN-2258
1 parent 34c7ec8 commit bc95236

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

modules/sdk-coin-apt/test/unit/keyPair.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import assert from 'assert';
2-
import { KeyPair } from '../../src';
2+
import { KeyPair, Tapt } from '../../src';
33
import utils from '../../src/lib/utils';
44
import should from 'should';
55
import { Eddsa } from '@bitgo/sdk-core';
66
import { Ed25519Bip32HdTree, HDTree } from '@bitgo/sdk-lib-mpc';
7+
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
8+
import { BitGoAPI } from '@bitgo/sdk-api';
79

810
describe('Apt KeyPair', function () {
911
let rootKeychain;
1012
let rootPublicKey;
1113
let MPC: Eddsa;
1214
let hdTree: HDTree;
15+
let bitgo: TestBitGoAPI;
16+
let basecoin;
1317

1418
before(async () => {
1519
hdTree = await Ed25519Bip32HdTree.initialize();
@@ -23,6 +27,9 @@ describe('Apt KeyPair', function () {
2327
const commonKeychain = A_combine.pShare.y + A_combine.pShare.chaincode;
2428
rootKeychain = MPC.deriveUnhardened(commonKeychain, 'm/0');
2529
rootPublicKey = Buffer.from(rootKeychain, 'hex').slice(0, 32).toString('hex');
30+
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' });
31+
bitgo.safeRegister('tapt', Tapt.createInstance);
32+
basecoin = bitgo.coin('tapt');
2633
});
2734

2835
describe('should create a valid KeyPair', () => {
@@ -47,6 +54,15 @@ describe('Apt KeyPair', function () {
4754
});
4855
});
4956

57+
describe('Keypair from random seed', () => {
58+
it('should generate a keypair from random seed', function () {
59+
const keyPair = basecoin.generateKeyPair();
60+
keyPair.should.have.property('pub');
61+
keyPair.should.have.property('prv');
62+
basecoin.isValidPub(keyPair.pub).should.equal(true);
63+
});
64+
});
65+
5066
describe('should fail to create a KeyPair', function () {
5167
it('from an invalid public key', () => {
5268
const source = {

modules/sdk-coin-apt/test/unit/transferBuilder.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { coins } from '@bitgo/statics';
22
import { TransactionBuilderFactory, TransferTransaction } from '../../src';
33
import * as testData from '../resources/apt';
44
import utils from '../../src/lib/utils';
5-
65
import { TransactionType } from '@bitgo/sdk-core';
76
import should from 'should';
87

@@ -49,7 +48,7 @@ describe('Apt Transfer Transaction', () => {
4948
);
5049
});
5150

52-
it('should build a transfer tx from a signed raw tx', async function () {
51+
it('should build and send a signed tx', async function () {
5352
const txBuilder = factory.from(testData.TRANSFER);
5453
const tx = (await txBuilder.build()) as TransferTransaction;
5554
should.equal(tx.type, TransactionType.Send);
@@ -75,6 +74,66 @@ describe('Apt Transfer Transaction', () => {
7574
should.equal(utils.isValidRawTransaction(rawTx), true);
7675
should.equal(rawTx, testData.TRANSFER);
7776
});
77+
78+
it('should succeed to validate a valid signablePayload', async function () {
79+
const transaction = new TransferTransaction(coins.get('tapt'));
80+
const txBuilder = factory.getTransferBuilder(transaction);
81+
txBuilder.sender(testData.sender2.address);
82+
txBuilder.recipient(testData.recipients[0]);
83+
txBuilder.gasData({
84+
maxGasAmount: 200000,
85+
gasUnitPrice: 100,
86+
});
87+
txBuilder.sequenceNumber(14);
88+
txBuilder.expirationTime(1736246155);
89+
const tx = (await txBuilder.build()) as TransferTransaction;
90+
const signablePayload = tx.signablePayload;
91+
should.equal(
92+
signablePayload.toString('hex'),
93+
'b5e97db07fa0bd0e5598aa3643a9bc6f6693bddc1a9fec9e674a461eaa00b193c8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e0000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002'
94+
);
95+
});
96+
97+
it('should build a unsigned tx and validate its toJson', async function () {
98+
const transaction = new TransferTransaction(coins.get('tapt'));
99+
const txBuilder = factory.getTransferBuilder(transaction);
100+
txBuilder.sender(testData.sender2.address);
101+
txBuilder.recipient(testData.recipients[0]);
102+
txBuilder.gasData({
103+
maxGasAmount: 200000,
104+
gasUnitPrice: 100,
105+
});
106+
txBuilder.sequenceNumber(14);
107+
txBuilder.expirationTime(1736246155);
108+
const tx = (await txBuilder.build()) as TransferTransaction;
109+
const toJson = tx.toJson();
110+
should.equal(toJson.id, 'UNAVAILABLE');
111+
should.equal(toJson.sender, testData.sender2.address);
112+
should.deepEqual(toJson.recipient, {
113+
address: testData.recipients[0].address,
114+
amount: testData.recipients[0].amount,
115+
});
116+
should.equal(toJson.sequenceNumber, 14);
117+
should.equal(toJson.maxGasAmount, 200000);
118+
should.equal(toJson.gasUnitPrice, 100);
119+
should.equal(toJson.expirationTime, 1736246155);
120+
});
121+
122+
it('should build a signed tx and validate its toJson', async function () {
123+
const txBuilder = factory.from(testData.TRANSFER);
124+
const tx = (await txBuilder.build()) as TransferTransaction;
125+
const toJson = tx.toJson();
126+
should.equal(toJson.id, '0x43ea7697550d5effb68c47488fd32a7756ee418e8d2be7d6b7f634f3ac0d7766');
127+
should.equal(toJson.sender, '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d09');
128+
should.deepEqual(toJson.recipient, {
129+
address: '0xf7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad9',
130+
amount: '1000',
131+
});
132+
should.equal(toJson.sequenceNumber, 23);
133+
should.equal(toJson.maxGasAmount, 200000);
134+
should.equal(toJson.gasUnitPrice, 100);
135+
should.equal(toJson.expirationTime, 1735818272);
136+
});
78137
});
79138

80139
describe('Fail', () => {

0 commit comments

Comments
 (0)