@@ -5,6 +5,7 @@ import { DELEGATE_CLAUSE_METHOD_ID, STARGATE_CONTRACT_ADDRESS_TESTNET } from '..
55import EthereumAbi from 'ethereumjs-abi' ;
66import * as testData from '../resources/vet' ;
77import { BN } from 'ethereumjs-util' ;
8+ import utils from '../../src/lib/utils' ;
89
910describe ( 'VET Delegation Transaction' , function ( ) {
1011 const factory = new TransactionBuilderFactory ( coins . get ( 'tvet' ) ) ;
@@ -166,7 +167,35 @@ describe('VET Delegation Transaction', function () {
166167 toJson . expiration . should . equal ( 64 ) ;
167168 toJson . chainTag . should . equal ( 39 ) ;
168169 toJson . tokenId ?. should . equal ( tokenIdForDelegateTxn ) ;
169- toJson . validatorAddress ?. should . equal ( '00563ec3cafbbe7e60b04b3190e6eca66579706d' ) ;
170+ toJson . validatorAddress ?. should . equal ( '0x00563ec3cafbbe7e60b04b3190e6eca66579706d' ) ;
171+ } ) ;
172+ } ) ;
173+
174+ describe ( 'decodeDelegateClauseData' , function ( ) {
175+ it ( 'should correctly decode delegate transaction data with proper address formatting' , function ( ) {
176+ const decodedData = utils . decodeDelegateClauseData ( testData . DELEGATE_CLAUSE_DATA ) ;
177+
178+ decodedData . tokenId . should . equal ( testData . DELEGATE_TOKEN_ID ) ;
179+ decodedData . validator . should . equal ( testData . DELEGATE_VALIDATOR ) ;
180+ decodedData . validator . should . startWith ( '0x' ) ;
181+ decodedData . validator . should . equal ( decodedData . validator . toLowerCase ( ) ) ;
182+ } ) ;
183+
184+ it ( 'should correctly deserialize real signed delegate transaction from raw hex' , async function ( ) {
185+ const txBuilder = factory . from ( testData . SIGNED_DELEGATE_RAW_HEX ) ;
186+ const tx = txBuilder . transaction as DelegateClauseTransaction ;
187+ tx . should . be . instanceof ( DelegateClauseTransaction ) ;
188+ tx . stakingContractAddress . should . equal ( testData . SIGNED_DELEGATE_RAW_EXPECTED_STAKING_CONTRACT ) ;
189+ tx . tokenId . should . equal ( testData . SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID ) ;
190+ tx . validator . should . equal ( testData . SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR ) ;
191+ tx . validator . should . startWith ( '0x' ) ;
192+ tx . validator . should . equal ( tx . validator . toLowerCase ( ) ) ;
193+ should . exist ( tx . inputs ) ;
194+ tx . inputs . length . should . equal ( 1 ) ;
195+
196+ const decodedData = utils . decodeDelegateClauseData ( tx . clauses [ 0 ] . data ) ;
197+ decodedData . tokenId . should . equal ( testData . SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID ) ;
198+ decodedData . validator . should . equal ( testData . SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR ) ;
170199 } ) ;
171200 } ) ;
172201} ) ;
0 commit comments