-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add non-anchor tests and update anchor tests
- Loading branch information
Vara Prasad Bandaru
committed
Mar 5, 2024
1 parent
c392cf3
commit 7210d7e
Showing
13 changed files
with
174 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lints/missing_signer_check/ui/insecure-non-anchor/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "signer-authorization-insecure-non-anchor" | ||
version = "0.1.0" | ||
description = "" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "signer_authorization_insecure_non_anchor" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
cpi = ["no-entrypoint"] | ||
default = [] | ||
|
||
[dependencies] | ||
solana-program = "1.18.4" | ||
|
||
[workspace] |
29 changes: 29 additions & 0 deletions
29
lints/missing_signer_check/ui/insecure-non-anchor/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use solana_program::msg; | ||
use solana_program::{ | ||
account_info::{next_account_info, AccountInfo}, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
instruction_data: &[u8], | ||
) -> ProgramResult { | ||
if instruction_data.len() != 0 { | ||
return Err(ProgramError::InvalidInstructionData); | ||
} | ||
log_message(accounts) | ||
} | ||
|
||
pub fn log_message(accounts: &[AccountInfo]) -> ProgramResult { | ||
let authority = next_account_info(&mut accounts.iter())?; | ||
msg!("GM {:?}", authority); | ||
Ok(()) | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
lints/missing_signer_check/ui/insecure-non-anchor/src/lib.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: this function lacks a use of `is_signer` | ||
--> $DIR/lib.rs:22:1 | ||
| | ||
LL | / pub fn log_message(accounts: &[AccountInfo]) -> ProgramResult { | ||
LL | | let authority = next_account_info(&mut accounts.iter())?; | ||
LL | | msg!("GM {:?}", authority); | ||
LL | | Ok(()) | ||
LL | | } | ||
| |_^ | ||
| | ||
= note: `-D missing-signer-check` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(missing_signer_check)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lints/missing_signer_check/ui/secure-non-anchor/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "signer-authorization-secure-non-anchor" | ||
version = "0.1.0" | ||
description = "" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "signer_authorization_secure_non_anchor" | ||
|
||
[features] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
cpi = ["no-entrypoint"] | ||
default = [] | ||
|
||
[dependencies] | ||
solana-program = "1.18.4" | ||
|
||
[workspace] |
32 changes: 32 additions & 0 deletions
32
lints/missing_signer_check/ui/secure-non-anchor/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use solana_program::msg; | ||
use solana_program::{ | ||
account_info::{next_account_info, AccountInfo}, | ||
entrypoint, | ||
entrypoint::ProgramResult, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
entrypoint!(process_instruction); | ||
fn process_instruction( | ||
_program_id: &Pubkey, | ||
accounts: &[AccountInfo], | ||
instruction_data: &[u8], | ||
) -> ProgramResult { | ||
if instruction_data.len() != 0 { | ||
return Err(ProgramError::InvalidInstructionData); | ||
} | ||
log_message(accounts) | ||
} | ||
|
||
pub fn log_message(accounts: &[AccountInfo]) -> ProgramResult { | ||
let authority = next_account_info(&mut accounts.iter())?; | ||
if !authority.is_signer { | ||
return Err(ProgramError::MissingRequiredSignature); | ||
} | ||
msg!("GM {:?}", authority); | ||
Ok(()) | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn main() {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: Account `authority` might need to be a signer | ||
--> $DIR/lib.rs:21:5 | ||
| | ||
LL | pub struct LogMessage<'info> { | ||
| ---------- Accounts of this instruction | ||
LL | authority: AccountInfo<'info>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D missing-signer-check` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(missing_signer_check)]` | ||
|
||
error: aborting due to 1 previous error | ||
|