@solana/kora 0.2.0 → 0.3.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/client.d.ts +201 -7
- package/dist/src/client.js +223 -18
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/kit/executor.js +18 -5
- package/dist/src/kit/index.d.ts +4 -1
- package/dist/src/kit/index.js +10 -2
- package/dist/src/kit/payment.js +3 -2
- package/dist/src/plugin.d.ts +85 -0
- package/dist/src/{kit/plugin.js → plugin.js} +88 -18
- package/dist/src/types/index.d.ts +173 -78
- package/dist/test/auth-setup.js +4 -4
- package/dist/test/integration.test.js +168 -291
- package/dist/test/kit-client.test.js +18 -0
- package/dist/test/plugin.test.js +126 -71
- package/dist/test/setup.d.ts +8 -15
- package/dist/test/setup.js +52 -152
- package/dist/test/unit.test.js +318 -166
- package/package.json +8 -16
- package/dist/src/kit/plugin.d.ts +0 -31
|
@@ -1,15 +1,60 @@
|
|
|
1
|
+
import { address, appendTransactionMessageInstruction, compileTransaction, createTransactionMessage, getBase64Decoder, getBase64EncodedWireTransaction, getBase64Encoder, getTransactionDecoder, getTransactionEncoder, partiallySignTransaction, pipe, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, } from '@solana/kit';
|
|
2
|
+
import { getTransferSolInstruction } from '@solana-program/system';
|
|
3
|
+
import { findAssociatedTokenPda, getTransferInstruction, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
1
4
|
import { createKitKoraClient } from '../src/index.js';
|
|
2
|
-
import setupTestSuite from './setup.js';
|
|
3
5
|
import { runAuthenticationTests } from './auth-setup.js';
|
|
4
|
-
import
|
|
5
|
-
import { getTransferSolInstruction } from '@solana-program/system';
|
|
6
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, findAssociatedTokenPda, parseTransferInstruction, TOKEN_PROGRAM_ADDRESS, tokenProgram, TRANSFER_DISCRIMINATOR, } from '@solana-program/token';
|
|
6
|
+
import setupTestSuite from './setup.js';
|
|
7
7
|
function transactionFromBase64(base64) {
|
|
8
8
|
const encoder = getBase64Encoder();
|
|
9
9
|
const decoder = getTransactionDecoder();
|
|
10
10
|
const messageBytes = encoder.encode(base64);
|
|
11
11
|
return decoder.decode(messageBytes);
|
|
12
12
|
}
|
|
13
|
+
function transactionToBase64(transaction) {
|
|
14
|
+
const txEncoder = getTransactionEncoder();
|
|
15
|
+
const txBytes = txEncoder.encode(transaction);
|
|
16
|
+
const base64Decoder = getBase64Decoder();
|
|
17
|
+
return base64Decoder.decode(txBytes);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Helper to build a SPL token transfer transaction.
|
|
21
|
+
* This replaces the deprecated transferTransaction endpoint.
|
|
22
|
+
*/
|
|
23
|
+
async function buildTokenTransferTransaction(params) {
|
|
24
|
+
const { client, amount, mint, sourceWallet, destinationWallet } = params;
|
|
25
|
+
// Get the payer signer from Kora (fee payer)
|
|
26
|
+
const { signer_address } = await client.getPayerSigner();
|
|
27
|
+
// Get blockhash
|
|
28
|
+
const { blockhash } = await client.getBlockhash();
|
|
29
|
+
// Find source and destination ATAs
|
|
30
|
+
const [sourceAta] = await findAssociatedTokenPda({
|
|
31
|
+
mint,
|
|
32
|
+
owner: sourceWallet.address,
|
|
33
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
34
|
+
});
|
|
35
|
+
const [destinationAta] = await findAssociatedTokenPda({
|
|
36
|
+
mint,
|
|
37
|
+
owner: destinationWallet,
|
|
38
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
39
|
+
});
|
|
40
|
+
// Build transfer instruction
|
|
41
|
+
const transferIx = getTransferInstruction({
|
|
42
|
+
amount,
|
|
43
|
+
authority: sourceWallet,
|
|
44
|
+
destination: destinationAta,
|
|
45
|
+
source: sourceAta,
|
|
46
|
+
});
|
|
47
|
+
// Build transaction message with Kora as fee payer
|
|
48
|
+
// We create a mock signer for the fee payer address since we only need the address
|
|
49
|
+
const feePayerSigner = {
|
|
50
|
+
address: signer_address,
|
|
51
|
+
};
|
|
52
|
+
const transactionMessage = pipe(createTransactionMessage({ version: 0 }), tx => setTransactionMessageFeePayerSigner(feePayerSigner, tx), tx => setTransactionMessageLifetimeUsingBlockhash({ blockhash: blockhash, lastValidBlockHeight: BigInt(Number.MAX_SAFE_INTEGER) }, tx), tx => appendTransactionMessageInstruction(transferIx, tx));
|
|
53
|
+
// Compile to transaction
|
|
54
|
+
const transaction = compileTransaction(transactionMessage);
|
|
55
|
+
const base64Transaction = getBase64EncodedWireTransaction(transaction);
|
|
56
|
+
return { blockhash: blockhash, transaction: base64Transaction };
|
|
57
|
+
}
|
|
13
58
|
const AUTH_ENABLED = process.env.ENABLE_AUTH === 'true';
|
|
14
59
|
const FREE_PRICING = process.env.FREE_PRICING === 'true';
|
|
15
60
|
const KORA_SIGNER_TYPE = process.env.KORA_SIGNER_TYPE || 'memory';
|
|
@@ -17,21 +62,15 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
17
62
|
let client;
|
|
18
63
|
let testWallet;
|
|
19
64
|
let testWalletAddress;
|
|
20
|
-
let destinationAddress;
|
|
21
65
|
let usdcMint;
|
|
22
66
|
let koraAddress;
|
|
23
|
-
let koraRpcUrl;
|
|
24
|
-
let authConfig;
|
|
25
67
|
beforeAll(async () => {
|
|
26
68
|
const testSuite = await setupTestSuite();
|
|
27
69
|
client = testSuite.koraClient;
|
|
28
70
|
testWallet = testSuite.testWallet;
|
|
29
71
|
testWalletAddress = testWallet.address;
|
|
30
|
-
destinationAddress = testSuite.destinationAddress;
|
|
31
72
|
usdcMint = testSuite.usdcMint;
|
|
32
73
|
koraAddress = testSuite.koraAddress;
|
|
33
|
-
koraRpcUrl = testSuite.koraRpcUrl;
|
|
34
|
-
authConfig = testSuite.authConfig;
|
|
35
74
|
}, 90000); // allow adequate time for airdrops and token initialization
|
|
36
75
|
// Run authentication tests only when auth is enabled
|
|
37
76
|
if (AUTH_ENABLED) {
|
|
@@ -93,9 +132,9 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
93
132
|
expect(config.enabled_methods.get_supported_tokens).toBeDefined();
|
|
94
133
|
expect(config.enabled_methods.sign_transaction).toBeDefined();
|
|
95
134
|
expect(config.enabled_methods.sign_and_send_transaction).toBeDefined();
|
|
96
|
-
expect(config.enabled_methods.transfer_transaction).toBeDefined();
|
|
97
135
|
expect(config.enabled_methods.get_blockhash).toBeDefined();
|
|
98
136
|
expect(config.enabled_methods.get_config).toBeDefined();
|
|
137
|
+
expect(config.enabled_methods.get_version).toBeDefined();
|
|
99
138
|
});
|
|
100
139
|
it('should get payer signer', async () => {
|
|
101
140
|
const { signer_address, payment_address } = await client.getPayerSigner();
|
|
@@ -115,54 +154,25 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
115
154
|
expect(blockhash.length).toBeGreaterThanOrEqual(43);
|
|
116
155
|
expect(blockhash.length).toBeLessThanOrEqual(44); // Base58 encoded hash length
|
|
117
156
|
});
|
|
157
|
+
it('should get version', async () => {
|
|
158
|
+
const { version } = await client.getVersion();
|
|
159
|
+
expect(version).toBeDefined();
|
|
160
|
+
expect(typeof version).toBe('string');
|
|
161
|
+
expect(version.length).toBeGreaterThan(0);
|
|
162
|
+
// Version should follow semver format (e.g., "2.1.0" or "2.1.0-beta.0")
|
|
163
|
+
expect(version).toMatch(/^\d+\.\d+\.\d+/);
|
|
164
|
+
});
|
|
118
165
|
});
|
|
119
166
|
describe('Transaction Operations', () => {
|
|
120
|
-
it('should create transfer transaction', async () => {
|
|
121
|
-
const request = {
|
|
122
|
-
amount: 1000000, // 1 USDC
|
|
123
|
-
token: usdcMint,
|
|
124
|
-
source: testWalletAddress,
|
|
125
|
-
destination: destinationAddress,
|
|
126
|
-
};
|
|
127
|
-
const response = await client.transferTransaction(request);
|
|
128
|
-
expect(response).toBeDefined();
|
|
129
|
-
expect(response.transaction).toBeDefined();
|
|
130
|
-
expect(response.blockhash).toBeDefined();
|
|
131
|
-
expect(response.message).toBeDefined();
|
|
132
|
-
expect(response.instructions).toBeDefined();
|
|
133
|
-
// since setup created ATA for destination, we should not expect ata instruction, only transfer instruction
|
|
134
|
-
expect(response.instructions?.length).toBe(1);
|
|
135
|
-
expect(response.instructions?.[0].programAddress).toBe(TOKEN_PROGRAM_ADDRESS);
|
|
136
|
-
});
|
|
137
|
-
it('should create transfer transaction to address with no ATA', async () => {
|
|
138
|
-
const randomDestination = await generateKeyPairSigner();
|
|
139
|
-
const request = {
|
|
140
|
-
amount: 1000000, // 1 USDC
|
|
141
|
-
token: usdcMint,
|
|
142
|
-
source: testWalletAddress,
|
|
143
|
-
destination: randomDestination.address,
|
|
144
|
-
};
|
|
145
|
-
const response = await client.transferTransaction(request);
|
|
146
|
-
expect(response).toBeDefined();
|
|
147
|
-
expect(response.transaction).toBeDefined();
|
|
148
|
-
expect(response.blockhash).toBeDefined();
|
|
149
|
-
expect(response.message).toBeDefined();
|
|
150
|
-
expect(response.instructions).toBeDefined();
|
|
151
|
-
// since setup created ATA for destination, we should not expect ata instruction, only transfer instruction
|
|
152
|
-
expect(response.instructions?.length).toBe(2);
|
|
153
|
-
expect(response.instructions?.[0].programAddress).toBe(ASSOCIATED_TOKEN_PROGRAM_ADDRESS);
|
|
154
|
-
expect(response.instructions?.[1].programAddress).toBe(TOKEN_PROGRAM_ADDRESS);
|
|
155
|
-
});
|
|
156
167
|
it('should estimate transaction fee', async () => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
const
|
|
165
|
-
const fee = await client.estimateTransactionFee({ transaction, fee_token: usdcMint });
|
|
168
|
+
const { transaction } = await buildTokenTransferTransaction({
|
|
169
|
+
amount: 1000000n,
|
|
170
|
+
client,
|
|
171
|
+
destinationWallet: koraAddress,
|
|
172
|
+
mint: usdcMint,
|
|
173
|
+
sourceWallet: testWallet,
|
|
174
|
+
});
|
|
175
|
+
const fee = await client.estimateTransactionFee({ fee_token: usdcMint, transaction });
|
|
166
176
|
expect(fee).toBeDefined();
|
|
167
177
|
expect(typeof fee.fee_in_lamports).toBe('number');
|
|
168
178
|
expect(fee.fee_in_lamports).toBeGreaterThanOrEqual(0);
|
|
@@ -173,15 +183,13 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
173
183
|
}
|
|
174
184
|
});
|
|
175
185
|
it('should sign transaction', async () => {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
const { transaction } = await client.transferTransaction(transferRequest);
|
|
186
|
+
const { transaction } = await buildTokenTransferTransaction({
|
|
187
|
+
amount: 1000000n,
|
|
188
|
+
client,
|
|
189
|
+
destinationWallet: koraAddress,
|
|
190
|
+
mint: usdcMint,
|
|
191
|
+
sourceWallet: testWallet,
|
|
192
|
+
});
|
|
185
193
|
const signResult = await client.signTransaction({
|
|
186
194
|
transaction,
|
|
187
195
|
});
|
|
@@ -189,47 +197,47 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
189
197
|
expect(signResult.signed_transaction).toBeDefined();
|
|
190
198
|
});
|
|
191
199
|
it('should sign and send transaction', async () => {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
};
|
|
200
|
-
const { transaction: transactionString } = await client.transferTransaction(transferRequest);
|
|
200
|
+
const { transaction: transactionString } = await buildTokenTransferTransaction({
|
|
201
|
+
amount: 1000000n,
|
|
202
|
+
client,
|
|
203
|
+
destinationWallet: koraAddress,
|
|
204
|
+
mint: usdcMint,
|
|
205
|
+
sourceWallet: testWallet,
|
|
206
|
+
});
|
|
201
207
|
const transaction = transactionFromBase64(transactionString);
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
const
|
|
208
|
+
// Partially sign transaction with test wallet before sending
|
|
209
|
+
// Kora will add fee payer signature via signAndSendTransaction
|
|
210
|
+
const signedTransaction = await partiallySignTransaction([testWallet.keyPair], transaction);
|
|
211
|
+
const base64SignedTransaction = transactionToBase64(signedTransaction);
|
|
205
212
|
const signResult = await client.signAndSendTransaction({
|
|
206
213
|
transaction: base64SignedTransaction,
|
|
207
214
|
});
|
|
208
215
|
expect(signResult).toBeDefined();
|
|
209
216
|
expect(signResult.signed_transaction).toBeDefined();
|
|
217
|
+
expect(signResult.signature).toBeDefined();
|
|
210
218
|
});
|
|
211
219
|
it('should get payment instruction', async () => {
|
|
212
|
-
const
|
|
213
|
-
amount:
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
const { transaction } = await buildTokenTransferTransaction({
|
|
221
|
+
amount: 1000000n,
|
|
222
|
+
client,
|
|
223
|
+
destinationWallet: koraAddress,
|
|
224
|
+
mint: usdcMint,
|
|
225
|
+
sourceWallet: testWallet,
|
|
226
|
+
});
|
|
218
227
|
const [expectedSenderAta] = await findAssociatedTokenPda({
|
|
228
|
+
mint: usdcMint,
|
|
219
229
|
owner: testWalletAddress,
|
|
220
230
|
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
221
|
-
mint: usdcMint,
|
|
222
231
|
});
|
|
223
232
|
const [koraAta] = await findAssociatedTokenPda({
|
|
233
|
+
mint: usdcMint,
|
|
224
234
|
owner: koraAddress,
|
|
225
235
|
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
226
|
-
mint: usdcMint,
|
|
227
236
|
});
|
|
228
|
-
const {
|
|
229
|
-
const { payment_instruction, payment_amount, payment_token, payment_address, signer_address, original_transaction, } = await client.getPaymentInstruction({
|
|
230
|
-
transaction,
|
|
237
|
+
const { payment_instruction, payment_amount: _payment_amount, payment_token, payment_address, signer_address, original_transaction, } = await client.getPaymentInstruction({
|
|
231
238
|
fee_token: usdcMint,
|
|
232
239
|
source_wallet: testWalletAddress,
|
|
240
|
+
transaction,
|
|
233
241
|
});
|
|
234
242
|
expect(payment_instruction).toBeDefined();
|
|
235
243
|
expect(payment_instruction.programAddress).toBe(TOKEN_PROGRAM_ADDRESS);
|
|
@@ -244,228 +252,101 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
244
252
|
expect(original_transaction).toBe(transaction);
|
|
245
253
|
});
|
|
246
254
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
it('should handle invalid amount', async () => {
|
|
258
|
-
const request = {
|
|
259
|
-
amount: -1, // Invalid amount
|
|
260
|
-
token: usdcMint,
|
|
261
|
-
source: testWalletAddress,
|
|
262
|
-
destination: destinationAddress,
|
|
263
|
-
};
|
|
264
|
-
await expect(client.transferTransaction(request)).rejects.toThrow();
|
|
265
|
-
});
|
|
266
|
-
it('should handle invalid transaction for signing', async () => {
|
|
267
|
-
await expect(client.signTransaction({
|
|
268
|
-
transaction: 'invalid_transaction',
|
|
269
|
-
})).rejects.toThrow();
|
|
270
|
-
});
|
|
271
|
-
it('should handle invalid transaction for fee estimation', async () => {
|
|
272
|
-
await expect(client.estimateTransactionFee({ transaction: 'invalid_transaction', fee_token: usdcMint })).rejects.toThrow();
|
|
273
|
-
});
|
|
274
|
-
it('should handle non-allowed token for fee payment', async () => {
|
|
275
|
-
const transferRequest = {
|
|
276
|
-
amount: 1000000,
|
|
277
|
-
token: usdcMint,
|
|
278
|
-
source: testWalletAddress,
|
|
279
|
-
destination: destinationAddress,
|
|
280
|
-
};
|
|
281
|
-
// TODO: API has an error. this endpoint should verify the provided fee token is supported
|
|
282
|
-
const { transaction } = await client.transferTransaction(transferRequest);
|
|
283
|
-
const fee = await client.estimateTransactionFee({ transaction, fee_token: usdcMint });
|
|
284
|
-
expect(fee).toBeDefined();
|
|
285
|
-
expect(typeof fee.fee_in_lamports).toBe('number');
|
|
286
|
-
expect(fee.fee_in_lamports).toBeGreaterThanOrEqual(0);
|
|
287
|
-
if (!FREE_PRICING) {
|
|
288
|
-
expect(fee.fee_in_lamports).toBeGreaterThan(0);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
describe('End-to-End Flows', () => {
|
|
293
|
-
it('should handle transfer and sign flow', async () => {
|
|
294
|
-
const config = await client.getConfig();
|
|
295
|
-
const paymentAddress = config.fee_payers[0];
|
|
296
|
-
const request = {
|
|
297
|
-
amount: 1000000,
|
|
298
|
-
token: usdcMint,
|
|
299
|
-
source: testWalletAddress,
|
|
300
|
-
destination: paymentAddress,
|
|
301
|
-
};
|
|
302
|
-
// Create and sign the transaction
|
|
303
|
-
const { transaction } = await client.transferTransaction(request);
|
|
304
|
-
const signResult = await client.signTransaction({ transaction });
|
|
305
|
-
expect(signResult.signed_transaction).toBeDefined();
|
|
306
|
-
});
|
|
307
|
-
it('should reject transaction with non-allowed token', async () => {
|
|
308
|
-
const invalidTokenMint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'; // Mainnet USDC mint
|
|
309
|
-
const request = {
|
|
310
|
-
amount: 1000000,
|
|
311
|
-
token: invalidTokenMint,
|
|
312
|
-
source: testWalletAddress,
|
|
313
|
-
destination: destinationAddress,
|
|
314
|
-
};
|
|
315
|
-
await expect(client.transferTransaction(request)).rejects.toThrow();
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
describe('Kit Client (createKitKoraClient)', () => {
|
|
319
|
-
let kitClient;
|
|
320
|
-
beforeAll(async () => {
|
|
321
|
-
kitClient = await createKitKoraClient({
|
|
322
|
-
endpoint: koraRpcUrl,
|
|
323
|
-
rpcUrl: process.env.SOLANA_RPC_URL || 'http://127.0.0.1:8899',
|
|
324
|
-
feeToken: usdcMint,
|
|
325
|
-
feePayerWallet: testWallet,
|
|
326
|
-
...authConfig,
|
|
255
|
+
// Bundle tests require bundle.enabled = true in the Kora config
|
|
256
|
+
(FREE_PRICING ? describe.skip : describe)('Bundle Operations', () => {
|
|
257
|
+
it('should sign bundle of transactions', async () => {
|
|
258
|
+
// Create two transfer transactions for the bundle
|
|
259
|
+
const { transaction: tx1String } = await buildTokenTransferTransaction({
|
|
260
|
+
amount: 1000000n,
|
|
261
|
+
client,
|
|
262
|
+
destinationWallet: koraAddress,
|
|
263
|
+
mint: usdcMint,
|
|
264
|
+
sourceWallet: testWallet,
|
|
327
265
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
it('should expose kora namespace', async () => {
|
|
335
|
-
const config = await kitClient.kora.getConfig();
|
|
336
|
-
expect(config.fee_payers.length).toBeGreaterThan(0);
|
|
337
|
-
});
|
|
338
|
-
it('should plan a transaction without sending', async () => {
|
|
339
|
-
const ix = getTransferSolInstruction({
|
|
340
|
-
source: testWallet,
|
|
341
|
-
destination: address(destinationAddress),
|
|
342
|
-
amount: 1000, // 1000 lamports
|
|
266
|
+
const { transaction: tx2String } = await buildTokenTransferTransaction({
|
|
267
|
+
amount: 500000n,
|
|
268
|
+
client,
|
|
269
|
+
destinationWallet: koraAddress,
|
|
270
|
+
mint: usdcMint,
|
|
271
|
+
sourceWallet: testWallet,
|
|
343
272
|
});
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
amount: 1000, // 1000 lamports
|
|
273
|
+
// Partially sign both transactions with test wallet
|
|
274
|
+
const tx1 = transactionFromBase64(tx1String);
|
|
275
|
+
const tx2 = transactionFromBase64(tx2String);
|
|
276
|
+
const signedTx1 = await partiallySignTransaction([testWallet.keyPair], tx1);
|
|
277
|
+
const signedTx2 = await partiallySignTransaction([testWallet.keyPair], tx2);
|
|
278
|
+
const base64Tx1 = transactionToBase64(signedTx1);
|
|
279
|
+
const base64Tx2 = transactionToBase64(signedTx2);
|
|
280
|
+
const result = await client.signBundle({
|
|
281
|
+
transactions: [base64Tx1, base64Tx2],
|
|
354
282
|
});
|
|
355
|
-
|
|
356
|
-
expect(result.
|
|
357
|
-
expect(result.
|
|
358
|
-
expect(
|
|
359
|
-
|
|
360
|
-
expect(result.context.signature.length).toBeGreaterThanOrEqual(43);
|
|
361
|
-
}, 30000);
|
|
362
|
-
it('should support plugin composition via .use()', () => {
|
|
363
|
-
// Kit plugins must spread the client to preserve existing properties
|
|
364
|
-
const extended = kitClient.use((c) => ({
|
|
365
|
-
...c,
|
|
366
|
-
custom: { hello: () => 'world' },
|
|
367
|
-
}));
|
|
368
|
-
expect(extended.custom.hello()).toBe('world');
|
|
369
|
-
expect(extended.kora).toBeDefined();
|
|
370
|
-
expect(typeof extended.sendTransaction).toBe('function');
|
|
283
|
+
expect(result).toBeDefined();
|
|
284
|
+
expect(result.signed_transactions).toBeDefined();
|
|
285
|
+
expect(Array.isArray(result.signed_transactions)).toBe(true);
|
|
286
|
+
expect(result.signed_transactions.length).toBe(2);
|
|
287
|
+
expect(result.signer_pubkey).toBeDefined();
|
|
371
288
|
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const instructions = message.instructions;
|
|
381
|
-
// Find the transfer placeholder by discriminator + token program
|
|
382
|
-
const paymentIx = instructions.find(ix => ix.programAddress === TOKEN_PROGRAM_ADDRESS && ix.data?.[0] === TRANSFER_DISCRIMINATOR);
|
|
383
|
-
expect(paymentIx).toBeDefined();
|
|
384
|
-
// Verify it's a placeholder (amount=0) with correct accounts
|
|
385
|
-
const parsed = parseTransferInstruction(paymentIx);
|
|
386
|
-
expect(parsed.data.amount).toBe(0n);
|
|
387
|
-
expect(parsed.accounts.authority.address).toBe(testWallet.address);
|
|
289
|
+
it('should sign and send bundle of transactions', async () => {
|
|
290
|
+
// Create two transfer transactions for the bundle
|
|
291
|
+
const { transaction: tx1String } = await buildTokenTransferTransaction({
|
|
292
|
+
amount: 1000000n,
|
|
293
|
+
client,
|
|
294
|
+
destinationWallet: koraAddress,
|
|
295
|
+
mint: usdcMint,
|
|
296
|
+
sourceWallet: testWallet,
|
|
388
297
|
});
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
298
|
+
const { transaction: tx2String } = await buildTokenTransferTransaction({
|
|
299
|
+
amount: 500000n,
|
|
300
|
+
client,
|
|
301
|
+
destinationWallet: koraAddress,
|
|
302
|
+
mint: usdcMint,
|
|
303
|
+
sourceWallet: testWallet,
|
|
304
|
+
});
|
|
305
|
+
// Partially sign both transactions with test wallet
|
|
306
|
+
const tx1 = transactionFromBase64(tx1String);
|
|
307
|
+
const tx2 = transactionFromBase64(tx2String);
|
|
308
|
+
const signedTx1 = await partiallySignTransaction([testWallet.keyPair], tx1);
|
|
309
|
+
const signedTx2 = await partiallySignTransaction([testWallet.keyPair], tx2);
|
|
310
|
+
const base64Tx1 = transactionToBase64(signedTx1);
|
|
311
|
+
const base64Tx2 = transactionToBase64(signedTx2);
|
|
312
|
+
const result = await client.signAndSendBundle({
|
|
313
|
+
transactions: [base64Tx1, base64Tx2],
|
|
400
314
|
});
|
|
315
|
+
expect(result).toBeDefined();
|
|
316
|
+
expect(result.signed_transactions).toBeDefined();
|
|
317
|
+
expect(Array.isArray(result.signed_transactions)).toBe(true);
|
|
318
|
+
expect(result.signed_transactions.length).toBe(2);
|
|
319
|
+
expect(result.signer_pubkey).toBeDefined();
|
|
320
|
+
expect(result.bundle_uuid).toBeDefined();
|
|
321
|
+
expect(typeof result.bundle_uuid).toBe('string');
|
|
401
322
|
});
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
destination: address(destinationAddress),
|
|
409
|
-
amount: 1000,
|
|
410
|
-
});
|
|
411
|
-
const result = await kitClient.sendTransaction([ix]);
|
|
412
|
-
expect(result.status).toBe('successful');
|
|
413
|
-
expect(result.context.signature).toBeDefined();
|
|
414
|
-
// Verify fee was estimated by checking the Kora RPC was called
|
|
415
|
-
// (the transaction succeeded, which means the payment IX had a valid amount)
|
|
416
|
-
}, 30000);
|
|
417
|
-
it('should handle multiple instructions in a single transaction', async () => {
|
|
418
|
-
const ix1 = getTransferSolInstruction({
|
|
419
|
-
source: testWallet,
|
|
420
|
-
destination: address(destinationAddress),
|
|
421
|
-
amount: 500,
|
|
422
|
-
});
|
|
423
|
-
const ix2 = getTransferSolInstruction({
|
|
424
|
-
source: testWallet,
|
|
425
|
-
destination: address(destinationAddress),
|
|
426
|
-
amount: 500,
|
|
427
|
-
});
|
|
428
|
-
const result = await kitClient.sendTransaction([ix1, ix2]);
|
|
429
|
-
expect(result.status).toBe('successful');
|
|
430
|
-
expect(result.context.signature).toBeDefined();
|
|
431
|
-
}, 30000);
|
|
323
|
+
});
|
|
324
|
+
describe('Error Handling', () => {
|
|
325
|
+
it('should handle invalid transaction for signing', async () => {
|
|
326
|
+
await expect(client.signTransaction({
|
|
327
|
+
transaction: 'invalid_transaction',
|
|
328
|
+
})).rejects.toThrow();
|
|
432
329
|
});
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
// tokenProgram() works out of the box — rpc is included in the Kora client
|
|
436
|
-
const tokenClient = kitClient.use(tokenProgram());
|
|
437
|
-
// Transfer USDC to destination via the token plugin's fluent API.
|
|
438
|
-
// This flows through Kora's planner (placeholder) → executor (fee estimate, resolve, send).
|
|
439
|
-
const result = await tokenClient.token.instructions
|
|
440
|
-
.transferToATA({
|
|
441
|
-
authority: testWallet,
|
|
442
|
-
recipient: destinationAddress,
|
|
443
|
-
mint: usdcMint,
|
|
444
|
-
amount: 1000,
|
|
445
|
-
decimals: 6,
|
|
446
|
-
})
|
|
447
|
-
.sendTransaction();
|
|
448
|
-
expect(result.status).toBe('successful');
|
|
449
|
-
expect(result.context.signature).toBeDefined();
|
|
450
|
-
}, 30000);
|
|
330
|
+
it('should handle invalid transaction for fee estimation', async () => {
|
|
331
|
+
await expect(client.estimateTransactionFee({ fee_token: usdcMint, transaction: 'invalid_transaction' })).rejects.toThrow();
|
|
451
332
|
});
|
|
452
333
|
});
|
|
453
334
|
if (FREE_PRICING) {
|
|
454
335
|
describe('Kit Client (free pricing)', () => {
|
|
455
336
|
let freeClient;
|
|
456
337
|
beforeAll(async () => {
|
|
338
|
+
const koraRpcUrl = process.env.KORA_RPC_URL || 'http://127.0.0.1:8080';
|
|
457
339
|
freeClient = await createKitKoraClient({
|
|
458
340
|
endpoint: koraRpcUrl,
|
|
459
341
|
rpcUrl: process.env.SOLANA_RPC_URL || 'http://127.0.0.1:8899',
|
|
460
342
|
feeToken: usdcMint,
|
|
461
343
|
feePayerWallet: testWallet,
|
|
462
|
-
...authConfig,
|
|
463
344
|
});
|
|
464
345
|
}, 30000);
|
|
465
346
|
it('should send transaction without payment instruction when fee is 0', async () => {
|
|
466
347
|
const ix = getTransferSolInstruction({
|
|
467
348
|
source: testWallet,
|
|
468
|
-
destination: address(
|
|
349
|
+
destination: address(koraAddress),
|
|
469
350
|
amount: 1000,
|
|
470
351
|
});
|
|
471
352
|
const result = await freeClient.sendTransaction([ix]);
|
|
@@ -473,15 +354,11 @@ describe(`KoraClient Integration Tests (${AUTH_ENABLED ? 'with auth' : 'without
|
|
|
473
354
|
expect(result.context.signature).toBeDefined();
|
|
474
355
|
}, 30000);
|
|
475
356
|
it('should strip placeholder from planned message when fee is 0', async () => {
|
|
476
|
-
// With free pricing, getPayerSigner may not return a payment address.
|
|
477
|
-
// If it does, the placeholder should still be stripped in the executor.
|
|
478
357
|
const ix = getTransferSolInstruction({
|
|
479
358
|
source: testWallet,
|
|
480
|
-
destination: address(
|
|
359
|
+
destination: address(koraAddress),
|
|
481
360
|
amount: 1000,
|
|
482
361
|
});
|
|
483
|
-
// Sending should succeed regardless — either no placeholder is added,
|
|
484
|
-
// or it's added then stripped when fee estimation returns 0.
|
|
485
362
|
const result = await freeClient.sendTransaction([ix]);
|
|
486
363
|
expect(result.status).toBe('successful');
|
|
487
364
|
}, 30000);
|
|
@@ -324,6 +324,24 @@ describe('createKitKoraClient', () => {
|
|
|
324
324
|
const headers = mockFetch.mock.calls[0][1].headers;
|
|
325
325
|
expect(headers['x-api-key']).toBe('test-api-key');
|
|
326
326
|
});
|
|
327
|
+
it('should pass getRecaptchaToken to underlying KoraClient', async () => {
|
|
328
|
+
const mockGetToken = jest.fn().mockResolvedValue('test-recaptcha-token');
|
|
329
|
+
mockRpcResponse({
|
|
330
|
+
signer_address: MOCK_PAYER_ADDRESS,
|
|
331
|
+
payment_address: MOCK_PAYMENT_ADDRESS,
|
|
332
|
+
});
|
|
333
|
+
await createKitKoraClient({
|
|
334
|
+
endpoint: MOCK_ENDPOINT,
|
|
335
|
+
rpcUrl: MOCK_RPC_URL,
|
|
336
|
+
feeToken: MOCK_FEE_TOKEN,
|
|
337
|
+
feePayerWallet: MOCK_WALLET,
|
|
338
|
+
getRecaptchaToken: mockGetToken,
|
|
339
|
+
});
|
|
340
|
+
// The init call should include the reCAPTCHA token header
|
|
341
|
+
expect(mockGetToken).toHaveBeenCalledTimes(1);
|
|
342
|
+
const headers = mockFetch.mock.calls[0][1].headers;
|
|
343
|
+
expect(headers['x-recaptcha-token']).toBe('test-recaptcha-token');
|
|
344
|
+
});
|
|
327
345
|
});
|
|
328
346
|
describe('Token-2022 support', () => {
|
|
329
347
|
it('should accept tokenProgramId in config', async () => {
|