-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix ed25519 builtin program handling (#23182) * Fix ed25519 builtin program handling * Fix tests * Add integration tests for processing transactions with ed25519 ixs * Fix another test * fix formatting (cherry picked from commit 813725d) * fix tests Co-authored-by: Justin Starry <[email protected]> Co-authored-by: Jack May <[email protected]>
- Loading branch information
1 parent
c08af09
commit 2120ef5
Showing
9 changed files
with
182 additions
and
17 deletions.
There are no files selected for viewing
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
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,19 @@ | ||
[package] | ||
name = "solana-ed25519-program-tests" | ||
version = "1.9.7" | ||
authors = ["Solana Maintainers <[email protected]>"] | ||
repository = "https://github.com/solana-labs/solana" | ||
license = "Apache-2.0" | ||
homepage = "https://solana.com/" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dev-dependencies] | ||
assert_matches = "1.5.0" | ||
ed25519-dalek = "=1.0.1" | ||
rand = "0.7.0" | ||
solana-program-test = { path = "../../program-test", version = "=1.9.7" } | ||
solana-sdk = { path = "../../sdk", version = "=1.9.7" } | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] |
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,87 @@ | ||
use { | ||
assert_matches::assert_matches, | ||
rand::thread_rng, | ||
solana_program_test::*, | ||
solana_sdk::{ | ||
ed25519_instruction::new_ed25519_instruction, | ||
feature_set, | ||
signature::Signer, | ||
transaction::{Transaction, TransactionError}, | ||
transport::TransportError, | ||
}, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_success() { | ||
let mut context = ProgramTest::default().start_with_context().await; | ||
|
||
let client = &mut context.banks_client; | ||
let payer = &context.payer; | ||
let recent_blockhash = context.last_blockhash; | ||
|
||
let privkey = ed25519_dalek::Keypair::generate(&mut thread_rng()); | ||
let message_arr = b"hello"; | ||
let instruction = new_ed25519_instruction(&privkey, message_arr); | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction], | ||
Some(&payer.pubkey()), | ||
&[payer], | ||
recent_blockhash, | ||
); | ||
|
||
assert_matches!(client.process_transaction(transaction).await, Ok(())); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_failure() { | ||
let mut context = ProgramTest::default().start_with_context().await; | ||
|
||
let client = &mut context.banks_client; | ||
let payer = &context.payer; | ||
let recent_blockhash = context.last_blockhash; | ||
|
||
let privkey = ed25519_dalek::Keypair::generate(&mut thread_rng()); | ||
let message_arr = b"hello"; | ||
let mut instruction = new_ed25519_instruction(&privkey, message_arr); | ||
|
||
instruction.data[0] += 1; | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction], | ||
Some(&payer.pubkey()), | ||
&[payer], | ||
recent_blockhash, | ||
); | ||
|
||
assert_matches!( | ||
client.process_transaction(transaction).await, | ||
Err(TransportError::TransactionError( | ||
TransactionError::InvalidAccountIndex | ||
)) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_success_call_builtin_program() { | ||
let mut program_test = ProgramTest::default(); | ||
program_test.deactivate_feature(feature_set::prevent_calling_precompiles_as_programs::id()); | ||
let mut context = program_test.start_with_context().await; | ||
|
||
let client = &mut context.banks_client; | ||
let payer = &context.payer; | ||
let recent_blockhash = context.last_blockhash; | ||
|
||
let privkey = ed25519_dalek::Keypair::generate(&mut thread_rng()); | ||
let message_arr = b"hello"; | ||
let instruction = new_ed25519_instruction(&privkey, message_arr); | ||
|
||
let transaction = Transaction::new_signed_with_payer( | ||
&[instruction], | ||
Some(&payer.pubkey()), | ||
&[payer], | ||
recent_blockhash, | ||
); | ||
|
||
assert_matches!(client.process_transaction(transaction).await, Ok(())); | ||
} |
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
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