Skip to content

Commit c57d573

Browse files
authored
P-Token Formatting (#83)
#77 Applied linting, but did not apply formatting Formatting is checked with: ``` pnpm install pnpm p-token:format ``` This pr also creates a CI job that will check linting and formatting for PRs to proof branch. Again this does not apply to SPL-Token which @Stevengre and I will deal with at a later point
1 parent 32f80f7 commit c57d573

21 files changed

+1283
-467
lines changed

.github/workflows/proofs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Proofs
2+
3+
on:
4+
push:
5+
branches: [proofs]
6+
pull_request:
7+
branches: [proofs]
8+
9+
jobs:
10+
format_and_lint_ptoken:
11+
name: Format & Lint p-token
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Git Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Environment
18+
uses: ./.github/actions/setup
19+
with:
20+
clippy: true
21+
rustfmt: true
22+
23+
- name: Format
24+
run: pnpm p-token:format
25+
26+
- name: Lint
27+
run: pnpm p-token:lint

p-token/src/entrypoint-runtime-verification.rs

Lines changed: 618 additions & 340 deletions
Large diffs are not rendered by default.

p-token/src/entrypoint.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use {
22
crate::processor::*,
33
pinocchio::{
4-
account_info::AccountInfo, no_allocator, nostd_panic_handler, program_entrypoint, program_error::{ProgramError, ToStr}, pubkey::Pubkey, ProgramResult
4+
account_info::AccountInfo,
5+
no_allocator, nostd_panic_handler, program_entrypoint,
6+
program_error::{ProgramError, ToStr},
7+
pubkey::Pubkey,
8+
ProgramResult,
59
},
610
pinocchio_token_interface::error::TokenError,
711
};

p-token/src/stubs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ pub unsafe extern "C" fn sol_memcpy_(dst: *mut u8, src: *const u8, n: usize) {
99
if !dst.is_null() && !src.is_null() && n > 0 {
1010
core::ptr::copy_nonoverlapping(src, dst, n);
1111
}
12-
}
12+
}

p-token/tests/approve.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ async fn _approve_invalid_src() {
144144
);
145145
let result = context.banks_client.process_transaction(tx).await;
146146
let inner_error = result.err().unwrap().unwrap();
147-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
147+
assert_eq!(
148+
inner_error,
149+
solana_transaction_error::TransactionError::InstructionError(
150+
0,
151+
solana_instruction::error::InstructionError::InvalidAccountData
152+
)
153+
);
148154
}
149155

150156
#[tokio::test]
@@ -202,7 +208,11 @@ async fn approve_frozen() {
202208
&[&context.payer, &freeze_authority],
203209
context.last_blockhash,
204210
);
205-
context.banks_client.process_transaction(freeze_tx).await.unwrap();
211+
context
212+
.banks_client
213+
.process_transaction(freeze_tx)
214+
.await
215+
.unwrap();
206216

207217
// When we approve a delegate.
208218

@@ -226,5 +236,11 @@ async fn approve_frozen() {
226236
);
227237
let result = context.banks_client.process_transaction(tx).await;
228238
let inner_error = result.err().unwrap().unwrap();
229-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
239+
assert_eq!(
240+
inner_error,
241+
solana_transaction_error::TransactionError::InstructionError(
242+
0,
243+
solana_instruction::error::InstructionError::Custom(17)
244+
)
245+
);
230246
}

p-token/tests/approve_checked.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ async fn _approve_checked_invalid_src() {
148148
);
149149
let result = context.banks_client.process_transaction(tx).await;
150150
let inner_error = result.err().unwrap().unwrap();
151-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
151+
assert_eq!(
152+
inner_error,
153+
solana_transaction_error::TransactionError::InstructionError(
154+
0,
155+
solana_instruction::error::InstructionError::InvalidAccountData
156+
)
157+
);
152158
}
153159

154160
#[tokio::test]
@@ -206,7 +212,11 @@ async fn approve_checked_frozen() {
206212
&[&context.payer, &freeze_authority],
207213
context.last_blockhash,
208214
);
209-
context.banks_client.process_transaction(freeze_tx).await.unwrap();
215+
context
216+
.banks_client
217+
.process_transaction(freeze_tx)
218+
.await
219+
.unwrap();
210220

211221
// When we approve a delegate.
212222

