@@ -10,61 +10,77 @@ import { TransferTransaction } from '../../src';
1010describe ( 'Apt Transfer Transaction' , ( ) => {
1111 const factory = new TransactionBuilderFactory ( coins . get ( 'tapt' ) ) ;
1212
13- it ( 'should build a transfer tx' , async function ( ) {
14- const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
15- const txBuilder = factory . getTransferBuilder ( transaction ) ;
16- txBuilder . sender ( testData . sender2 . address ) ;
17- txBuilder . recipient ( testData . recipients [ 0 ] ) ;
18- txBuilder . gasData ( {
19- maxGasAmount : 200000 ,
20- gasUnitPrice : 100 ,
13+ describe ( 'Succeed' , ( ) => {
14+ it ( 'should build a transfer tx' , async function ( ) {
15+ const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
16+ const txBuilder = factory . getTransferBuilder ( transaction ) ;
17+ txBuilder . sender ( testData . sender2 . address ) ;
18+ txBuilder . recipient ( testData . recipients [ 0 ] ) ;
19+ txBuilder . gasData ( {
20+ maxGasAmount : 200000 ,
21+ gasUnitPrice : 100 ,
22+ } ) ;
23+ txBuilder . sequenceNumber ( 14 ) ;
24+ txBuilder . expirationTime ( 1736246155 ) ;
25+ const tx = await txBuilder . build ( ) ;
26+ should . equal ( tx . type , TransactionType . Send ) ;
27+ tx . inputs . length . should . equal ( 1 ) ;
28+ tx . inputs [ 0 ] . should . deepEqual ( {
29+ address : testData . sender2 . address ,
30+ value : testData . recipients [ 0 ] . amount ,
31+ coin : 'tapt' ,
32+ } ) ;
33+ tx . outputs . length . should . equal ( 1 ) ;
34+ tx . outputs [ 0 ] . should . deepEqual ( {
35+ address : testData . recipients [ 0 ] . address ,
36+ value : testData . recipients [ 0 ] . amount ,
37+ coin : 'tapt' ,
38+ } ) ;
39+ const rawTx = tx . toBroadcastFormat ( ) ;
40+ should . equal ( utils . isValidRawTransaction ( rawTx ) , true ) ;
41+ rawTx . should . equal (
42+ '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e0000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
43+ ) ;
2144 } ) ;
22- txBuilder . sequenceNumber ( 14 ) ;
23- txBuilder . expirationTime ( 1736246155 ) ;
24- const tx = await txBuilder . build ( ) ;
25- should . equal ( tx . type , TransactionType . Send ) ;
26- tx . inputs . length . should . equal ( 1 ) ;
27- tx . inputs [ 0 ] . should . deepEqual ( {
28- address : testData . sender2 . address ,
29- value : testData . recipients [ 0 ] . amount ,
30- coin : 'tapt' ,
31- } ) ;
32- tx . outputs . length . should . equal ( 1 ) ;
33- tx . outputs [ 0 ] . should . deepEqual ( {
34- address : testData . recipients [ 0 ] . address ,
35- value : testData . recipients [ 0 ] . amount ,
36- coin : 'tapt' ,
45+
46+ it ( 'should build and send a signed tx' , async function ( ) {
47+ const txHex = testData . TRANSFER ;
48+ const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
49+ transaction . fromRawTransaction ( txHex ) ;
50+
51+ const txBuilder = factory . getTransferBuilder ( transaction ) ;
52+ const tx = await txBuilder . build ( ) ;
53+ should . equal ( tx . type , TransactionType . Send ) ;
54+ tx . inputs . length . should . equal ( 1 ) ;
55+ tx . inputs [ 0 ] . should . deepEqual ( {
56+ address : testData . sender2 . address ,
57+ value : testData . recipients [ 0 ] . amount ,
58+ coin : 'tapt' ,
59+ } ) ;
60+ tx . outputs . length . should . equal ( 1 ) ;
61+ tx . outputs [ 0 ] . should . deepEqual ( {
62+ address : testData . recipients [ 0 ] . address ,
63+ value : testData . recipients [ 0 ] . amount ,
64+ coin : 'tapt' ,
65+ } ) ;
66+ const rawTx = tx . toBroadcastFormat ( ) ;
67+ should . equal ( utils . isValidRawTransaction ( rawTx ) , true ) ;
68+ should . equal ( rawTx , testData . TRANSFER ) ;
3769 } ) ;
38- const rawTx = tx . toBroadcastFormat ( ) ;
39- should . equal ( utils . isValidRawTransaction ( rawTx ) , true ) ;
40- rawTx . should . equal (
41- '0xc8f02d25aa698b3e9fbd8a08e8da4c8ee261832a25a4cde8731b5ec356537d090e0000000000000002000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220f7405c28a02cf5bab4ea4498240bb3579db45951794eb1c843bef0534c093ad908e803000000000000400d03000000000064000000000000008b037d670000000002002000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
42- ) ;
4370 } ) ;
4471
45- it ( 'should build and send a signed tx' , async function ( ) {
46- const txHex = testData . TRANSFER ;
47- const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
48- transaction . fromRawTransaction ( txHex ) ;
49- // const explainedTx = transaction.explainTransaction(); // can be used for verification
50- const txBuilder = factory . getTransferBuilder ( transaction ) ;
51- const tx = await txBuilder . build ( ) ;
52- should . equal ( tx . type , TransactionType . Send ) ;
53- tx . inputs . length . should . equal ( 1 ) ;
54- tx . inputs [ 0 ] . should . deepEqual ( {
55- address : testData . sender2 . address ,
56- value : testData . recipients [ 0 ] . amount ,
57- coin : 'tapt' ,
72+ describe ( 'Fail' , ( ) => {
73+ it ( 'should fail for invalid sender' , async function ( ) {
74+ const transaction = new TransferTransaction ( coins . get ( 'tapt' ) ) ;
75+ const builder = factory . getTransferBuilder ( transaction ) ;
76+ should ( ( ) => builder . sender ( 'randomString' ) ) . throwError ( 'Invalid address randomString' ) ;
5877 } ) ;
59- tx . outputs . length . should . equal ( 1 ) ;
60- tx . outputs [ 0 ] . should . deepEqual ( {
61- address : testData . recipients [ 0 ] . address ,
62- value : testData . recipients [ 0 ] . amount ,
63- coin : 'tapt' ,
78+
79+ it ( 'should fail for invalid recipient' , async function ( ) {
80+ const builder = factory . getTransferBuilder ( ) ;
81+ should ( ( ) => builder . recipient ( testData . invalidRecipients [ 0 ] ) ) . throwError ( 'Invalid address randomString' ) ;
82+ should ( ( ) => builder . recipient ( testData . invalidRecipients [ 1 ] ) ) . throwError ( 'Value cannot be less than zero' ) ;
83+ should ( ( ) => builder . recipient ( testData . invalidRecipients [ 2 ] ) ) . throwError ( 'Invalid amount format' ) ;
6484 } ) ;
65- const rawTx = tx . toBroadcastFormat ( ) ;
66- should . equal ( utils . isValidRawTransaction ( rawTx ) , true ) ;
67- should . equal ( rawTx , testData . TRANSFER ) ;
6885 } ) ;
69- // Invalid or Failing Test Case can be added if needed.
7086} ) ;
0 commit comments