Skip to content

Commit 871ed17

Browse files
Merge pull request #7704 from BitGo/WIN-8152
fix(sdk-coin-iota): update tx builder validation
2 parents a395d9a + db3402a commit 871ed17

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

modules/sdk-coin-iota/src/lib/transferBuilder.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ export class TransferBuilder extends TransactionBuilder {
3333
* These are the source coins that will be split and transferred to recipients.
3434
* @param paymentObjects - Array of IOTA coin objects to use for payment
3535
* @returns This builder for method chaining
36-
* @throws BuildTransactionError if payment objects array is empty
3736
*/
3837
paymentObjects(paymentObjects: TransactionObjectInput[]): this {
39-
if (paymentObjects.length === 0) {
40-
throw new BuildTransactionError('No Objects provided for payment');
41-
}
4238
this.transferTransaction.paymentObjects = paymentObjects;
4339
return this;
4440
}

modules/sdk-coin-iota/test/unit/transactionBuilder/transferBuilder.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,33 @@ describe('Iota Transfer Builder', () => {
298298
should.equal(tx.type, TransactionType.Send);
299299
tx.paymentObjects?.length.should.equal(2);
300300
});
301+
302+
it('should accept empty payment objects array and use gas objects for payment in non-sponsor mode', async function () {
303+
const builder = factory
304+
.getTransferBuilder()
305+
.sender(testData.sender.address)
306+
.recipients(testData.recipients)
307+
.paymentObjects([])
308+
.gasData(testData.gasData);
309+
310+
const tx = (await builder.build()) as TransferTransaction;
311+
should.equal(tx.type, TransactionType.Send);
312+
should.equal(tx.isSimulateTx, false);
313+
should.equal(tx.sender, testData.sender.address);
314+
await assertValidRawTransaction(tx);
315+
});
316+
317+
it('should fail tx building in case of empty payment objects in sponsor mode', async function () {
318+
const builder = factory
319+
.getTransferBuilder()
320+
.sender(testData.sender.address)
321+
.gasSponsor(testData.gasSponsor.address)
322+
.recipients(testData.recipients)
323+
.paymentObjects([])
324+
.gasData(testData.gasData);
325+
326+
await builder.build().should.be.rejectedWith(/Payment objects are required when using a gas sponsor/);
327+
});
301328
});
302329

303330
describe('Validation Errors', () => {
@@ -380,9 +407,9 @@ describe('Iota Transfer Builder', () => {
380407
await builder.build().should.be.rejected();
381408
});
382409

383-
it('should fail for empty payment objects', function () {
410+
it('should allow empty payment objects', function () {
384411
const builder = createBasicTransferBuilder();
385-
should(() => builder.paymentObjects([])).throwError('No Objects provided for payment');
412+
should.doesNotThrow(() => builder.paymentObjects([]));
386413
});
387414

388415
it('should fail without payment objects when using gas sponsor', async function () {

0 commit comments

Comments
 (0)