diff --git a/modules/sdk-coin-apt/test/unit/keyPair.ts b/modules/sdk-coin-apt/test/unit/keyPair.ts index ef04ffcf8d..f202c897cf 100644 --- a/modules/sdk-coin-apt/test/unit/keyPair.ts +++ b/modules/sdk-coin-apt/test/unit/keyPair.ts @@ -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(); @@ -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', () => { @@ -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 = { diff --git a/modules/sdk-coin-apt/test/unit/transferBuilder.ts b/modules/sdk-coin-apt/test/unit/transferBuilder.ts index f5f02643b9..af2d3f0da2 100644 --- a/modules/sdk-coin-apt/test/unit/transferBuilder.ts +++ b/modules/sdk-coin-apt/test/unit/transferBuilder.ts @@ -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'; @@ -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); @@ -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', () => {