@sudobility/contracts 0.15.1 → 1.9.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/README.md +2 -3
- package/artifacts/contracts/Mailer.sol/Mailer.dbg.json +1 -1
- package/artifacts/contracts/Mailer.sol/Mailer.json +2 -278
- package/artifacts/contracts/MockUSDC.sol/MockUSDC.dbg.json +1 -1
- package/artifacts/contracts/interfaces/IERC20.sol/IERC20.dbg.json +1 -1
- package/dist/evm/src/evm/index.d.ts +1 -1
- package/dist/evm/src/evm/index.d.ts.map +1 -1
- package/dist/evm/src/evm/index.js +4 -4
- package/dist/evm/src/evm/index.js.map +1 -1
- package/dist/evm/src/evm/mailer-client.d.ts +210 -0
- package/dist/evm/src/evm/mailer-client.d.ts.map +1 -0
- package/dist/evm/src/evm/mailer-client.js +417 -0
- package/dist/evm/src/evm/mailer-client.js.map +1 -0
- package/dist/evm/typechain-types/Mailer.d.ts +10 -177
- package/dist/evm/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/evm/typechain-types/factories/Mailer__factory.d.ts +1 -216
- package/dist/evm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
- package/dist/evm/typechain-types/factories/Mailer__factory.js +1 -277
- package/dist/evm/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/dist/solana/solana/index.d.ts +1 -1
- package/dist/solana/solana/index.d.ts.map +1 -1
- package/dist/solana/solana/index.js +1 -4
- package/dist/solana/solana/index.js.map +1 -1
- package/dist/solana/solana/mailer-client.d.ts +209 -0
- package/dist/solana/solana/mailer-client.d.ts.map +1 -0
- package/dist/solana/solana/mailer-client.js +728 -0
- package/dist/solana/solana/mailer-client.js.map +1 -0
- package/dist/solana/solana/types.d.ts +2 -3
- package/dist/solana/solana/types.d.ts.map +1 -1
- package/dist/solana/solana/types.js.map +1 -1
- package/dist/unified/src/evm/index.d.ts +1 -1
- package/dist/unified/src/evm/index.d.ts.map +1 -1
- package/dist/unified/src/evm/index.js +4 -4
- package/dist/unified/src/evm/index.js.map +1 -1
- package/dist/unified/src/evm/mailer-client.d.ts +210 -0
- package/dist/unified/src/evm/mailer-client.d.ts.map +1 -0
- package/dist/unified/src/evm/mailer-client.js +417 -0
- package/dist/unified/src/evm/mailer-client.js.map +1 -0
- package/dist/unified/src/react/context/MailerProvider.d.ts +20 -26
- package/dist/unified/src/react/context/MailerProvider.d.ts.map +1 -1
- package/dist/unified/src/react/context/MailerProvider.js +26 -26
- package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.d.ts +192 -225
- package/dist/unified/src/react/hooks/useMailerMutations.d.ts.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.js +266 -263
- package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.d.ts +63 -117
- package/dist/unified/src/react/hooks/useMailerQueries.d.ts.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.js +104 -239
- package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified/src/react/index.d.ts +3 -5
- package/dist/unified/src/react/index.d.ts.map +1 -1
- package/dist/unified/src/react/index.js +26 -41
- package/dist/unified/src/react/index.js.map +1 -1
- package/dist/unified/src/solana/index.d.ts +1 -1
- package/dist/unified/src/solana/index.d.ts.map +1 -1
- package/dist/unified/src/solana/index.js +1 -4
- package/dist/unified/src/solana/index.js.map +1 -1
- package/dist/unified/src/solana/mailer-client.d.ts +209 -0
- package/dist/unified/src/solana/mailer-client.d.ts.map +1 -0
- package/dist/unified/src/solana/mailer-client.js +728 -0
- package/dist/unified/src/solana/mailer-client.js.map +1 -0
- package/dist/unified/src/solana/types.d.ts +2 -3
- package/dist/unified/src/solana/types.d.ts.map +1 -1
- package/dist/unified/src/solana/types.js.map +1 -1
- package/dist/unified/src/unified/index.d.ts +1 -1
- package/dist/unified/src/unified/index.d.ts.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.d.ts +247 -192
- package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.js +1462 -551
- package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified/src/unified/types.d.ts +6 -23
- package/dist/unified/src/unified/types.d.ts.map +1 -1
- package/dist/unified/src/utils/chain-config.d.ts +2 -4
- package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
- package/dist/unified/src/utils/chain-config.js +36 -46
- package/dist/unified/src/utils/chain-config.js.map +1 -1
- package/dist/unified/typechain-types/Mailer.d.ts +10 -177
- package/dist/unified/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/unified/typechain-types/factories/Mailer__factory.d.ts +1 -216
- package/dist/unified/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
- package/dist/unified/typechain-types/factories/Mailer__factory.js +1 -277
- package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/dist/unified-esm/src/evm/index.d.ts +1 -1
- package/dist/unified-esm/src/evm/index.d.ts.map +1 -1
- package/dist/unified-esm/src/evm/index.js +2 -2
- package/dist/unified-esm/src/evm/index.js.map +1 -1
- package/dist/unified-esm/src/evm/mailer-client.d.ts +210 -0
- package/dist/unified-esm/src/evm/mailer-client.d.ts.map +1 -0
- package/dist/unified-esm/src/evm/mailer-client.js +413 -0
- package/dist/unified-esm/src/evm/mailer-client.js.map +1 -0
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts +20 -26
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +1 -1
- package/dist/unified-esm/src/react/context/MailerProvider.js +26 -25
- package/dist/unified-esm/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +192 -225
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js +262 -254
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +63 -117
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +1 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js +102 -232
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified-esm/src/react/index.d.ts +3 -5
- package/dist/unified-esm/src/react/index.d.ts.map +1 -1
- package/dist/unified-esm/src/react/index.js +5 -9
- package/dist/unified-esm/src/react/index.js.map +1 -1
- package/dist/unified-esm/src/solana/index.d.ts +1 -1
- package/dist/unified-esm/src/solana/index.d.ts.map +1 -1
- package/dist/unified-esm/src/solana/index.js +1 -2
- package/dist/unified-esm/src/solana/index.js.map +1 -1
- package/dist/unified-esm/src/solana/mailer-client.d.ts +209 -0
- package/dist/unified-esm/src/solana/mailer-client.d.ts.map +1 -0
- package/dist/unified-esm/src/solana/mailer-client.js +724 -0
- package/dist/unified-esm/src/solana/mailer-client.js.map +1 -0
- package/dist/unified-esm/src/solana/types.d.ts +2 -3
- package/dist/unified-esm/src/solana/types.d.ts.map +1 -1
- package/dist/unified-esm/src/solana/types.js.map +1 -1
- package/dist/unified-esm/src/unified/index.d.ts +1 -1
- package/dist/unified-esm/src/unified/index.d.ts.map +1 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +247 -192
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.js +1462 -551
- package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified-esm/src/unified/types.d.ts +6 -23
- package/dist/unified-esm/src/unified/types.d.ts.map +1 -1
- package/dist/unified-esm/src/utils/chain-config.d.ts +2 -4
- package/dist/unified-esm/src/utils/chain-config.d.ts.map +1 -1
- package/dist/unified-esm/src/utils/chain-config.js +35 -46
- package/dist/unified-esm/src/utils/chain-config.js.map +1 -1
- package/dist/unified-esm/typechain-types/Mailer.d.ts +10 -177
- package/dist/unified-esm/typechain-types/Mailer.d.ts.map +1 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +1 -216
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +1 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +1 -277
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/package.json +11 -22
- package/programs/mailer/src/lib.rs +171 -1026
- package/programs/mailer/tests/integration_tests.rs +65 -586
- package/typechain-types/Mailer.ts +8 -319
- package/typechain-types/factories/Mailer__factory.ts +1 -277
- package/artifacts/contracts/Mailer.sol/Mailer.d.ts +0 -1146
- package/artifacts/contracts/Mailer.sol/artifacts.d.ts +0 -21
- package/artifacts/contracts/MockUSDC.sol/MockUSDC.d.ts +0 -284
- package/artifacts/contracts/MockUSDC.sol/artifacts.d.ts +0 -21
- package/artifacts/contracts/interfaces/IERC20.sol/IERC20.d.ts +0 -157
- package/artifacts/contracts/interfaces/IERC20.sol/artifacts.d.ts +0 -21
- package/dist/evm/src/evm/evm-mailer-client.d.ts +0 -1062
- package/dist/evm/src/evm/evm-mailer-client.d.ts.map +0 -1
- package/dist/evm/src/evm/evm-mailer-client.js +0 -924
- package/dist/evm/src/evm/evm-mailer-client.js.map +0 -1
- package/dist/solana/solana/solana-mailer-client.d.ts +0 -209
- package/dist/solana/solana/solana-mailer-client.d.ts.map +0 -1
- package/dist/solana/solana/solana-mailer-client.js +0 -1004
- package/dist/solana/solana/solana-mailer-client.js.map +0 -1
- package/dist/unified/src/evm/evm-mailer-client.d.ts +0 -1062
- package/dist/unified/src/evm/evm-mailer-client.d.ts.map +0 -1
- package/dist/unified/src/evm/evm-mailer-client.js +0 -924
- package/dist/unified/src/evm/evm-mailer-client.js.map +0 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts +0 -209
- package/dist/unified/src/solana/solana-mailer-client.d.ts.map +0 -1
- package/dist/unified/src/solana/solana-mailer-client.js +0 -1004
- package/dist/unified/src/solana/solana-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts +0 -1062
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/evm-mailer-client.js +0 -920
- package/dist/unified-esm/src/evm/evm-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +0 -209
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.js +0 -1000
- package/dist/unified-esm/src/solana/solana-mailer-client.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
use borsh::BorshDeserialize;
|
|
2
1
|
use solana_program::{
|
|
3
2
|
instruction::{AccountMeta, Instruction},
|
|
4
3
|
program_pack::Pack,
|
|
@@ -14,10 +13,11 @@ use spl_token::{
|
|
|
14
13
|
instruction as spl_instruction,
|
|
15
14
|
state::{Account as TokenAccount, Mint},
|
|
16
15
|
};
|
|
16
|
+
use borsh::BorshDeserialize;
|
|
17
17
|
use std::str::FromStr;
|
|
18
18
|
|
|
19
19
|
// Import our program
|
|
20
|
-
use mailer::{
|
|
20
|
+
use mailer::{MailerInstruction, MailerState, RecipientClaim, Delegation};
|
|
21
21
|
|
|
22
22
|
// Program ID for tests
|
|
23
23
|
const PROGRAM_ID_STR: &str = "9FLkBDGpZBcR8LMsQ7MwwV6X9P4TDFgN3DeRh5qYyHJF";
|
|
@@ -51,8 +51,7 @@ async fn create_usdc_mint(
|
|
|
51
51
|
&payer.pubkey(),
|
|
52
52
|
None,
|
|
53
53
|
6, // USDC has 6 decimals
|
|
54
|
-
)
|
|
55
|
-
.unwrap(),
|
|
54
|
+
).unwrap(),
|
|
56
55
|
],
|
|
57
56
|
Some(&payer.pubkey()),
|
|
58
57
|
);
|
|
@@ -83,8 +82,12 @@ async fn create_token_account(
|
|
|
83
82
|
TokenAccount::LEN as u64,
|
|
84
83
|
&spl_token::id(),
|
|
85
84
|
),
|
|
86
|
-
spl_instruction::initialize_account(
|
|
87
|
-
|
|
85
|
+
spl_instruction::initialize_account(
|
|
86
|
+
&spl_token::id(),
|
|
87
|
+
&account.pubkey(),
|
|
88
|
+
mint,
|
|
89
|
+
owner,
|
|
90
|
+
).unwrap(),
|
|
88
91
|
],
|
|
89
92
|
Some(&payer.pubkey()),
|
|
90
93
|
);
|
|
@@ -111,8 +114,7 @@ async fn mint_to(
|
|
|
111
114
|
&payer.pubkey(),
|
|
112
115
|
&[],
|
|
113
116
|
amount,
|
|
114
|
-
)
|
|
115
|
-
.unwrap()],
|
|
117
|
+
).unwrap()],
|
|
116
118
|
Some(&payer.pubkey()),
|
|
117
119
|
);
|
|
118
120
|
transaction.sign(&[payer], recent_blockhash);
|
|
@@ -168,7 +170,7 @@ async fn test_initialize_program() {
|
|
|
168
170
|
// Verify the mailer state was initialized correctly
|
|
169
171
|
let account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
170
172
|
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &account.data[8..]).unwrap();
|
|
171
|
-
|
|
173
|
+
|
|
172
174
|
assert_eq!(mailer_state.owner, payer.pubkey());
|
|
173
175
|
assert_eq!(mailer_state.usdc_mint, usdc_mint);
|
|
174
176
|
assert_eq!(mailer_state.send_fee, 100_000); // 0.1 USDC
|
|
@@ -188,7 +190,7 @@ async fn test_send_priority_message() {
|
|
|
188
190
|
// Create USDC mint and accounts
|
|
189
191
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
190
192
|
let (mailer_pda, _) = get_mailer_pda();
|
|
191
|
-
|
|
193
|
+
|
|
192
194
|
// Initialize the program first
|
|
193
195
|
let init_instruction = Instruction::new_with_borsh(
|
|
194
196
|
program_id(),
|
|
@@ -205,33 +207,11 @@ async fn test_send_priority_message() {
|
|
|
205
207
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
206
208
|
|
|
207
209
|
// Create token accounts
|
|
208
|
-
let sender_usdc = create_token_account(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
recent_blockhash,
|
|
212
|
-
&usdc_mint,
|
|
213
|
-
&payer.pubkey(),
|
|
214
|
-
)
|
|
215
|
-
.await;
|
|
216
|
-
let mailer_usdc = create_token_account(
|
|
217
|
-
&mut banks_client,
|
|
218
|
-
&payer,
|
|
219
|
-
recent_blockhash,
|
|
220
|
-
&usdc_mint,
|
|
221
|
-
&mailer_pda,
|
|
222
|
-
)
|
|
223
|
-
.await;
|
|
224
|
-
|
|
210
|
+
let sender_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
211
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
212
|
+
|
|
225
213
|
// Mint USDC to sender
|
|
226
|
-
mint_to(
|
|
227
|
-
&mut banks_client,
|
|
228
|
-
&payer,
|
|
229
|
-
recent_blockhash,
|
|
230
|
-
&usdc_mint,
|
|
231
|
-
&sender_usdc,
|
|
232
|
-
1_000_000,
|
|
233
|
-
)
|
|
234
|
-
.await; // 1 USDC
|
|
214
|
+
mint_to(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &sender_usdc, 1_000_000).await; // 1 USDC
|
|
235
215
|
|
|
236
216
|
// Get recipient claim PDA
|
|
237
217
|
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
@@ -267,22 +247,16 @@ async fn test_send_priority_message() {
|
|
|
267
247
|
let _recent_blockhash = banks_client.get_latest_blockhash().await.unwrap();
|
|
268
248
|
|
|
269
249
|
// Verify recipient claim was created with correct amount
|
|
270
|
-
let claim_account = banks_client
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
.unwrap()
|
|
274
|
-
.unwrap();
|
|
275
|
-
let recipient_claim: RecipientClaim =
|
|
276
|
-
BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
277
|
-
|
|
250
|
+
let claim_account = banks_client.get_account(recipient_claim_pda).await.unwrap().unwrap();
|
|
251
|
+
let recipient_claim: RecipientClaim = BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
252
|
+
|
|
278
253
|
assert_eq!(recipient_claim.recipient, payer.pubkey());
|
|
279
254
|
assert_eq!(recipient_claim.amount, 90_000); // 90% of send_fee (100,000)
|
|
280
255
|
|
|
281
256
|
// Verify mailer state was updated with owner share
|
|
282
257
|
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
283
|
-
let mailer_state: MailerState =
|
|
284
|
-
|
|
285
|
-
|
|
258
|
+
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
259
|
+
|
|
286
260
|
// Debug output
|
|
287
261
|
println!("Debug - Mailer state:");
|
|
288
262
|
println!(" owner: {}", mailer_state.owner);
|
|
@@ -291,7 +265,7 @@ async fn test_send_priority_message() {
|
|
|
291
265
|
println!(" delegation_fee: {}", mailer_state.delegation_fee);
|
|
292
266
|
println!(" owner_claimable: {}", mailer_state.owner_claimable);
|
|
293
267
|
println!(" bump: {}", mailer_state.bump);
|
|
294
|
-
|
|
268
|
+
|
|
295
269
|
assert_eq!(mailer_state.owner_claimable, 10_000); // 10% of send_fee
|
|
296
270
|
}
|
|
297
271
|
|
|
@@ -307,7 +281,7 @@ async fn test_send_standard_message() {
|
|
|
307
281
|
// Setup similar to priority test
|
|
308
282
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
309
283
|
let (mailer_pda, _) = get_mailer_pda();
|
|
310
|
-
|
|
284
|
+
|
|
311
285
|
// Initialize the program
|
|
312
286
|
let init_instruction = Instruction::new_with_borsh(
|
|
313
287
|
program_id(),
|
|
@@ -324,33 +298,11 @@ async fn test_send_standard_message() {
|
|
|
324
298
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
325
299
|
|
|
326
300
|
// Create token accounts
|
|
327
|
-
let sender_usdc = create_token_account(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
recent_blockhash,
|
|
331
|
-
&usdc_mint,
|
|
332
|
-
&payer.pubkey(),
|
|
333
|
-
)
|
|
334
|
-
.await;
|
|
335
|
-
let mailer_usdc = create_token_account(
|
|
336
|
-
&mut banks_client,
|
|
337
|
-
&payer,
|
|
338
|
-
recent_blockhash,
|
|
339
|
-
&usdc_mint,
|
|
340
|
-
&mailer_pda,
|
|
341
|
-
)
|
|
342
|
-
.await;
|
|
343
|
-
|
|
301
|
+
let sender_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
302
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
303
|
+
|
|
344
304
|
// Mint USDC to sender
|
|
345
|
-
mint_to(
|
|
346
|
-
&mut banks_client,
|
|
347
|
-
&payer,
|
|
348
|
-
recent_blockhash,
|
|
349
|
-
&usdc_mint,
|
|
350
|
-
&sender_usdc,
|
|
351
|
-
1_000_000,
|
|
352
|
-
)
|
|
353
|
-
.await;
|
|
305
|
+
mint_to(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &sender_usdc, 1_000_000).await;
|
|
354
306
|
|
|
355
307
|
// Get recipient claim PDA (needed even if not used for standard send)
|
|
356
308
|
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
@@ -384,207 +336,7 @@ async fn test_send_standard_message() {
|
|
|
384
336
|
|
|
385
337
|
// Verify only owner fee was charged (10% of send_fee = 10,000)
|
|
386
338
|
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
387
|
-
let mailer_state: MailerState =
|
|
388
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
389
|
-
assert_eq!(mailer_state.owner_claimable, 10_000); // Only 10% fee
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
#[tokio::test]
|
|
393
|
-
async fn test_send_through_webhook_priority() {
|
|
394
|
-
let program_test = ProgramTest::new(
|
|
395
|
-
"mailer",
|
|
396
|
-
program_id(),
|
|
397
|
-
processor!(mailer::process_instruction),
|
|
398
|
-
);
|
|
399
|
-
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;
|
|
400
|
-
|
|
401
|
-
// Setup similar to priority test
|
|
402
|
-
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
403
|
-
let (mailer_pda, _) = get_mailer_pda();
|
|
404
|
-
|
|
405
|
-
// Initialize the program
|
|
406
|
-
let init_instruction = Instruction::new_with_borsh(
|
|
407
|
-
program_id(),
|
|
408
|
-
&MailerInstruction::Initialize { usdc_mint },
|
|
409
|
-
vec![
|
|
410
|
-
AccountMeta::new(payer.pubkey(), true),
|
|
411
|
-
AccountMeta::new(mailer_pda, false),
|
|
412
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
413
|
-
],
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
let mut transaction = Transaction::new_with_payer(&[init_instruction], Some(&payer.pubkey()));
|
|
417
|
-
transaction.sign(&[&payer], recent_blockhash);
|
|
418
|
-
banks_client.process_transaction(transaction).await.unwrap();
|
|
419
|
-
|
|
420
|
-
// Create token accounts
|
|
421
|
-
let sender_usdc = create_token_account(
|
|
422
|
-
&mut banks_client,
|
|
423
|
-
&payer,
|
|
424
|
-
recent_blockhash,
|
|
425
|
-
&usdc_mint,
|
|
426
|
-
&payer.pubkey(),
|
|
427
|
-
)
|
|
428
|
-
.await;
|
|
429
|
-
let mailer_usdc = create_token_account(
|
|
430
|
-
&mut banks_client,
|
|
431
|
-
&payer,
|
|
432
|
-
recent_blockhash,
|
|
433
|
-
&usdc_mint,
|
|
434
|
-
&mailer_pda,
|
|
435
|
-
)
|
|
436
|
-
.await;
|
|
437
|
-
|
|
438
|
-
// Mint USDC to sender
|
|
439
|
-
mint_to(
|
|
440
|
-
&mut banks_client,
|
|
441
|
-
&payer,
|
|
442
|
-
recent_blockhash,
|
|
443
|
-
&usdc_mint,
|
|
444
|
-
&sender_usdc,
|
|
445
|
-
1_000_000,
|
|
446
|
-
)
|
|
447
|
-
.await; // 1 USDC
|
|
448
|
-
|
|
449
|
-
// Get recipient claim PDA
|
|
450
|
-
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
451
|
-
|
|
452
|
-
// Send message through webhook with revenue sharing (priority mode)
|
|
453
|
-
let instruction_data = MailerInstruction::SendThroughWebhook {
|
|
454
|
-
to: payer.pubkey(),
|
|
455
|
-
webhook_id: "webhook-123".to_string(),
|
|
456
|
-
revenue_share_to_receiver: true,
|
|
457
|
-
resolve_sender_to_name: false,
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
let instruction = Instruction::new_with_borsh(
|
|
461
|
-
program_id(),
|
|
462
|
-
&instruction_data,
|
|
463
|
-
vec![
|
|
464
|
-
AccountMeta::new(payer.pubkey(), true),
|
|
465
|
-
AccountMeta::new(recipient_claim_pda, false),
|
|
466
|
-
AccountMeta::new(mailer_pda, false), // Must be writable for record_shares to update owner_claimable
|
|
467
|
-
AccountMeta::new(sender_usdc, false),
|
|
468
|
-
AccountMeta::new(mailer_usdc, false),
|
|
469
|
-
AccountMeta::new_readonly(spl_token::id(), false),
|
|
470
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
471
|
-
],
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
let mut transaction = Transaction::new_with_payer(&[instruction], Some(&payer.pubkey()));
|
|
475
|
-
transaction.sign(&[&payer], recent_blockhash);
|
|
476
|
-
banks_client.process_transaction(transaction).await.unwrap();
|
|
477
|
-
|
|
478
|
-
// Verify recipient claim was created with correct amount
|
|
479
|
-
let claim_account = banks_client
|
|
480
|
-
.get_account(recipient_claim_pda)
|
|
481
|
-
.await
|
|
482
|
-
.unwrap()
|
|
483
|
-
.unwrap();
|
|
484
|
-
let recipient_claim: RecipientClaim =
|
|
485
|
-
BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
486
|
-
|
|
487
|
-
assert_eq!(recipient_claim.recipient, payer.pubkey());
|
|
488
|
-
assert_eq!(recipient_claim.amount, 90_000); // 90% of send_fee (100,000)
|
|
489
|
-
|
|
490
|
-
// Verify mailer state was updated with owner share
|
|
491
|
-
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
492
|
-
let mailer_state: MailerState =
|
|
493
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
494
|
-
|
|
495
|
-
assert_eq!(mailer_state.owner_claimable, 10_000); // 10% of send_fee
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
#[tokio::test]
|
|
499
|
-
async fn test_send_through_webhook_standard() {
|
|
500
|
-
let program_test = ProgramTest::new(
|
|
501
|
-
"mailer",
|
|
502
|
-
program_id(),
|
|
503
|
-
processor!(mailer::process_instruction),
|
|
504
|
-
);
|
|
505
|
-
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;
|
|
506
|
-
|
|
507
|
-
// Setup similar to standard test
|
|
508
|
-
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
509
|
-
let (mailer_pda, _) = get_mailer_pda();
|
|
510
|
-
|
|
511
|
-
// Initialize the program
|
|
512
|
-
let init_instruction = Instruction::new_with_borsh(
|
|
513
|
-
program_id(),
|
|
514
|
-
&MailerInstruction::Initialize { usdc_mint },
|
|
515
|
-
vec![
|
|
516
|
-
AccountMeta::new(payer.pubkey(), true),
|
|
517
|
-
AccountMeta::new(mailer_pda, false),
|
|
518
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
519
|
-
],
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
let mut transaction = Transaction::new_with_payer(&[init_instruction], Some(&payer.pubkey()));
|
|
523
|
-
transaction.sign(&[&payer], recent_blockhash);
|
|
524
|
-
banks_client.process_transaction(transaction).await.unwrap();
|
|
525
|
-
|
|
526
|
-
// Create token accounts
|
|
527
|
-
let sender_usdc = create_token_account(
|
|
528
|
-
&mut banks_client,
|
|
529
|
-
&payer,
|
|
530
|
-
recent_blockhash,
|
|
531
|
-
&usdc_mint,
|
|
532
|
-
&payer.pubkey(),
|
|
533
|
-
)
|
|
534
|
-
.await;
|
|
535
|
-
let mailer_usdc = create_token_account(
|
|
536
|
-
&mut banks_client,
|
|
537
|
-
&payer,
|
|
538
|
-
recent_blockhash,
|
|
539
|
-
&usdc_mint,
|
|
540
|
-
&mailer_pda,
|
|
541
|
-
)
|
|
542
|
-
.await;
|
|
543
|
-
|
|
544
|
-
// Mint USDC to sender
|
|
545
|
-
mint_to(
|
|
546
|
-
&mut banks_client,
|
|
547
|
-
&payer,
|
|
548
|
-
recent_blockhash,
|
|
549
|
-
&usdc_mint,
|
|
550
|
-
&sender_usdc,
|
|
551
|
-
1_000_000,
|
|
552
|
-
)
|
|
553
|
-
.await;
|
|
554
|
-
|
|
555
|
-
// Get recipient claim PDA (needed even if not used for standard send)
|
|
556
|
-
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
557
|
-
|
|
558
|
-
// Send webhook message (standard mode - no revenue sharing)
|
|
559
|
-
let instruction_data = MailerInstruction::SendThroughWebhook {
|
|
560
|
-
to: payer.pubkey(),
|
|
561
|
-
webhook_id: "webhook-456".to_string(),
|
|
562
|
-
revenue_share_to_receiver: false,
|
|
563
|
-
resolve_sender_to_name: false,
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
let instruction = Instruction::new_with_borsh(
|
|
567
|
-
program_id(),
|
|
568
|
-
&instruction_data,
|
|
569
|
-
vec![
|
|
570
|
-
AccountMeta::new(payer.pubkey(), true),
|
|
571
|
-
AccountMeta::new_readonly(recipient_claim_pda, false), // Not used for standard send but required
|
|
572
|
-
AccountMeta::new(mailer_pda, false), // Needs to be writable to update owner_claimable
|
|
573
|
-
AccountMeta::new(sender_usdc, false),
|
|
574
|
-
AccountMeta::new(mailer_usdc, false),
|
|
575
|
-
AccountMeta::new_readonly(spl_token::id(), false),
|
|
576
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
577
|
-
],
|
|
578
|
-
);
|
|
579
|
-
|
|
580
|
-
let mut transaction = Transaction::new_with_payer(&[instruction], Some(&payer.pubkey()));
|
|
581
|
-
transaction.sign(&[&payer], recent_blockhash);
|
|
582
|
-
banks_client.process_transaction(transaction).await.unwrap();
|
|
583
|
-
|
|
584
|
-
// Verify only owner fee was charged (10% of send_fee = 10,000)
|
|
585
|
-
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
586
|
-
let mailer_state: MailerState =
|
|
587
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
339
|
+
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
588
340
|
assert_eq!(mailer_state.owner_claimable, 10_000); // Only 10% fee
|
|
589
341
|
}
|
|
590
342
|
|
|
@@ -600,7 +352,7 @@ async fn test_claim_recipient_share() {
|
|
|
600
352
|
// Setup and send priority message first (similar to previous test)
|
|
601
353
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
602
354
|
let (mailer_pda, _) = get_mailer_pda();
|
|
603
|
-
|
|
355
|
+
|
|
604
356
|
// Initialize
|
|
605
357
|
let init_instruction = Instruction::new_with_borsh(
|
|
606
358
|
program_id(),
|
|
@@ -617,33 +369,11 @@ async fn test_claim_recipient_share() {
|
|
|
617
369
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
618
370
|
|
|
619
371
|
// Create token accounts
|
|
620
|
-
let sender_usdc = create_token_account(
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
recent_blockhash,
|
|
624
|
-
&usdc_mint,
|
|
625
|
-
&payer.pubkey(),
|
|
626
|
-
)
|
|
627
|
-
.await;
|
|
628
|
-
let mailer_usdc = create_token_account(
|
|
629
|
-
&mut banks_client,
|
|
630
|
-
&payer,
|
|
631
|
-
recent_blockhash,
|
|
632
|
-
&usdc_mint,
|
|
633
|
-
&mailer_pda,
|
|
634
|
-
)
|
|
635
|
-
.await;
|
|
636
|
-
|
|
372
|
+
let sender_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
373
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
374
|
+
|
|
637
375
|
// Mint USDC
|
|
638
|
-
mint_to(
|
|
639
|
-
&mut banks_client,
|
|
640
|
-
&payer,
|
|
641
|
-
recent_blockhash,
|
|
642
|
-
&usdc_mint,
|
|
643
|
-
&sender_usdc,
|
|
644
|
-
1_000_000,
|
|
645
|
-
)
|
|
646
|
-
.await;
|
|
376
|
+
mint_to(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &sender_usdc, 1_000_000).await;
|
|
647
377
|
|
|
648
378
|
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
649
379
|
|
|
@@ -655,7 +385,7 @@ async fn test_claim_recipient_share() {
|
|
|
655
385
|
subject: "Test".to_string(),
|
|
656
386
|
_body: "Test".to_string(),
|
|
657
387
|
revenue_share_to_receiver: true,
|
|
658
|
-
|
|
388
|
+
resolve_sender_to_name: false,
|
|
659
389
|
},
|
|
660
390
|
vec![
|
|
661
391
|
AccountMeta::new(payer.pubkey(), true),
|
|
@@ -673,14 +403,7 @@ async fn test_claim_recipient_share() {
|
|
|
673
403
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
674
404
|
|
|
675
405
|
// Create recipient's own USDC account to receive the claim
|
|
676
|
-
let recipient_usdc = create_token_account(
|
|
677
|
-
&mut banks_client,
|
|
678
|
-
&payer,
|
|
679
|
-
recent_blockhash,
|
|
680
|
-
&usdc_mint,
|
|
681
|
-
&payer.pubkey(),
|
|
682
|
-
)
|
|
683
|
-
.await;
|
|
406
|
+
let recipient_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
684
407
|
|
|
685
408
|
// Now claim the recipient share
|
|
686
409
|
let claim_instruction = Instruction::new_with_borsh(
|
|
@@ -701,21 +424,12 @@ async fn test_claim_recipient_share() {
|
|
|
701
424
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
702
425
|
|
|
703
426
|
// Verify the claim was processed
|
|
704
|
-
let claim_account = banks_client
|
|
705
|
-
|
|
706
|
-
.await
|
|
707
|
-
.unwrap()
|
|
708
|
-
.unwrap();
|
|
709
|
-
let recipient_claim: RecipientClaim =
|
|
710
|
-
BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
427
|
+
let claim_account = banks_client.get_account(recipient_claim_pda).await.unwrap().unwrap();
|
|
428
|
+
let recipient_claim: RecipientClaim = BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
711
429
|
assert_eq!(recipient_claim.amount, 0); // Should be zero after claiming
|
|
712
430
|
|
|
713
431
|
// Verify tokens were transferred to recipient
|
|
714
|
-
let recipient_token_account = banks_client
|
|
715
|
-
.get_account(recipient_usdc)
|
|
716
|
-
.await
|
|
717
|
-
.unwrap()
|
|
718
|
-
.unwrap();
|
|
432
|
+
let recipient_token_account = banks_client.get_account(recipient_usdc).await.unwrap().unwrap();
|
|
719
433
|
let token_account_data = TokenAccount::unpack(&recipient_token_account.data).unwrap();
|
|
720
434
|
assert_eq!(token_account_data.amount, 90_000); // 90% of 100,000
|
|
721
435
|
}
|
|
@@ -732,7 +446,7 @@ async fn test_claim_owner_share() {
|
|
|
732
446
|
// Setup and send a message to accumulate owner fees
|
|
733
447
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
734
448
|
let (mailer_pda, _) = get_mailer_pda();
|
|
735
|
-
|
|
449
|
+
|
|
736
450
|
// Initialize
|
|
737
451
|
let init_instruction = Instruction::new_with_borsh(
|
|
738
452
|
program_id(),
|
|
@@ -749,40 +463,11 @@ async fn test_claim_owner_share() {
|
|
|
749
463
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
750
464
|
|
|
751
465
|
// Setup token accounts and send standard message to accumulate owner fees
|
|
752
|
-
let sender_usdc = create_token_account(
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
&payer.pubkey(),
|
|
758
|
-
)
|
|
759
|
-
.await;
|
|
760
|
-
let mailer_usdc = create_token_account(
|
|
761
|
-
&mut banks_client,
|
|
762
|
-
&payer,
|
|
763
|
-
recent_blockhash,
|
|
764
|
-
&usdc_mint,
|
|
765
|
-
&mailer_pda,
|
|
766
|
-
)
|
|
767
|
-
.await;
|
|
768
|
-
let owner_usdc = create_token_account(
|
|
769
|
-
&mut banks_client,
|
|
770
|
-
&payer,
|
|
771
|
-
recent_blockhash,
|
|
772
|
-
&usdc_mint,
|
|
773
|
-
&payer.pubkey(),
|
|
774
|
-
)
|
|
775
|
-
.await;
|
|
776
|
-
|
|
777
|
-
mint_to(
|
|
778
|
-
&mut banks_client,
|
|
779
|
-
&payer,
|
|
780
|
-
recent_blockhash,
|
|
781
|
-
&usdc_mint,
|
|
782
|
-
&sender_usdc,
|
|
783
|
-
1_000_000,
|
|
784
|
-
)
|
|
785
|
-
.await;
|
|
466
|
+
let sender_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
467
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
468
|
+
let owner_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
469
|
+
|
|
470
|
+
mint_to(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &sender_usdc, 1_000_000).await;
|
|
786
471
|
|
|
787
472
|
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
788
473
|
|
|
@@ -794,7 +479,7 @@ async fn test_claim_owner_share() {
|
|
|
794
479
|
subject: "Test".to_string(),
|
|
795
480
|
_body: "Test".to_string(),
|
|
796
481
|
revenue_share_to_receiver: false,
|
|
797
|
-
|
|
482
|
+
resolve_sender_to_name: false,
|
|
798
483
|
},
|
|
799
484
|
vec![
|
|
800
485
|
AccountMeta::new(payer.pubkey(), true),
|
|
@@ -830,8 +515,7 @@ async fn test_claim_owner_share() {
|
|
|
830
515
|
|
|
831
516
|
// Verify owner claimable was reset
|
|
832
517
|
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
833
|
-
let mailer_state: MailerState =
|
|
834
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
518
|
+
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
835
519
|
assert_eq!(mailer_state.owner_claimable, 0);
|
|
836
520
|
|
|
837
521
|
// Verify tokens were transferred to owner
|
|
@@ -851,7 +535,7 @@ async fn test_set_fees() {
|
|
|
851
535
|
|
|
852
536
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
853
537
|
let (mailer_pda, _) = get_mailer_pda();
|
|
854
|
-
|
|
538
|
+
|
|
855
539
|
// Initialize
|
|
856
540
|
let init_instruction = Instruction::new_with_borsh(
|
|
857
541
|
program_id(),
|
|
@@ -877,38 +561,32 @@ async fn test_set_fees() {
|
|
|
877
561
|
],
|
|
878
562
|
);
|
|
879
563
|
|
|
880
|
-
let mut transaction =
|
|
881
|
-
Transaction::new_with_payer(&[set_fee_instruction], Some(&payer.pubkey()));
|
|
564
|
+
let mut transaction = Transaction::new_with_payer(&[set_fee_instruction], Some(&payer.pubkey()));
|
|
882
565
|
transaction.sign(&[&payer], recent_blockhash);
|
|
883
566
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
884
567
|
|
|
885
568
|
// Verify fee was updated
|
|
886
569
|
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
887
|
-
let mailer_state: MailerState =
|
|
888
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
570
|
+
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
889
571
|
assert_eq!(mailer_state.send_fee, 200_000);
|
|
890
572
|
|
|
891
573
|
// Test setting delegation fee
|
|
892
574
|
let set_delegation_fee_instruction = Instruction::new_with_borsh(
|
|
893
575
|
program_id(),
|
|
894
|
-
&MailerInstruction::SetDelegationFee {
|
|
895
|
-
new_fee: 20_000_000,
|
|
896
|
-
},
|
|
576
|
+
&MailerInstruction::SetDelegationFee { new_fee: 20_000_000 },
|
|
897
577
|
vec![
|
|
898
578
|
AccountMeta::new(payer.pubkey(), true),
|
|
899
579
|
AccountMeta::new(mailer_pda, false),
|
|
900
580
|
],
|
|
901
581
|
);
|
|
902
582
|
|
|
903
|
-
let mut transaction =
|
|
904
|
-
Transaction::new_with_payer(&[set_delegation_fee_instruction], Some(&payer.pubkey()));
|
|
583
|
+
let mut transaction = Transaction::new_with_payer(&[set_delegation_fee_instruction], Some(&payer.pubkey()));
|
|
905
584
|
transaction.sign(&[&payer], recent_blockhash);
|
|
906
585
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
907
586
|
|
|
908
587
|
// Verify delegation fee was updated
|
|
909
588
|
let mailer_account = banks_client.get_account(mailer_pda).await.unwrap().unwrap();
|
|
910
|
-
let mailer_state: MailerState =
|
|
911
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
589
|
+
let mailer_state: MailerState = BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
912
590
|
assert_eq!(mailer_state.delegation_fee, 20_000_000);
|
|
913
591
|
}
|
|
914
592
|
|
|
@@ -923,7 +601,7 @@ async fn test_delegation_functionality() {
|
|
|
923
601
|
|
|
924
602
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
925
603
|
let (mailer_pda, _) = get_mailer_pda();
|
|
926
|
-
|
|
604
|
+
|
|
927
605
|
// Initialize
|
|
928
606
|
let init_instruction = Instruction::new_with_borsh(
|
|
929
607
|
program_id(),
|
|
@@ -940,32 +618,10 @@ async fn test_delegation_functionality() {
|
|
|
940
618
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
941
619
|
|
|
942
620
|
// Setup token accounts
|
|
943
|
-
let delegator_usdc = create_token_account(
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
&usdc_mint,
|
|
948
|
-
&payer.pubkey(),
|
|
949
|
-
)
|
|
950
|
-
.await;
|
|
951
|
-
let mailer_usdc = create_token_account(
|
|
952
|
-
&mut banks_client,
|
|
953
|
-
&payer,
|
|
954
|
-
recent_blockhash,
|
|
955
|
-
&usdc_mint,
|
|
956
|
-
&mailer_pda,
|
|
957
|
-
)
|
|
958
|
-
.await;
|
|
959
|
-
|
|
960
|
-
mint_to(
|
|
961
|
-
&mut banks_client,
|
|
962
|
-
&payer,
|
|
963
|
-
recent_blockhash,
|
|
964
|
-
&usdc_mint,
|
|
965
|
-
&delegator_usdc,
|
|
966
|
-
50_000_000,
|
|
967
|
-
)
|
|
968
|
-
.await; // 50 USDC
|
|
621
|
+
let delegator_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
622
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
623
|
+
|
|
624
|
+
mint_to(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &delegator_usdc, 50_000_000).await; // 50 USDC
|
|
969
625
|
|
|
970
626
|
let delegate = Keypair::new();
|
|
971
627
|
let (delegation_pda, _) = get_delegation_pda(&payer.pubkey());
|
|
@@ -987,19 +643,13 @@ async fn test_delegation_functionality() {
|
|
|
987
643
|
],
|
|
988
644
|
);
|
|
989
645
|
|
|
990
|
-
let mut transaction =
|
|
991
|
-
Transaction::new_with_payer(&[delegate_instruction], Some(&payer.pubkey()));
|
|
646
|
+
let mut transaction = Transaction::new_with_payer(&[delegate_instruction], Some(&payer.pubkey()));
|
|
992
647
|
transaction.sign(&[&payer], recent_blockhash);
|
|
993
648
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
994
649
|
|
|
995
650
|
// Verify delegation was created
|
|
996
|
-
let delegation_account = banks_client
|
|
997
|
-
|
|
998
|
-
.await
|
|
999
|
-
.unwrap()
|
|
1000
|
-
.unwrap();
|
|
1001
|
-
let delegation: Delegation =
|
|
1002
|
-
BorshDeserialize::deserialize(&mut &delegation_account.data[8..]).unwrap();
|
|
651
|
+
let delegation_account = banks_client.get_account(delegation_pda).await.unwrap().unwrap();
|
|
652
|
+
let delegation: Delegation = BorshDeserialize::deserialize(&mut &delegation_account.data[8..]).unwrap();
|
|
1003
653
|
assert_eq!(delegation.delegator, payer.pubkey());
|
|
1004
654
|
assert_eq!(delegation.delegate, Some(delegate.pubkey()));
|
|
1005
655
|
|
|
@@ -1012,7 +662,6 @@ async fn test_delegation_functionality() {
|
|
|
1012
662
|
vec![
|
|
1013
663
|
AccountMeta::new(delegate.pubkey(), true),
|
|
1014
664
|
AccountMeta::new(delegation_pda, false),
|
|
1015
|
-
AccountMeta::new_readonly(mailer_pda, false),
|
|
1016
665
|
],
|
|
1017
666
|
);
|
|
1018
667
|
|
|
@@ -1038,25 +687,11 @@ async fn test_error_conditions() {
|
|
|
1038
687
|
|
|
1039
688
|
let usdc_mint = create_usdc_mint(&mut banks_client, &payer, recent_blockhash).await;
|
|
1040
689
|
let (mailer_pda, _) = get_mailer_pda();
|
|
1041
|
-
|
|
690
|
+
|
|
1042
691
|
// Test claiming with no claimable amount (should fail)
|
|
1043
692
|
let (recipient_claim_pda, _) = get_claim_pda(&payer.pubkey());
|
|
1044
|
-
let recipient_usdc = create_token_account(
|
|
1045
|
-
|
|
1046
|
-
&payer,
|
|
1047
|
-
recent_blockhash,
|
|
1048
|
-
&usdc_mint,
|
|
1049
|
-
&payer.pubkey(),
|
|
1050
|
-
)
|
|
1051
|
-
.await;
|
|
1052
|
-
let mailer_usdc = create_token_account(
|
|
1053
|
-
&mut banks_client,
|
|
1054
|
-
&payer,
|
|
1055
|
-
recent_blockhash,
|
|
1056
|
-
&usdc_mint,
|
|
1057
|
-
&mailer_pda,
|
|
1058
|
-
)
|
|
1059
|
-
.await;
|
|
693
|
+
let recipient_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &payer.pubkey()).await;
|
|
694
|
+
let mailer_usdc = create_token_account(&mut banks_client, &payer, recent_blockhash, &usdc_mint, &mailer_pda).await;
|
|
1060
695
|
|
|
1061
696
|
let claim_instruction = Instruction::new_with_borsh(
|
|
1062
697
|
program_id(),
|
|
@@ -1073,164 +708,8 @@ async fn test_error_conditions() {
|
|
|
1073
708
|
|
|
1074
709
|
let mut transaction = Transaction::new_with_payer(&[claim_instruction], Some(&payer.pubkey()));
|
|
1075
710
|
transaction.sign(&[&payer], recent_blockhash);
|
|
1076
|
-
|
|
711
|
+
|
|
1077
712
|
// This should fail because no claim exists
|
|
1078
713
|
let result = banks_client.process_transaction(transaction).await;
|
|
1079
714
|
assert!(result.is_err());
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
#[tokio::test]
|
|
1083
|
-
async fn test_claim_expired_shares_moves_funds_to_owner() {
|
|
1084
|
-
let program_test = ProgramTest::new(
|
|
1085
|
-
"mailer",
|
|
1086
|
-
program_id(),
|
|
1087
|
-
processor!(mailer::process_instruction),
|
|
1088
|
-
);
|
|
1089
|
-
let mut context = program_test.start_with_context().await;
|
|
1090
|
-
|
|
1091
|
-
let mut recent_blockhash = context.last_blockhash;
|
|
1092
|
-
|
|
1093
|
-
// Create USDC mint and initialize the program
|
|
1094
|
-
let usdc_mint =
|
|
1095
|
-
create_usdc_mint(&mut context.banks_client, &context.payer, recent_blockhash).await;
|
|
1096
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1097
|
-
|
|
1098
|
-
let (mailer_pda, _) = get_mailer_pda();
|
|
1099
|
-
let init_instruction = Instruction::new_with_borsh(
|
|
1100
|
-
program_id(),
|
|
1101
|
-
&MailerInstruction::Initialize { usdc_mint },
|
|
1102
|
-
vec![
|
|
1103
|
-
AccountMeta::new(context.payer.pubkey(), true),
|
|
1104
|
-
AccountMeta::new(mailer_pda, false),
|
|
1105
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
1106
|
-
],
|
|
1107
|
-
);
|
|
1108
|
-
|
|
1109
|
-
let mut transaction =
|
|
1110
|
-
Transaction::new_with_payer(&[init_instruction], Some(&context.payer.pubkey()));
|
|
1111
|
-
transaction.sign(&[&context.payer], recent_blockhash);
|
|
1112
|
-
context
|
|
1113
|
-
.banks_client
|
|
1114
|
-
.process_transaction(transaction)
|
|
1115
|
-
.await
|
|
1116
|
-
.unwrap();
|
|
1117
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1118
|
-
|
|
1119
|
-
// Prepare token accounts and fund the sender
|
|
1120
|
-
let sender_usdc = create_token_account(
|
|
1121
|
-
&mut context.banks_client,
|
|
1122
|
-
&context.payer,
|
|
1123
|
-
recent_blockhash,
|
|
1124
|
-
&usdc_mint,
|
|
1125
|
-
&context.payer.pubkey(),
|
|
1126
|
-
)
|
|
1127
|
-
.await;
|
|
1128
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1129
|
-
|
|
1130
|
-
let mailer_usdc = create_token_account(
|
|
1131
|
-
&mut context.banks_client,
|
|
1132
|
-
&context.payer,
|
|
1133
|
-
recent_blockhash,
|
|
1134
|
-
&usdc_mint,
|
|
1135
|
-
&mailer_pda,
|
|
1136
|
-
)
|
|
1137
|
-
.await;
|
|
1138
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1139
|
-
|
|
1140
|
-
mint_to(
|
|
1141
|
-
&mut context.banks_client,
|
|
1142
|
-
&context.payer,
|
|
1143
|
-
recent_blockhash,
|
|
1144
|
-
&usdc_mint,
|
|
1145
|
-
&sender_usdc,
|
|
1146
|
-
1_000_000,
|
|
1147
|
-
)
|
|
1148
|
-
.await; // 1 USDC to cover priority message
|
|
1149
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1150
|
-
|
|
1151
|
-
let (recipient_claim_pda, _) = get_claim_pda(&context.payer.pubkey());
|
|
1152
|
-
|
|
1153
|
-
// Send a priority message to create the claim record
|
|
1154
|
-
let send_instruction = Instruction::new_with_borsh(
|
|
1155
|
-
program_id(),
|
|
1156
|
-
&MailerInstruction::Send {
|
|
1157
|
-
to: context.payer.pubkey(),
|
|
1158
|
-
subject: "Expired claim".to_string(),
|
|
1159
|
-
_body: "Body".to_string(),
|
|
1160
|
-
revenue_share_to_receiver: true,
|
|
1161
|
-
resolve_sender_to_name: false,
|
|
1162
|
-
},
|
|
1163
|
-
vec![
|
|
1164
|
-
AccountMeta::new(context.payer.pubkey(), true),
|
|
1165
|
-
AccountMeta::new(recipient_claim_pda, false),
|
|
1166
|
-
AccountMeta::new(mailer_pda, false),
|
|
1167
|
-
AccountMeta::new(sender_usdc, false),
|
|
1168
|
-
AccountMeta::new(mailer_usdc, false),
|
|
1169
|
-
AccountMeta::new_readonly(spl_token::id(), false),
|
|
1170
|
-
AccountMeta::new_readonly(system_program::id(), false),
|
|
1171
|
-
],
|
|
1172
|
-
);
|
|
1173
|
-
|
|
1174
|
-
let mut transaction =
|
|
1175
|
-
Transaction::new_with_payer(&[send_instruction], Some(&context.payer.pubkey()));
|
|
1176
|
-
transaction.sign(&[&context.payer], recent_blockhash);
|
|
1177
|
-
context
|
|
1178
|
-
.banks_client
|
|
1179
|
-
.process_transaction(transaction)
|
|
1180
|
-
.await
|
|
1181
|
-
.unwrap();
|
|
1182
|
-
|
|
1183
|
-
// Warp forward so the claim expires (claim period is 60 days = 5,184,000 seconds)
|
|
1184
|
-
// Manually set the clock to a future timestamp beyond the claim period
|
|
1185
|
-
use solana_sdk::clock::Clock;
|
|
1186
|
-
let mut clock = context.banks_client.get_sysvar::<Clock>().await.unwrap();
|
|
1187
|
-
clock.unix_timestamp += 60 * 24 * 60 * 60 + 1; // 60 days + 1 second
|
|
1188
|
-
context.set_sysvar(&clock);
|
|
1189
|
-
|
|
1190
|
-
recent_blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
|
|
1191
|
-
|
|
1192
|
-
// Owner reclaims expired shares
|
|
1193
|
-
let claim_expired_instruction = Instruction::new_with_borsh(
|
|
1194
|
-
program_id(),
|
|
1195
|
-
&MailerInstruction::ClaimExpiredShares {
|
|
1196
|
-
recipient: context.payer.pubkey(),
|
|
1197
|
-
},
|
|
1198
|
-
vec![
|
|
1199
|
-
AccountMeta::new(context.payer.pubkey(), true),
|
|
1200
|
-
AccountMeta::new(mailer_pda, false),
|
|
1201
|
-
AccountMeta::new(recipient_claim_pda, false),
|
|
1202
|
-
],
|
|
1203
|
-
);
|
|
1204
|
-
|
|
1205
|
-
let mut transaction =
|
|
1206
|
-
Transaction::new_with_payer(&[claim_expired_instruction], Some(&context.payer.pubkey()));
|
|
1207
|
-
transaction.sign(&[&context.payer], recent_blockhash);
|
|
1208
|
-
context
|
|
1209
|
-
.banks_client
|
|
1210
|
-
.process_transaction(transaction)
|
|
1211
|
-
.await
|
|
1212
|
-
.unwrap();
|
|
1213
|
-
|
|
1214
|
-
// Recipient claim should be cleared
|
|
1215
|
-
let claim_account = context
|
|
1216
|
-
.banks_client
|
|
1217
|
-
.get_account(recipient_claim_pda)
|
|
1218
|
-
.await
|
|
1219
|
-
.unwrap()
|
|
1220
|
-
.unwrap();
|
|
1221
|
-
let claim_state: RecipientClaim =
|
|
1222
|
-
BorshDeserialize::deserialize(&mut &claim_account.data[8..]).unwrap();
|
|
1223
|
-
assert_eq!(claim_state.amount, 0);
|
|
1224
|
-
assert_eq!(claim_state.timestamp, 0);
|
|
1225
|
-
|
|
1226
|
-
// Owner claimable should now include both original owner share and reclaimed amount (total 100,000)
|
|
1227
|
-
let mailer_account = context
|
|
1228
|
-
.banks_client
|
|
1229
|
-
.get_account(mailer_pda)
|
|
1230
|
-
.await
|
|
1231
|
-
.unwrap()
|
|
1232
|
-
.unwrap();
|
|
1233
|
-
let mailer_state: MailerState =
|
|
1234
|
-
BorshDeserialize::deserialize(&mut &mailer_account.data[8..]).unwrap();
|
|
1235
|
-
assert_eq!(mailer_state.owner_claimable, 100_000);
|
|
1236
|
-
}
|
|
715
|
+
}
|