Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/utils/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export const StellarUtils = {
? Networks.FUTURENET
: Networks.TESTNET;

const asset = assetCode === 'XLM' ? Asset.native() : new Asset(assetCode, issuer as string);
if (assetCode !== 'XLM' && (!issuer || !ValidationUtils.isValidStellarAddress(issuer))) {
throw new Error(`A valid issuer is required for non-native asset payments: ${assetCode}`);
}

const asset = assetCode === 'XLM' ? Asset.native() : new Asset(assetCode, issuer);

// We use a dummy sequence number because the actual submission will be handled later
// or by a signer that manages sequence numbers.
Expand Down
25 changes: 25 additions & 0 deletions tests/utils/stellar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ describe('StellarUtils', () => {
expect(parseFloat(operation.amount)).toBe(parseFloat(params.amount));
});

it('should throw a clear error when a non-native asset issuer is missing', async () => {
await expect(
StellarUtils.buildPaymentXdr({
source: validAccountId,
destination: validAccountId,
amount: '1.5',
assetCode: 'USDC',
network: 'testnet',
}),
).rejects.toThrow('A valid issuer is required for non-native asset payments: USDC');
});

it('should throw a clear error when a non-native asset issuer is invalid', async () => {
await expect(
StellarUtils.buildPaymentXdr({
source: validAccountId,
destination: validAccountId,
amount: '1.5',
assetCode: 'USDC',
issuer: invalidAccountId,
network: 'testnet',
}),
).rejects.toThrow('A valid issuer is required for non-native asset payments: USDC');
});

it('should throw when parsing invalid XDR', () => {
expect(() => StellarUtils.parseXdrTransaction('invalid-xdr')).toThrow(/Failed to parse XDR/);
});
Expand Down
Loading