Skip to content

Commit 89f2a4c

Browse files
authored
test: non-utxo input handle (#34)
* test: non-utxo input handle * fix: handle non-utxo inputs
1 parent 50e42dd commit 89f2a4c

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

packages/sdk/src/mintlayer-connect-sdk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,10 @@ class Client {
24492449
})) : [];
24502450

24512451
const utxos: UtxoEntry[] = data_utxos.filter((item: UtxoEntry) => {
2452+
if (!item.utxo) {
2453+
return false;
2454+
}
2455+
24522456
// filter out UTXO with type htlc, they have to be added manually
24532457
if (item.utxo.type === 'Htlc') {
24542458
return false;

packages/sdk/tests/transfer.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,40 @@ test('fails transfer if not enough utxo', async () => {
164164
})).rejects.toThrow('Not enough coin UTXOs');
165165
});
166166

167+
test('transfer ignores account entries without utxo', async () => {
168+
fetchMock.mockIf('https://mojito-api.mintlayer.org/mintlayer/testnet/batch', async () => {
169+
return {
170+
body: JSON.stringify({
171+
results: [[
172+
{
173+
input: {
174+
input_type: 'Account',
175+
account_type: 'DelegationBalance',
176+
amount: {
177+
atoms: '100000000000',
178+
decimal: '1',
179+
},
180+
delegation_id: 'tde1q9gndm5e2d6w33xtm26gppaj29qh52gnxwucnqlq',
181+
nonce: 1,
182+
},
183+
},
184+
...utxos,
185+
]],
186+
}),
187+
};
188+
});
189+
190+
const client = await Client.create({ network: 'testnet', autoRestore: false });
191+
await client.connect();
192+
193+
const result = await client.transfer({
194+
to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc',
195+
amount: 10,
196+
});
197+
198+
expect(result).toBe('signed-transaction');
199+
});
200+
167201
test('transfer transfer fee precise', async () => {
168202
const client = await Client.create({ network: 'testnet', autoRestore: false });
169203

0 commit comments

Comments
 (0)