diff --git a/modules/sdk-coin-vet/src/lib/utils.ts b/modules/sdk-coin-vet/src/lib/utils.ts index 01310b5f73..71e989485e 100644 --- a/modules/sdk-coin-vet/src/lib/utils.ts +++ b/modules/sdk-coin-vet/src/lib/utils.ts @@ -194,7 +194,7 @@ export class Utils implements BaseUtils { return { tokenId: String(decoded[0]), - validator: String(decoded[1]), + validator: addHexPrefix(decoded[1].toString()).toLowerCase(), }; } catch (error) { throw new Error(`Failed to decode delegation data: ${error.message}`); diff --git a/modules/sdk-coin-vet/test/resources/vet.ts b/modules/sdk-coin-vet/test/resources/vet.ts index 812065b6c5..39325cd256 100644 --- a/modules/sdk-coin-vet/test/resources/vet.ts +++ b/modules/sdk-coin-vet/test/resources/vet.ts @@ -215,3 +215,14 @@ export const SERIALIZED_SIGNED_FLUSH_TOKEN_TX = export const VALID_NFT_CONTRACT_DATA = '0x23b872dd0000000000000000000000007ca00e3bc8a836026c2917c6c7c6d049e52099dd000000000000000000000000e59f1cea4e0fef511e3d0f4eec44adf19c4cbeec00000000000000000000000000000000000000000000000000000000000004d2'; + +export const DELEGATE_CLAUSE_DATA = + '0x08bbb8240000000000000000000000000000000000000000000000000000000000003d45000000000000000000000000ae99cb89767a09d53e589a40cb4016974aba4b94'; +export const DELEGATE_TOKEN_ID = '15685'; +export const DELEGATE_VALIDATOR = '0xae99cb89767a09d53e589a40cb4016974aba4b94'; + +export const SIGNED_DELEGATE_RAW_HEX = + '0xf8fa278801671187de8af70440f85ef85c941e02b2953adefec225cf0ec49805b1146a4429c180b84408bbb8240000000000000000000000000000000000000000000000000000000000003d2d00000000000000000000000000563ec3cafbbe7e60b04b3190e6eca66579706d818082cb5680820190c101b882313e783169eae670b1210e65f59b7c30cfd6c140c377257413fef378f70549f738a22a172ccc4ac7854ebc9952845fa90f7a676e5e9d9e277724ef3968e32e8a00f05ddf913b2b8fb884dbd5d5133217666ec4a68d077dce1537d270f25caf440e0f11232ecc4a5859ab49b2442cc0b0c0c1488302556e6323eec0498f1a42e17301'; +export const SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID = '15661'; +export const SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR = '0x00563ec3cafbbe7e60b04b3190e6eca66579706d'; +export const SIGNED_DELEGATE_RAW_EXPECTED_STAKING_CONTRACT = '0x1e02b2953adefec225cf0ec49805b1146a4429c1'; diff --git a/modules/sdk-coin-vet/test/transactionBuilder/delegateClauseTxnBuilder.ts b/modules/sdk-coin-vet/test/transactionBuilder/delegateClauseTxnBuilder.ts index 5816cc7b7b..703ac21751 100644 --- a/modules/sdk-coin-vet/test/transactionBuilder/delegateClauseTxnBuilder.ts +++ b/modules/sdk-coin-vet/test/transactionBuilder/delegateClauseTxnBuilder.ts @@ -5,6 +5,7 @@ import { DELEGATE_CLAUSE_METHOD_ID, STARGATE_CONTRACT_ADDRESS_TESTNET } from '.. import EthereumAbi from 'ethereumjs-abi'; import * as testData from '../resources/vet'; import { BN } from 'ethereumjs-util'; +import utils from '../../src/lib/utils'; describe('VET Delegation Transaction', function () { const factory = new TransactionBuilderFactory(coins.get('tvet')); @@ -166,7 +167,35 @@ describe('VET Delegation Transaction', function () { toJson.expiration.should.equal(64); toJson.chainTag.should.equal(39); toJson.tokenId?.should.equal(tokenIdForDelegateTxn); - toJson.validatorAddress?.should.equal('00563ec3cafbbe7e60b04b3190e6eca66579706d'); + toJson.validatorAddress?.should.equal('0x00563ec3cafbbe7e60b04b3190e6eca66579706d'); + }); + }); + + describe('decodeDelegateClauseData', function () { + it('should correctly decode delegate transaction data with proper address formatting', function () { + const decodedData = utils.decodeDelegateClauseData(testData.DELEGATE_CLAUSE_DATA); + + decodedData.tokenId.should.equal(testData.DELEGATE_TOKEN_ID); + decodedData.validator.should.equal(testData.DELEGATE_VALIDATOR); + decodedData.validator.should.startWith('0x'); + decodedData.validator.should.equal(decodedData.validator.toLowerCase()); + }); + + it('should correctly deserialize real signed delegate transaction from raw hex', async function () { + const txBuilder = factory.from(testData.SIGNED_DELEGATE_RAW_HEX); + const tx = txBuilder.transaction as DelegateClauseTransaction; + tx.should.be.instanceof(DelegateClauseTransaction); + tx.stakingContractAddress.should.equal(testData.SIGNED_DELEGATE_RAW_EXPECTED_STAKING_CONTRACT); + tx.tokenId.should.equal(testData.SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID); + tx.validator.should.equal(testData.SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR); + tx.validator.should.startWith('0x'); + tx.validator.should.equal(tx.validator.toLowerCase()); + should.exist(tx.inputs); + tx.inputs.length.should.equal(1); + + const decodedData = utils.decodeDelegateClauseData(tx.clauses[0].data); + decodedData.tokenId.should.equal(testData.SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID); + decodedData.validator.should.equal(testData.SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR); }); }); });