@@ -232,7 +242,13 @@ async fn approve_checked_frozen() {
232242
);
233243
let result = context.banks_client.process_transaction(tx).await;
234244
let inner_error = result.err().unwrap().unwrap();
235-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
245+
assert_eq!(
246+
inner_error,
247+
solana_transaction_error::TransactionError::InstructionError(
248+
0,
249+
solana_instruction::error::InstructionError::Custom(17)
250+
)
251+
);
236252
}
237253

238254
#[tokio::test]
@@ -297,7 +313,13 @@ async fn approve_checked_mint_mismatch() {
297313
);
298314
let result = context.banks_client.process_transaction(tx).await;
299315
let inner_error = result.err().unwrap().unwrap();
300-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
316+
assert_eq!(
317+
inner_error,
318+
solana_transaction_error::TransactionError::InstructionError(
319+
0,
320+
solana_instruction::error::InstructionError::Custom(3)
321+
)
322+
);
301323
}
302324

303325
#[tokio::test]
@@ -362,5 +384,11 @@ async fn approve_checked_incorrect_decimals() {
362384
);
363385
let result = context.banks_client.process_transaction(tx).await;
364386
let inner_error = result.err().unwrap().unwrap();
365-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18)));
387+
assert_eq!(
388+
inner_error,
389+
solana_transaction_error::TransactionError::InstructionError(
390+
0,
391+
solana_instruction::error::InstructionError::Custom(18)
392+
)
393+
);
366394
}

p-token/tests/burn.rs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ async fn _burn_invalid_source() {
114114

115115
// When we burn 50 tokens.
116116

117-
let burn_ix =
118-
spl_token::instruction::burn(&spl_token::ID, &Pubkey::new_unique(), &mint, &owner.pubkey(), &[], 50)
119-
.unwrap(); // Invalid sender
117+
let burn_ix = spl_token::instruction::burn(
118+
&spl_token::ID,
119+
&Pubkey::new_unique(),
120+
&mint,
121+
&owner.pubkey(),
122+
&[],
123+
50,
124+
)
125+
.unwrap(); // Invalid sender
120126

121127
let tx = Transaction::new_signed_with_payer(
122128
&[burn_ix],
@@ -126,7 +132,13 @@ async fn _burn_invalid_source() {
126132
);
127133
let result = context.banks_client.process_transaction(tx).await;
128134
let inner_error = result.err().unwrap().unwrap();
129-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
135+
assert_eq!(
136+
inner_error,
137+
solana_transaction_error::TransactionError::InstructionError(
138+
0,
139+
solana_instruction::error::InstructionError::InvalidAccountData
140+
)
141+
);
130142
}
131143

132144
#[tokio::test]
@@ -182,7 +194,11 @@ async fn burn_frozen_source() {
182194
&[&context.payer, &freeze_authority],
183195
context.last_blockhash,
184196
);
185-
context.banks_client.process_transaction(freeze_tx).await.unwrap();
197+
context
198+
.banks_client
199+
.process_transaction(freeze_tx)
200+
.await
201+
.unwrap();
186202

187203
// When we burn 50 tokens.
188204

@@ -198,7 +214,13 @@ async fn burn_frozen_source() {
198214
);
199215
let result = context.banks_client.process_transaction(tx).await;
200216
let inner_error = result.err().unwrap().unwrap();
201-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
217+
assert_eq!(
218+
inner_error,
219+
solana_transaction_error::TransactionError::InstructionError(
220+
0,
221+
solana_instruction::error::InstructionError::Custom(17)
222+
)
223+
);
202224
}
203225

204226
#[tokio::test]
@@ -230,7 +252,13 @@ async fn burn_native() {
230252
);
231253
let result = context.banks_client.process_transaction(tx).await;
232254
let inner_error = result.err().unwrap().unwrap();
233-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10)));
255+
assert_eq!(
256+
inner_error,
257+
solana_transaction_error::TransactionError::InstructionError(
258+
0,
259+
solana_instruction::error::InstructionError::Custom(10)
260+
)
261+
);
234262
}
235263

236264
#[tokio::test]
@@ -285,7 +313,13 @@ async fn burn_excessive_amount() {
285313
);
286314
let result = context.banks_client.process_transaction(tx).await;
287315
let inner_error = result.err().unwrap().unwrap();
288-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1)));
316+
assert_eq!(
317+
inner_error,
318+
solana_transaction_error::TransactionError::InstructionError(
319+
0,
320+
solana_instruction::error::InstructionError::Custom(1)
321+
)
322+
);
289323
}
290324

