|
| 1 | +import { getBuilderFactory } from '../getBuilderFactory'; |
| 2 | +import { coins } from '@bitgo/statics'; |
| 3 | +import * as testData from '../../resources/apt'; |
| 4 | +import { TransactionType } from '@bitgo/sdk-core'; |
| 5 | +import should from 'should'; |
| 6 | +import { DelegationPoolUnlockTransaction } from '../../../src/lib/transaction/delegationPoolUnlockTransaction'; |
| 7 | + |
| 8 | +describe('Apt Delegation Pool Unlock Builder', () => { |
| 9 | + const factory = getBuilderFactory('tapt'); |
| 10 | + |
| 11 | + describe('Succeed', () => { |
| 12 | + it('should build a staking delegate transaction', async function () { |
| 13 | + const transaction = new DelegationPoolUnlockTransaction(coins.get('tapt')); |
| 14 | + const txBuilder = factory.getDelegationPoolUnlockTransactionBuilder(transaction); |
| 15 | + txBuilder.sender(testData.sender.address); |
| 16 | + txBuilder.validator(testData.delegationPoolData.validatorAddress, testData.delegationPoolData.amount); |
| 17 | + txBuilder.gasData({ |
| 18 | + maxGasAmount: 200000, |
| 19 | + gasUnitPrice: 100, |
| 20 | + }); |
| 21 | + txBuilder.sequenceNumber(14); |
| 22 | + txBuilder.expirationTime(1736246155); |
| 23 | + txBuilder.addFeePayerAddress(testData.feePayer.address); |
| 24 | + const tx = (await txBuilder.build()) as DelegationPoolUnlockTransaction; |
| 25 | + should.equal(tx.sender, testData.sender.address); |
| 26 | + should.deepEqual(tx.recipients, []); |
| 27 | + should.deepEqual(tx.validatorAddress, testData.delegationPoolData.validatorAddress); |
| 28 | + should.deepEqual(tx.amount, testData.delegationPoolData.amount); |
| 29 | + should.equal(tx.maxGasAmount, 200000); |
| 30 | + should.equal(tx.gasUnitPrice, 100); |
| 31 | + should.equal(tx.sequenceNumber, 14); |
| 32 | + should.equal(tx.expirationTime, 1736246155); |
| 33 | + should.equal(tx.type, TransactionType.StakingUnlock); |
| 34 | + should.deepEqual(tx.inputs, []); |
| 35 | + should.deepEqual(tx.outputs, []); |
| 36 | + const rawTx = tx.toBroadcastFormat(); |
| 37 | + should.equal(txBuilder.isValidRawTransaction(rawTx), true); |
| 38 | + rawTx.should.equal(testData.DELEGATION_POOL_UNLOCK_TX_HEX); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should build and send a signed tx', async function () { |
| 42 | + const txBuilder = factory.from(testData.DELEGATION_POOL_UNLOCK_TX_HEX); |
| 43 | + const tx = (await txBuilder.build()) as DelegationPoolUnlockTransaction; |
| 44 | + tx.inputs.should.deepEqual([]); |
| 45 | + tx.outputs.should.deepEqual([]); |
| 46 | + should.equal(tx.id, '0x471bb32955f9cff7c9c0a603ef2354e781fd80a221f9044f08df84d95473e86f'); |
| 47 | + should.equal(tx.maxGasAmount, 200000); |
| 48 | + should.equal(tx.gasUnitPrice, 100); |
| 49 | + should.equal(tx.sequenceNumber, 14); |
| 50 | + should.equal(tx.expirationTime, 1736246155); |
| 51 | + should.equal(tx.type, TransactionType.StakingUnlock); |
| 52 | + const rawTx = tx.toBroadcastFormat(); |
| 53 | + should.equal(txBuilder.isValidRawTransaction(rawTx), true); |
| 54 | + should.equal(rawTx, testData.DELEGATION_POOL_UNLOCK_TX_HEX); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should succeed to validate a valid signablePayload', async function () { |
| 58 | + const transaction = new DelegationPoolUnlockTransaction(coins.get('tapt')); |
| 59 | + const txBuilder = factory.getDelegationPoolUnlockTransactionBuilder(transaction); |
| 60 | + txBuilder.sender(testData.sender.address); |
| 61 | + txBuilder.validator(testData.delegationPoolData.validatorAddress, testData.delegationPoolData.amount); |
| 62 | + txBuilder.gasData({ |
| 63 | + maxGasAmount: 200000, |
| 64 | + gasUnitPrice: 100, |
| 65 | + }); |
| 66 | + txBuilder.sequenceNumber(14); |
| 67 | + txBuilder.expirationTime(1736246155); |
| 68 | + txBuilder.addFeePayerAddress(testData.feePayer.address); |
| 69 | + const tx = (await txBuilder.build()) as DelegationPoolUnlockTransaction; |
| 70 | + const signablePayload = tx.signablePayload; |
| 71 | + should.equal(signablePayload.toString('hex'), testData.DELEGATION_POOL_UNLOCK_TX_HEX_SIGNABLE_PAYLOAD); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should build a unsigned tx and validate its toJson', async function () { |
| 75 | + const transaction = new DelegationPoolUnlockTransaction(coins.get('tapt')); |
| 76 | + const txBuilder = factory.getDelegationPoolUnlockTransactionBuilder(transaction); |
| 77 | + txBuilder.sender(testData.sender.address); |
| 78 | + txBuilder.validator(testData.delegationPoolData.validatorAddress, testData.delegationPoolData.amount); |
| 79 | + txBuilder.gasData({ |
| 80 | + maxGasAmount: 200000, |
| 81 | + gasUnitPrice: 100, |
| 82 | + }); |
| 83 | + txBuilder.sequenceNumber(14); |
| 84 | + txBuilder.expirationTime(1736246155); |
| 85 | + txBuilder.assetId(testData.fungibleTokenAddress.usdt); |
| 86 | + txBuilder.addFeePayerAddress(testData.feePayer.address); |
| 87 | + const tx = (await txBuilder.build()) as DelegationPoolUnlockTransaction; |
| 88 | + const toJson = tx.toJson(); |
| 89 | + should.equal(toJson.sender, testData.sender.address); |
| 90 | + should.deepEqual(toJson.recipients, []); |
| 91 | + should.deepEqual(tx.validatorAddress, testData.delegationPoolData.validatorAddress); |
| 92 | + should.deepEqual(tx.amount, testData.delegationPoolData.amount); |
| 93 | + should.equal(toJson.sequenceNumber, 14); |
| 94 | + should.equal(toJson.maxGasAmount, 200000); |
| 95 | + should.equal(toJson.gasUnitPrice, 100); |
| 96 | + should.equal(toJson.expirationTime, 1736246155); |
| 97 | + should.equal(toJson.feePayer, testData.feePayer.address); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should build a signed tx and validate its toJson', async function () { |
| 101 | + const txBuilder = factory.from(testData.DELEGATION_POOL_UNLOCK_TX_HEX); |
| 102 | + const tx = (await txBuilder.build()) as DelegationPoolUnlockTransaction; |
| 103 | + const toJson = tx.toJson(); |
| 104 | + should.equal(toJson.id, '0x471bb32955f9cff7c9c0a603ef2354e781fd80a221f9044f08df84d95473e86f'); |
| 105 | + should.equal(toJson.sender, testData.sender.address); |
| 106 | + should.deepEqual(toJson.recipients, []); |
| 107 | + should.deepEqual(tx.validatorAddress, testData.delegationPoolData.validatorAddress); |
| 108 | + should.deepEqual(tx.amount, testData.delegationPoolData.amount); |
| 109 | + should.equal(toJson.maxGasAmount, 200000); |
| 110 | + should.equal(toJson.gasUnitPrice, 100); |
| 111 | + should.equal(toJson.sequenceNumber, 14); |
| 112 | + should.equal(toJson.expirationTime, 1736246155); |
| 113 | + }); |
| 114 | + }); |
| 115 | +}); |
0 commit comments