Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-coin-avaxp): stake output cannot be 0 #4418

Merged
merged 1 commit into from
Apr 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class PermissionlessValidatorTxBuilder extends TransactionBuilder {
);
stakeOutputs.push(stakeOutput);

if (currentTotal >= totalTarget) {
if (currentTotal > totalTarget) {
const changeOutput = new avaxSerial.TransferableOutput(
assetId,
new TransferOutput(
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-avaxp/test/resources/avaxp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ export const BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE = {
startTime: '1656423398',
endTime: '1659053398',
stakeAmount: '2370000000',
stakeAmountNoOutput: '4097000000',
delegationFeeRate: 10,
nodeId: 'NodeID-2hMqBQdjZMWdHvYu7ZPLA2CmrAdbTvpGf',
blsPublicKey: '0xad9e9476b701edec88e53b1c314456053b3cf846a1192117872e41455f440c074d6ee89530d45e88f79ac0eda06f2887',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,30 @@ describe('AvaxP permissionlessValidatorTxBuilder', () => {
console.log(fullSignedTx.toJson());
});
});
it('Should fail to build if utxos change output 0', async () => {
const unixNow = BigInt(Math.round(new Date().getTime() / 1000));
const startTime = unixNow + BigInt(60);
const endTime = startTime + BigInt(60 * 60 * 24 + 600);

const txBuilder = new AvaxpLib.TransactionBuilderFactory(coins.get('tavaxp'))
.getPermissionlessValidatorTxBuilder()
.threshold(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.threshold)
.locktime(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.locktime)
.recoverMode(false)
.fromPubKey(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.bitgoAddresses)
.startTime(startTime.toString())
.endTime(endTime.toString())
.stakeAmount(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.stakeAmountNoOutput)
.delegationFeeRate(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.delegationFeeRate)
.nodeID(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.nodeId)
.blsPublicKey(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.blsPublicKey)
.blsSignature(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.blsSignature)
.utxos(testData.BUILD_AND_SIGN_ADD_PERMISSIONLESS_VALIDATOR_SAMPLE.utxos);
const tx = await txBuilder.build();
const txJson = tx.toJson();
const txExplain = tx.explainTransaction();
txJson.changeOutputs.length.should.equal(0);
txExplain.changeOutputs.length.should.equal(0);
txExplain.changeAmount.should.equal('0');
});
});
Loading