Skip to content

Commit 42bb1c7

Browse files
committed
fix(tx-construction): use output address size as minimum coin computation param
OutputValidator.validateOutput used a stub shelley address, which computed an invalid minimum coin quantity for outputs to Byron address that are larger in bytes, therefore actually requiring more coins than computed
1 parent 920c642 commit 42bb1c7

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

packages/tx-construction/src/output-validation/outputValidator.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ import { computeMinimumCoinQuantity, tokenBundleSizeExceedsLimit } from '../inpu
1212
export const createOutputValidator = ({
1313
protocolParameters: protocolParametersGetter
1414
}: OutputValidatorContext): OutputValidator => {
15-
const validateValue = async (
16-
value: Cardano.Value,
15+
const validateOutput = async (
16+
{ address, value }: Cardano.TxOut,
1717
protocolParameters?: ProtocolParametersRequiredByOutputValidator
18-
): Promise<OutputValidation> => {
18+
) => {
1919
const { coinsPerUtxoByte, maxValueSize } = protocolParameters || (await protocolParametersGetter());
20-
const stubMaxSizeAddress = Cardano.PaymentAddress(
21-
'addr_test1qqydn46r6mhge0kfpqmt36m6q43knzsd9ga32n96m89px3nuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qypp3m9'
22-
);
23-
const stubTxOut: Cardano.TxOut = { address: stubMaxSizeAddress, value };
20+
const stubTxOut: Cardano.TxOut = { address, value };
2421
const negativeAssetQty = value.assets ? [...value.assets.values()].some((qty) => qty <= 0) : false;
2522
if (negativeAssetQty) {
2623
// return early, otherwise 'minimumCoin/maxValueSize' will fail with error: "ParseIntError { kind: InvalidDigit }"
@@ -39,10 +36,6 @@ export const createOutputValidator = ({
3936
tokenBundleSizeExceedsLimit: tokenBundleSizeExceedsLimit(maxValueSize)(value.assets)
4037
};
4138
};
42-
const validateOutput = async (
43-
output: Cardano.TxOut,
44-
protocolParameters?: ProtocolParametersRequiredByOutputValidator
45-
) => validateValue(output.value, protocolParameters);
4639

4740
return {
4841
validateOutput,

packages/tx-construction/test/output-validation/outputValidator.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,22 @@ describe('createOutputValidator', () => {
9696
).negativeAssetQty
9797
).toBe(true);
9898
});
99+
100+
it('uses output address size as minimum coin computation parameter', async () => {
101+
const value: Cardano.Value = { coins: 123n };
102+
const { minimumCoin: byronAddressMinimumCoin } = await validator.validateOutput({
103+
address: Cardano.PaymentAddress(
104+
'DdzFFzCqrht4PWfBGtmrQz4x1GkZHYLVGbK7aaBkjWxujxzz3L5GxCgPiTsks5RjUr3yX9KvwKjNJBt7ZzPCmS3fUQrGeRvo9Y1YBQKQ'
105+
),
106+
value
107+
});
108+
const { minimumCoin: shelleyAddressMinimumCoin } = await validator.validateOutput({
109+
address: Cardano.PaymentAddress(
110+
'addr_test1qqydn46r6mhge0kfpqmt36m6q43knzsd9ga32n96m89px3nuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qypp3m9'
111+
),
112+
value
113+
});
114+
expect(byronAddressMinimumCoin).toBeGreaterThan(shelleyAddressMinimumCoin);
115+
});
99116
});
100117
});

0 commit comments

Comments
 (0)