|
| 1 | +import should from 'should'; |
| 2 | +import { TransactionType } from '@bitgo/sdk-core'; |
| 3 | +import { TransactionBuilderFactory } from '../../src'; |
| 4 | +import { coins } from '@bitgo/statics'; |
| 5 | +import * as testData from '../resources/ton'; |
| 6 | + |
| 7 | +describe('Ton Whales Vesting Deposit Builder', () => { |
| 8 | + const factory = new TransactionBuilderFactory(coins.get('tton')); |
| 9 | + const fixture = testData.tonWhalesVestingDepositFixture; |
| 10 | + |
| 11 | + it('should build an unsigned vesting deposit transaction', async function () { |
| 12 | + const txBuilder = factory.getTonWhalesVestingDepositBuilder(); |
| 13 | + |
| 14 | + txBuilder.sender(fixture.sender); |
| 15 | + txBuilder.publicKey(fixture.publicKey); |
| 16 | + txBuilder.sequenceNumber(fixture.seqno); |
| 17 | + txBuilder.expireTime(fixture.expireTime); |
| 18 | + txBuilder.bounceable(fixture.bounceable); |
| 19 | + |
| 20 | + txBuilder.send({ |
| 21 | + address: fixture.recipient.address, |
| 22 | + amount: fixture.recipient.amount, |
| 23 | + }); |
| 24 | + txBuilder.setDepositAmount(fixture.recipient.amount); |
| 25 | + txBuilder.setDepositMessage(); |
| 26 | + |
| 27 | + const tx = await txBuilder.build(); |
| 28 | + |
| 29 | + should.equal(tx.type, TransactionType.TonWhalesVestingDeposit); |
| 30 | + should.equal(tx.toJson().bounceable, fixture.bounceable); |
| 31 | + should.equal(tx.toJson().destination, fixture.recipient.address); |
| 32 | + should.equal(tx.toJson().amount, fixture.recipient.amount); |
| 33 | + |
| 34 | + tx.inputs.length.should.equal(1); |
| 35 | + tx.inputs[0].should.deepEqual({ |
| 36 | + address: fixture.sender, |
| 37 | + value: fixture.recipient.amount, |
| 38 | + coin: 'tton', |
| 39 | + }); |
| 40 | + |
| 41 | + tx.outputs.length.should.equal(1); |
| 42 | + tx.outputs[0].should.deepEqual({ |
| 43 | + address: fixture.recipient.address, |
| 44 | + value: fixture.recipient.amount, |
| 45 | + coin: 'tton', |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should build and parse a vesting deposit transaction', async function () { |
| 50 | + const txBuilder = factory.getTonWhalesVestingDepositBuilder(); |
| 51 | + |
| 52 | + txBuilder.sender(fixture.sender); |
| 53 | + txBuilder.publicKey(fixture.publicKey); |
| 54 | + txBuilder.sequenceNumber(fixture.seqno); |
| 55 | + txBuilder.expireTime(fixture.expireTime); |
| 56 | + txBuilder.bounceable(fixture.bounceable); |
| 57 | + |
| 58 | + txBuilder.send({ |
| 59 | + address: fixture.recipient.address, |
| 60 | + amount: fixture.recipient.amount, |
| 61 | + }); |
| 62 | + txBuilder.setDepositAmount(fixture.recipient.amount); |
| 63 | + txBuilder.setDepositMessage(); |
| 64 | + |
| 65 | + const tx = await txBuilder.build(); |
| 66 | + const rawTx = tx.toBroadcastFormat(); |
| 67 | + |
| 68 | + const txBuilder2 = factory.from(rawTx); |
| 69 | + const tx2 = await txBuilder2.build(); |
| 70 | + |
| 71 | + should.equal(tx2.type, TransactionType.TonWhalesVestingDeposit); |
| 72 | + should.equal(tx2.toBroadcastFormat(), rawTx); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should set the correct message for vesting deposit', async function () { |
| 76 | + const txBuilder = factory.getTonWhalesVestingDepositBuilder(); |
| 77 | + |
| 78 | + txBuilder.sender(fixture.sender); |
| 79 | + txBuilder.publicKey(fixture.publicKey); |
| 80 | + txBuilder.sequenceNumber(fixture.seqno); |
| 81 | + txBuilder.expireTime(fixture.expireTime); |
| 82 | + txBuilder.bounceable(fixture.bounceable); |
| 83 | + |
| 84 | + txBuilder.send({ |
| 85 | + address: fixture.recipient.address, |
| 86 | + amount: fixture.recipient.amount, |
| 87 | + }); |
| 88 | + txBuilder.setDepositAmount(fixture.recipient.amount); |
| 89 | + txBuilder.setDepositMessage(); |
| 90 | + |
| 91 | + const tx = await txBuilder.build(); |
| 92 | + const message = tx['message']; |
| 93 | + should.equal(message, 'Deposit'); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should support vesting contract specific flags', async function () { |
| 97 | + const txBuilder = factory.getTonWhalesVestingDepositBuilder(); |
| 98 | + |
| 99 | + txBuilder.sender(fixture.sender); |
| 100 | + txBuilder.publicKey(fixture.publicKey); |
| 101 | + txBuilder.sequenceNumber(fixture.seqno); |
| 102 | + txBuilder.expireTime(fixture.expireTime); |
| 103 | + txBuilder.bounceable(true); |
| 104 | + txBuilder.isV3ContractMessage(true); |
| 105 | + txBuilder.subWalletId(268); |
| 106 | + |
| 107 | + txBuilder.send({ |
| 108 | + address: fixture.recipient.address, |
| 109 | + amount: fixture.recipient.amount, |
| 110 | + }); |
| 111 | + txBuilder.setDepositAmount(fixture.recipient.amount); |
| 112 | + txBuilder.setDepositMessage(); |
| 113 | + |
| 114 | + const tx = await txBuilder.build(); |
| 115 | + |
| 116 | + should.equal(tx.type, TransactionType.TonWhalesVestingDeposit); |
| 117 | + should.equal(tx.toJson().bounceable, true); |
| 118 | + should.equal(tx.toJson().sub_wallet_id, 268); |
| 119 | + }); |
| 120 | +}); |
0 commit comments