Skip to content

Commit 5180ad0

Browse files
authored
Merge pull request #7723 from BitGo/SC-4444
fix(sdk-coin-vet): add prefix for validator address
2 parents 7c3fc05 + dc17da1 commit 5180ad0

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

modules/sdk-coin-vet/src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class Utils implements BaseUtils {
194194

195195
return {
196196
tokenId: String(decoded[0]),
197-
validator: String(decoded[1]),
197+
validator: addHexPrefix(decoded[1].toString()).toLowerCase(),
198198
};
199199
} catch (error) {
200200
throw new Error(`Failed to decode delegation data: ${error.message}`);

modules/sdk-coin-vet/test/resources/vet.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,14 @@ export const SERIALIZED_SIGNED_FLUSH_TOKEN_TX =
215215

216216
export const VALID_NFT_CONTRACT_DATA =
217217
'0x23b872dd0000000000000000000000007ca00e3bc8a836026c2917c6c7c6d049e52099dd000000000000000000000000e59f1cea4e0fef511e3d0f4eec44adf19c4cbeec00000000000000000000000000000000000000000000000000000000000004d2';
218+
219+
export const DELEGATE_CLAUSE_DATA =
220+
'0x08bbb8240000000000000000000000000000000000000000000000000000000000003d45000000000000000000000000ae99cb89767a09d53e589a40cb4016974aba4b94';
221+
export const DELEGATE_TOKEN_ID = '15685';
222+
export const DELEGATE_VALIDATOR = '0xae99cb89767a09d53e589a40cb4016974aba4b94';
223+
224+
export const SIGNED_DELEGATE_RAW_HEX =
225+
'0xf8fa278801671187de8af70440f85ef85c941e02b2953adefec225cf0ec49805b1146a4429c180b84408bbb8240000000000000000000000000000000000000000000000000000000000003d2d00000000000000000000000000563ec3cafbbe7e60b04b3190e6eca66579706d818082cb5680820190c101b882313e783169eae670b1210e65f59b7c30cfd6c140c377257413fef378f70549f738a22a172ccc4ac7854ebc9952845fa90f7a676e5e9d9e277724ef3968e32e8a00f05ddf913b2b8fb884dbd5d5133217666ec4a68d077dce1537d270f25caf440e0f11232ecc4a5859ab49b2442cc0b0c0c1488302556e6323eec0498f1a42e17301';
226+
export const SIGNED_DELEGATE_RAW_EXPECTED_TOKEN_ID = '15661';
227+
export const SIGNED_DELEGATE_RAW_EXPECTED_VALIDATOR = '0x00563ec3cafbbe7e60b04b3190e6eca66579706d';
228+
export const SIGNED_DELEGATE_RAW_EXPECTED_STAKING_CONTRACT = '0x1e02b2953adefec225cf0ec49805b1146a4429c1';

modules/sdk-coin-vet/test/transactionBuilder/delegateClauseTxnBuilder.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DELEGATE_CLAUSE_METHOD_ID, STARGATE_CONTRACT_ADDRESS_TESTNET } from '..
55
import EthereumAbi from 'ethereumjs-abi';
66
import * as testData from '../resources/vet';
77
import { BN } from 'ethereumjs-util';
8+
import utils from '../../src/lib/utils';
89

910
describe('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

Comments
 (0)