Skip to content

Commit

Permalink
Don't sponsor own transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed Jul 22, 2023
1 parent ac2a8d6 commit 1d5ea57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lto-did-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class LtoDIDProvider extends AbstractIdentifierProvider {

private async broadcast(...tsx: Transaction[]): Promise<Transaction[]> {
if (this.sponsor) {
tsx.forEach((tx) => tx.sponsorWith(this.sponsor));
tsx.forEach((tx) => tx.sender !== this.sponsor.address && tx.sponsorWith(this.sponsor));
}

return Promise.all(tsx.map((tx) => this.lto.node.broadcast(tx)));
Expand Down
14 changes: 14 additions & 0 deletions test/lto-did-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ describe('LtoDIDProvider', () => {
expect(tx.sponsor).to.eq(sponsor.address);
}
});

it('should sponsor tx when the signer is the sponsor', async () => {
ltoDIDProvider = new LtoDIDProvider({
defaultKms: 'kms',
lto: lto,
sponsor: { seed: 'test' },
});

const txs = await ltoDIDProvider.removeService({ identifier, id: '#test' }, context);

for (const tx of txs) {
expect(tx.sponsor).to.be.undefined;
}
});
});

describe('using builder', () => {
Expand Down

0 comments on commit 1d5ea57

Please sign in to comment.