Skip to content

Commit

Permalink
feat(apt): untracked chaanges
Browse files Browse the repository at this point in the history
Ticket: COIN-2258
  • Loading branch information
baltiyal committed Jan 8, 2025
1 parent 34c7ec8 commit bc95236
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
18 changes: 17 additions & 1 deletion modules/sdk-coin-apt/test/unit/keyPair.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import assert from 'assert';
import { KeyPair } from '../../src';
import { KeyPair, Tapt } from '../../src';
import utils from '../../src/lib/utils';
import should from 'should';
import { Eddsa } from '@bitgo/sdk-core';
import { Ed25519Bip32HdTree, HDTree } from '@bitgo/sdk-lib-mpc';
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';

describe('Apt KeyPair', function () {
let rootKeychain;
let rootPublicKey;
let MPC: Eddsa;
let hdTree: HDTree;
let bitgo: TestBitGoAPI;
let basecoin;

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

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

describe('Keypair from random seed', () => {
it('should generate a keypair from random seed', function () {
const keyPair = basecoin.generateKeyPair();
keyPair.should.have.property('pub');
keyPair.should.have.property('prv');
basecoin.isValidPub(keyPair.pub).should.equal(true);
});
});

describe('should fail to create a KeyPair', function () {
it('from an invalid public key', () => {
const source = {
Expand Down
63 changes: 61 additions & 2 deletions modules/sdk-coin-apt/test/unit/transferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { coins } from '@bitgo/statics';
import { TransactionBuilderFactory, TransferTransaction } from '../../src';
import * as testData from '../resources/apt';
import utils from '../../src/lib/utils';

import { TransactionType } from '@bitgo/sdk-core';
import should from 'should';

Expand Down Expand Up @@ -49,7 +48,7 @@ describe('Apt Transfer Transaction', () => {
);
});

it('should build a transfer tx from a signed raw tx', async function () {
it('should build and send a signed tx', async function () {
const txBuilder = factory.from(testData.TRANSFER);
const tx = (await txBuilder.build()) as TransferTransaction;
should.equal(tx.type, TransactionType.Send);
Expand All @@ -75,6 +74,66 @@ describe('Apt Transfer Transaction', () => {
should.equal(utils.isValidRawTransaction(rawTx), true);
should.equal(rawTx, testData.TRANSFER);
});

it('should succeed to validate a valid signablePayload', async function () {
const transaction = new TransferTransaction(coins.get('tapt'));
const txBuilder = factory.getTransferBuilder(transaction);
txBuilder.sender(testData.sender2.address);
txBuilder.recipient(testData.recipients[0]);
txBuilder.gasData({
maxGasAmount: 200000,
gasUnitPrice: 100,
});
txBuilder.sequenceNumber(14);
txBuilder.expirationTime(1736246155);
const tx = (await txBuilder.build()) as TransferTransaction;
const signablePayload = tx.signablePayload;
should.equal(
signablePayload.toString('hex'),
'b5e97db07fa0bd0e5598aa3643a9bc6f6693bddc1a9fec9e674a461eaa00b193c8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e0000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002'
);
});

it('should build a unsigned tx and validate its toJson', async function () {
const transaction = new TransferTransaction(coins.get('tapt'));
const txBuilder = factory.getTransferBuilder(transaction);
txBuilder.sender(testData.sender2.address);
txBuilder.recipient(testData.recipients[0]);
txBuilder.gasData({
maxGasAmount: 200000,
gasUnitPrice: 100,
});
txBuilder.sequenceNumber(14);
txBuilder.expirationTime(1736246155);
const tx = (await txBuilder.build()) as TransferTransaction;
const toJson = tx.toJson();
should.equal(toJson.id, 'UNAVAILABLE');
should.equal(toJson.sender, testData.sender2.address);
should.deepEqual(toJson.recipient, {
address: testData.recipients[0].address,
amount: testData.recipients[0].amount,
});
should.equal(toJson.sequenceNumber, 14);
should.equal(toJson.maxGasAmount, 200000);
should.equal(toJson.gasUnitPrice, 100);
should.equal(toJson.expirationTime, 1736246155);
});

it('should build a signed tx and validate its toJson', async function () {
const txBuilder = factory.from(testData.TRANSFER);
const tx = (await txBuilder.build()) as TransferTransaction;
const toJson = tx.toJson();
should.equal(toJson.id, '0x43ea7697550d5effb68c47488fd32a7756ee418e8d2be7d6b7f634f3ac0d7766');
should.equal(toJson.sender, '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d09');
should.deepEqual(toJson.recipient, {
address: '0xf7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad9',
amount: '1000',
});
should.equal(toJson.sequenceNumber, 23);
should.equal(toJson.maxGasAmount, 200000);
should.equal(toJson.gasUnitPrice, 100);
should.equal(toJson.expirationTime, 1735818272);
});
});

describe('Fail', () => {
Expand Down

0 comments on commit bc95236

Please sign in to comment.