Skip to content

Commit 5d51345

Browse files
authored
Merge pull request #7196 from BitGo/SC-3398
fix: load inputs for unstake txns
2 parents d8dc2a5 + a1413f9 commit 5d51345

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

modules/sdk-coin-vet/src/lib/transaction/burnNftTransaction.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export class BurnNftTransaction extends Transaction {
4747
data: this._transactionData || this.getBurnNftData(),
4848
},
4949
];
50+
51+
this._recipients = [
52+
{
53+
address: this._contract,
54+
amount: '0',
55+
},
56+
];
5057
}
5158

5259
/**
@@ -115,12 +122,13 @@ export class BurnNftTransaction extends Transaction {
115122
if (this.transactionData.startsWith(BURN_NFT_METHOD_ID)) {
116123
this.tokenId = utils.decodeBurnNftData(this.transactionData);
117124
}
118-
119125
// Set sender address
120126
if (signedTx.signature && signedTx.origin) {
121127
this.sender = signedTx.origin.toString().toLowerCase();
122128
}
123129

130+
this.loadInputsAndOutputs();
131+
124132
// Set signatures if present
125133
if (signedTx.signature) {
126134
// First signature is sender's signature

modules/sdk-coin-vet/src/lib/transaction/exitDelegation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EXIT_DELEGATION_METHOD_ID } from '../constants';
77
import EthereumAbi from 'ethereumjs-abi';
88
import { addHexPrefix } from 'ethereumjs-util';
99
import utils from '../utils';
10+
import BigNumber from 'bignumber.js';
1011

1112
export class ExitDelegationTransaction extends Transaction {
1213
private _tokenId: string;
@@ -47,6 +48,13 @@ export class ExitDelegationTransaction extends Transaction {
4748
data: this._transactionData || this.getExitDelegationData(),
4849
},
4950
];
51+
52+
this._recipients = [
53+
{
54+
address: this._contract,
55+
amount: '0',
56+
},
57+
];
5058
}
5159

5260
/**
@@ -115,12 +123,18 @@ export class ExitDelegationTransaction extends Transaction {
115123
if (this.transactionData.startsWith(EXIT_DELEGATION_METHOD_ID)) {
116124
this.tokenId = utils.decodeExitDelegationData(this.transactionData);
117125
}
126+
this.recipients = body.clauses.map((clause) => ({
127+
address: (clause.to || '0x0').toString().toLowerCase(),
128+
amount: new BigNumber(clause.value || 0).toString(),
129+
}));
118130

119131
// Set sender address
120132
if (signedTx.signature && signedTx.origin) {
121133
this.sender = signedTx.origin.toString().toLowerCase();
122134
}
123135

136+
this.loadInputsAndOutputs();
137+
124138
// Set signatures if present
125139
if (signedTx.signature) {
126140
// First signature is sender's signature

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,27 @@ describe('Vet Burn NFT Transaction', () => {
3333
should.equal(tx.expiration, 64);
3434
should.equal(tx.type, TransactionType.StakingWithdraw);
3535

36-
// Verify the transaction data contains the correct method ID
36+
// Verify the transaction data contains the correct method ID and tokenId
3737
tx.clauses[0].data.should.startWith(BURN_NFT_METHOD_ID);
3838

3939
// Verify the transaction has the correct structure
4040
tx.clauses.length.should.equal(1);
41-
should.equal(tx.clauses[0].to, STARGATE_NFT_ADDRESS_TESTNET);
42-
should.equal(tx.clauses[0].value, '0x0');
41+
should.exist(tx.clauses[0]);
42+
should.exist(tx.clauses[0].to);
43+
tx.clauses[0]?.to?.should.equal(STARGATE_NFT_ADDRESS_TESTNET);
44+
should.exist(tx.clauses[0].value);
45+
tx.clauses[0].value.should.equal('0x0');
46+
47+
tx.inputs.length.should.equal(1);
48+
tx.outputs.length.should.equal(1);
49+
50+
should.equal(tx.inputs[0].address, testData.addresses.validAddresses[0]);
51+
should.equal(tx.inputs[0].value, '0');
52+
should.equal(tx.inputs[0].coin, 'tvet');
53+
54+
should.equal(tx.outputs[0].address, STARGATE_NFT_ADDRESS_TESTNET);
55+
should.equal(tx.outputs[0].value, '0');
56+
should.equal(tx.outputs[0].coin, 'tvet');
4357
});
4458

4559
it('should build a burn NFT transaction with custom contract address', async function () {
@@ -59,7 +73,9 @@ describe('Vet Burn NFT Transaction', () => {
5973
const tx = (await txBuilder.build()) as BurnNftTransaction;
6074

6175
should.equal(tx.contract, customContractAddress);
62-
should.equal(tx.clauses[0].to, customContractAddress);
76+
should.exist(tx.clauses[0]);
77+
should.exist(tx.clauses[0].to);
78+
tx.clauses[0]?.to?.should.equal(customContractAddress);
6379
});
6480

6581
it('should deserialize and reserialize a signed burn NFT transaction', async function () {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ describe('Vet Exit Delegation Transaction', () => {
4343
tx.clauses[0]?.to?.should.equal(STARGATE_DELEGATION_ADDRESS_TESTNET);
4444
should.exist(tx.clauses[0].value);
4545
tx.clauses[0].value.should.equal('0x0');
46+
47+
tx.inputs.length.should.equal(1);
48+
tx.outputs.length.should.equal(1);
49+
50+
should.equal(tx.inputs[0].address, testData.addresses.validAddresses[0]);
51+
should.equal(tx.inputs[0].value, '0');
52+
should.equal(tx.inputs[0].coin, 'tvet');
53+
54+
should.equal(tx.outputs[0].address, STARGATE_DELEGATION_ADDRESS_TESTNET);
55+
should.equal(tx.outputs[0].value, '0');
56+
should.equal(tx.outputs[0].coin, 'tvet');
4657
});
4758

4859
it('should build an exit delegation transaction with custom contract address', async function () {

0 commit comments

Comments
 (0)