diff --git a/modules/sdk-coin-iota/src/lib/transferBuilder.ts b/modules/sdk-coin-iota/src/lib/transferBuilder.ts index e99d6f6719..a1cb4edbcc 100644 --- a/modules/sdk-coin-iota/src/lib/transferBuilder.ts +++ b/modules/sdk-coin-iota/src/lib/transferBuilder.ts @@ -33,12 +33,8 @@ export class TransferBuilder extends TransactionBuilder { * These are the source coins that will be split and transferred to recipients. * @param paymentObjects - Array of IOTA coin objects to use for payment * @returns This builder for method chaining - * @throws BuildTransactionError if payment objects array is empty */ paymentObjects(paymentObjects: TransactionObjectInput[]): this { - if (paymentObjects.length === 0) { - throw new BuildTransactionError('No Objects provided for payment'); - } this.transferTransaction.paymentObjects = paymentObjects; return this; } diff --git a/modules/sdk-coin-iota/test/unit/transactionBuilder/transferBuilder.ts b/modules/sdk-coin-iota/test/unit/transactionBuilder/transferBuilder.ts index 75f36b6946..7a2c5c9485 100644 --- a/modules/sdk-coin-iota/test/unit/transactionBuilder/transferBuilder.ts +++ b/modules/sdk-coin-iota/test/unit/transactionBuilder/transferBuilder.ts @@ -298,6 +298,33 @@ describe('Iota Transfer Builder', () => { should.equal(tx.type, TransactionType.Send); tx.paymentObjects?.length.should.equal(2); }); + + it('should accept empty payment objects array and use gas objects for payment in non-sponsor mode', async function () { + const builder = factory + .getTransferBuilder() + .sender(testData.sender.address) + .recipients(testData.recipients) + .paymentObjects([]) + .gasData(testData.gasData); + + const tx = (await builder.build()) as TransferTransaction; + should.equal(tx.type, TransactionType.Send); + should.equal(tx.isSimulateTx, false); + should.equal(tx.sender, testData.sender.address); + await assertValidRawTransaction(tx); + }); + + it('should fail tx building in case of empty payment objects in sponsor mode', async function () { + const builder = factory + .getTransferBuilder() + .sender(testData.sender.address) + .gasSponsor(testData.gasSponsor.address) + .recipients(testData.recipients) + .paymentObjects([]) + .gasData(testData.gasData); + + await builder.build().should.be.rejectedWith(/Payment objects are required when using a gas sponsor/); + }); }); describe('Validation Errors', () => { @@ -380,9 +407,9 @@ describe('Iota Transfer Builder', () => { await builder.build().should.be.rejected(); }); - it('should fail for empty payment objects', function () { + it('should allow empty payment objects', function () { const builder = createBasicTransferBuilder(); - should(() => builder.paymentObjects([])).throwError('No Objects provided for payment'); + should.doesNotThrow(() => builder.paymentObjects([])); }); it('should fail without payment objects when using gas sponsor', async function () {