11import { coins } from '@bitgo/statics' ;
22import { TransactionBuilderFactory , Transaction , DelegateClauseTransaction } from '../../src/lib' ;
33import should from 'should' ;
4- import { DELEGATE_CLAUSE_METHOD_ID , STARGATE_DELEGATION_ADDRESS_TESTNET } from '../../src/lib/constants' ;
4+ import { DELEGATE_CLAUSE_METHOD_ID , STARGATE_CONTRACT_ADDRESS_TESTNET } from '../../src/lib/constants' ;
55import EthereumAbi from 'ethereumjs-abi' ;
66import * as testData from '../resources/vet' ;
7+ import { BN } from 'ethereumjs-util' ;
78
89describe ( 'VET Delegation Transaction' , function ( ) {
910 const factory = new TransactionBuilderFactory ( coins . get ( 'tvet' ) ) ;
10- const tokenId = 100201 ; // Test level ID
11- const delegateForever = true ; // Test delegateForever flag
11+ const tokenId = ' 100201' ; // Test token ID
12+ const validatorAddress = '0x9a7aFCACc88c106f3bbD6B213CD0821D9224d945' ;
1213
1314 // Helper function to create a basic transaction builder with common properties
1415 const createBasicTxBuilder = ( ) => {
@@ -20,12 +21,13 @@ describe('VET Delegation Transaction', function () {
2021 txBuilder . gas ( 100000 ) ;
2122 txBuilder . gasPriceCoef ( 0 ) ;
2223 txBuilder . nonce ( '12345' ) ;
24+ txBuilder . validator ( validatorAddress ) ;
2325 return txBuilder ;
2426 } ;
2527
2628 it ( 'should build a delegate transaction' , async function ( ) {
2729 const txBuilder = factory . getStakingDelegateBuilder ( ) ;
28- txBuilder . stakingContractAddress ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
30+ txBuilder . stakingContractAddress ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
2931 txBuilder . tokenId ( tokenId ) ;
3032 txBuilder . sender ( '0x9378c12BD7502A11F770a5C1F223c959B2805dA9' ) ;
3133 txBuilder . chainTag ( 0x27 ) ; // Testnet chain tag
@@ -34,21 +36,22 @@ describe('VET Delegation Transaction', function () {
3436 txBuilder . gas ( 100000 ) ;
3537 txBuilder . gasPriceCoef ( 0 ) ;
3638 txBuilder . nonce ( '12345' ) ;
39+ txBuilder . validator ( validatorAddress ) ;
3740
3841 const tx = await txBuilder . build ( ) ;
3942 should . exist ( tx ) ;
4043 tx . should . be . instanceof ( Transaction ) ;
4144 tx . should . be . instanceof ( DelegateClauseTransaction ) ;
4245
4346 const delegationTx = tx as DelegateClauseTransaction ;
44- delegationTx . stakingContractAddress . should . equal ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
47+ delegationTx . stakingContractAddress . should . equal ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
4548 delegationTx . tokenId . should . equal ( tokenId ) ;
46- delegationTx . delegateForever . should . equal ( delegateForever ) ;
49+ delegationTx . validator . should . equal ( validatorAddress ) ;
4750
4851 // Verify clauses
4952 delegationTx . clauses . length . should . equal ( 1 ) ;
5053 should . exist ( delegationTx . clauses [ 0 ] . to ) ;
51- delegationTx . clauses [ 0 ] . to ?. should . equal ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
54+ delegationTx . clauses [ 0 ] . to ?. should . equal ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
5255
5356 // Verify transaction data is correctly encoded using ethereumABI
5457 should . exist ( delegationTx . clauses [ 0 ] . data ) ;
@@ -57,8 +60,8 @@ describe('VET Delegation Transaction', function () {
5760
5861 // Verify the encoded data matches what we expect from ethereumABI
5962 const methodName = 'delegate' ;
60- const types = [ 'uint256' , 'bool ' ] ;
61- const params = [ tokenId , delegateForever ] ;
63+ const types = [ 'uint256' , 'address ' ] ;
64+ const params = [ new BN ( tokenId ) , validatorAddress ] ;
6265
6366 const method = EthereumAbi . methodID ( methodName , types ) ;
6467 const args = EthereumAbi . rawEncode ( types , params ) ;
@@ -68,24 +71,33 @@ describe('VET Delegation Transaction', function () {
6871
6972 // Verify recipients
7073 delegationTx . recipients . length . should . equal ( 1 ) ;
71- delegationTx . recipients [ 0 ] . address . should . equal ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
74+ delegationTx . recipients [ 0 ] . address . should . equal ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
7275 } ) ;
7376
7477 describe ( 'Failure scenarios' , function ( ) {
7578 it ( 'should throw error when stakingContractAddress is missing' , async function ( ) {
7679 const txBuilder = createBasicTxBuilder ( ) ;
7780 txBuilder . tokenId ( tokenId ) ;
81+ txBuilder . validator ( validatorAddress ) ;
7882
7983 await txBuilder . build ( ) . should . be . rejectedWith ( 'Staking contract address is required' ) ;
8084 } ) ;
8185
8286 it ( 'should throw error when tokenId is missing' , async function ( ) {
8387 const txBuilder = createBasicTxBuilder ( ) ;
84- txBuilder . stakingContractAddress ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
88+ txBuilder . stakingContractAddress ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
8589
8690 await txBuilder . build ( ) . should . be . rejectedWith ( 'Token ID is required' ) ;
8791 } ) ;
8892
93+ it ( 'should throw error when validator address is missing' , async function ( ) {
94+ const txBuilder = createBasicTxBuilder ( ) ;
95+ txBuilder . stakingContractAddress ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
96+ txBuilder . tokenId ( tokenId ) ;
97+
98+ await txBuilder . build ( ) . should . be . rejectedWith ( 'Validator address is required' ) ;
99+ } ) ;
100+
89101 it ( 'should throw error when stakingContractAddress is invalid' , async function ( ) {
90102 const txBuilder = createBasicTxBuilder ( ) ;
91103
@@ -97,14 +109,15 @@ describe('VET Delegation Transaction', function () {
97109
98110 it ( 'should build transaction with undefined sender but include it in inputs' , async function ( ) {
99111 const txBuilder = factory . getStakingDelegateBuilder ( ) ;
100- txBuilder . stakingContractAddress ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
112+ txBuilder . stakingContractAddress ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
101113 txBuilder . tokenId ( tokenId ) ;
102114 txBuilder . chainTag ( 0x27 ) ;
103115 txBuilder . blockRef ( '0x0000000000000000' ) ;
104116 txBuilder . expiration ( 64 ) ;
105117 txBuilder . gas ( 100000 ) ;
106118 txBuilder . gasPriceCoef ( 0 ) ;
107119 txBuilder . nonce ( '12345' ) ;
120+ txBuilder . validator ( validatorAddress ) ;
108121 // Not setting sender
109122
110123 const tx = await txBuilder . build ( ) ;
@@ -117,12 +130,12 @@ describe('VET Delegation Transaction', function () {
117130
118131 // Verify the transaction has the correct output
119132 delegationTx . outputs . length . should . equal ( 1 ) ;
120- delegationTx . outputs [ 0 ] . address . should . equal ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
133+ delegationTx . outputs [ 0 ] . address . should . equal ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
121134 } ) ;
122135
123136 it ( 'should use network default chainTag when not explicitly set' , async function ( ) {
124137 const txBuilder = factory . getStakingDelegateBuilder ( ) ;
125- txBuilder . stakingContractAddress ( STARGATE_DELEGATION_ADDRESS_TESTNET ) ;
138+ txBuilder . stakingContractAddress ( STARGATE_CONTRACT_ADDRESS_TESTNET ) ;
126139 txBuilder . tokenId ( tokenId ) ;
127140 // Not setting chainTag
128141 txBuilder . blockRef ( '0x0000000000000000' ) ;
@@ -131,6 +144,7 @@ describe('VET Delegation Transaction', function () {
131144 txBuilder . gasPriceCoef ( 0 ) ;
132145 txBuilder . nonce ( '12345' ) ;
133146 txBuilder . sender ( '0x9378c12BD7502A11F770a5C1F223c959B2805dA9' ) ;
147+ txBuilder . validator ( validatorAddress ) ;
134148
135149 const tx = await txBuilder . build ( ) ;
136150 tx . should . be . instanceof ( DelegateClauseTransaction ) ;
@@ -140,6 +154,7 @@ describe('VET Delegation Transaction', function () {
140154 delegationTx . chainTag . should . equal ( 39 ) ;
141155 } ) ;
142156
157+ // TODO(SC-3926): this test needs to be updated with delegate txn data once its done in coins sandbox
143158 it ( 'should build a signed tx and validate its toJson' , async function ( ) {
144159 const txBuilder = factory . from ( testData . DELEGATION_TRANSACTION ) ;
145160 const tx = txBuilder . transaction as DelegateClauseTransaction ;
@@ -153,7 +168,7 @@ describe('VET Delegation Transaction', function () {
153168 toJson . chainTag . should . equal ( 39 ) ;
154169 // in delegate txn, nftTokenId indicates the tokenId
155170 toJson . nftTokenId ?. should . equal ( tokenId ) ;
156- toJson . autorenew ?. should . equal ( true ) ;
171+ toJson . validatorAddress ?. should . equal ( validatorAddress ) ;
157172 } ) ;
158173 } ) ;
159174} ) ;
0 commit comments