Skip to content
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
4 changes: 0 additions & 4 deletions modules/sdk-coin-iota/src/lib/transferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () {
Expand Down