291325
#[tokio::test]
@@ -330,9 +364,15 @@ async fn burn_different_mint() {
330364

331365
// When we burn 50 tokens.
332366

333-
let burn_ix =
334-
spl_token::instruction::burn(&spl_token::ID, &account, &native_mint, &owner.pubkey(), &[], 50)
335-
.unwrap();
367+
let burn_ix = spl_token::instruction::burn(
368+
&spl_token::ID,
369+
&account,
370+
&native_mint,
371+
&owner.pubkey(),
372+
&[],
373+
50,
374+
)
375+
.unwrap();
336376

337377
let tx = Transaction::new_signed_with_payer(
338378
&[burn_ix],
@@ -342,5 +382,11 @@ async fn burn_different_mint() {
342382
);
343383
let result = context.banks_client.process_transaction(tx).await;
344384
let inner_error = result.err().unwrap().unwrap();
345-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
385+
assert_eq!(
386+
inner_error,
387+
solana_transaction_error::TransactionError::InstructionError(
388+
0,
389+
solana_instruction::error::InstructionError::Custom(3)
390+
)
391+
);
346392
}

p-token/tests/burn_checked.rs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ async fn _burn_checked_invalid_source() {
140140
);
141141
let result = context.banks_client.process_transaction(tx).await;
142142
let inner_error = result.err().unwrap().unwrap();
143-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData));
143+
assert_eq!(
144+
inner_error,
145+
solana_transaction_error::TransactionError::InstructionError(
146+
0,
147+
solana_instruction::error::InstructionError::InvalidAccountData
148+
)
149+
);
144150
}
145151

146152
#[tokio::test]
@@ -196,7 +202,11 @@ async fn burn_checked_frozen_source() {
196202
&[&context.payer, &freeze_authority],
197203
context.last_blockhash,
198204
);
199-
context.banks_client.process_transaction(freeze_tx).await.unwrap();
205+
context
206+
.banks_client
207+
.process_transaction(freeze_tx)
208+
.await
209+
.unwrap();
200210

201211
// When we burn 50 tokens.
202212

@@ -219,7 +229,13 @@ async fn burn_checked_frozen_source() {
219229
);
220230
let result = context.banks_client.process_transaction(tx).await;
221231
let inner_error = result.err().unwrap().unwrap();
222-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17)));
232+
assert_eq!(
233+
inner_error,
234+
solana_transaction_error::TransactionError::InstructionError(
235+
0,
236+
solana_instruction::error::InstructionError::Custom(17)
237+
)
238+
);
223239
}
224240

225241
#[tokio::test]
@@ -258,7 +274,13 @@ async fn burn_checked_native() {
258274
);
259275
let result = context.banks_client.process_transaction(tx).await;
260276
let inner_error = result.err().unwrap().unwrap();
261-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10)));
277+
assert_eq!(
278+
inner_error,
279+
solana_transaction_error::TransactionError::InstructionError(
280+
0,
281+
solana_instruction::error::InstructionError::Custom(10)
282+
)
283+
);
262284
}
263285

264286
#[tokio::test]
@@ -320,7 +342,13 @@ async fn burn_checked_excessive_amount() {
320342
);
321343
let result = context.banks_client.process_transaction(tx).await;
322344
let inner_error = result.err().unwrap().unwrap();
323-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1)));
345+
assert_eq!(
346+
inner_error,
347+
solana_transaction_error::TransactionError::InstructionError(
348+
0,
349+
solana_instruction::error::InstructionError::Custom(1)
350+
)
351+
);
324352
}
325353

326354
#[tokio::test]
@@ -384,7 +412,13 @@ async fn burn_checked_different_mint() {
384412
);
385413
let result = context.banks_client.process_transaction(tx).await;
386414
let inner_error = result.err().unwrap().unwrap();
387-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3)));
415+
assert_eq!(
416+
inner_error,
417+
solana_transaction_error::TransactionError::InstructionError(
418+
0,
419+
solana_instruction::error::InstructionError::Custom(3)
420+
)
421+
);
388422
}
389423

390424
#[tokio::test]
@@ -446,5 +480,11 @@ async fn burn_checked_incorrect_decimals() {
446480
);
447481
let result = context.banks_client.process_transaction(tx).await;
448482
let inner_error = result.err().unwrap().unwrap();
449-
assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18)));
483+
assert_eq!(
484+
inner_error,
485+
solana_transaction_error::TransactionError::InstructionError(
486+
0,
487+
solana_instruction::error::InstructionError::Custom(18)
488+
)
489+
);
450490
}

0 commit comments

Comments
 (0)