Skip to content

Commit b13c88f

Browse files
authored
fix: deriveTransactionType defaults to CustomTx for non-transfer transactions
2 parents e22b1f8 + 23d8629 commit b13c88f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

modules/sdk-coin-sol/src/lib/explainTransactionWasm.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function deriveTransactionType(
112112
// Unknown instructions indicate a custom/unrecognized transaction
113113
if (instructions.some((i) => i.type === 'Unknown')) return TransactionType.CustomTx;
114114

115-
return TransactionType.Send;
115+
// Send requires an explicit Transfer or TokenTransfer instruction.
116+
// Everything else is a custom/unrecognized transaction.
117+
if (instructions.some((i) => i.type === 'Transfer' || i.type === 'TokenTransfer')) return TransactionType.Send;
118+
119+
return TransactionType.CustomTx;
116120
}
117121

118122
// =============================================================================
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Tests for explainTransactionWasm (WASM-based Solana transaction explanation).
3+
*/
4+
import 'should';
5+
import { explainSolTransaction } from '../../src/lib/explainTransactionWasm';
6+
7+
describe('explainTransactionWasm', function () {
8+
describe('deriveTransactionType', function () {
9+
it('should classify boilerplate-only transaction as CustomTx', function () {
10+
// Transaction with only NonceAdvance + Memo instructions (no Transfer or TokenTransfer).
11+
// Previously this would incorrectly fall through to 'Send'.
12+
const BOILERPLATE_ONLY_TX_BASE64 =
13+
'AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADE3aDK9nmEccOmQJ4crZzPuTnRVa3woFSjKzE2hcsFbNkpvA8Lnj7CVeJ+/UfXwLI5g223D02m4+REUfPc50QCAgEEB8OpoX+Ybq/j8xi80DhFtj8AUVHPrjhK1E3DnT5Bmx346iUtYQKMMBolIAO6PmfJh3w7huFcYcGNOB8sgXN38Wg6ZrWANNJfb64q8B242qfRiT7dffb80H2OoXGQ0aq0lAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABUpTWpkpIQZNJOhxYNo4fHw1td28kruB5B+oQEEFRI0Gp9UXGMd0yShWY5hpHV62i164o5tLbVxzVVshAAAAAAan1RcZLFaO4IqEX3PSl4jPA1wxRbIas0TYBi6pQAAAEHPqtGYOjjqVfHgg1S32M4qMe2AQO/kDy1+CEYQwkisDAwMCBgEEBAAAAAQCAAUJSGVsbG8gQVBJBAAnQVBJIEludGVncmF0aW9uIHRlc3QgY3VzdG9tIHRyYW5zYWN0aW9u';
14+
15+
const explained = explainSolTransaction({
16+
txBase64: BOILERPLATE_ONLY_TX_BASE64,
17+
feeInfo: { fee: '5000' },
18+
coinName: 'tsol',
19+
});
20+
21+
explained.type.should.equal('CustomTx');
22+
explained.outputAmount.should.equal('0');
23+
explained.outputs.length.should.equal(0);
24+
(typeof explained.memo).should.equal('string');
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)