Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/sdk-coin-vet/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
11 changes: 11 additions & 0 deletions modules/sdk-coin-vet/test/resources/vet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
});
});
});