gemachain_ed25519_program/
lib.rs1use gemachain_sdk::{
2 instruction::InstructionError, process_instruction::InvokeContext, pubkey::Pubkey,
3};
4
5pub fn process_instruction(
6 _program_id: &Pubkey,
7 _data: &[u8],
8 _invoke_context: &mut dyn InvokeContext,
9) -> Result<(), InstructionError> {
10 Ok(())
12}
13
14#[cfg(test)]
15pub mod test {
16 use rand::{thread_rng, Rng};
17 use gemachain_sdk::{
18 ed25519_instruction::new_ed25519_instruction,
19 feature_set::FeatureSet,
20 hash::Hash,
21 signature::{Keypair, Signer},
22 transaction::Transaction,
23 };
24 use std::sync::Arc;
25
26 #[test]
27 fn test_ed25519() {
28 gemachain_logger::setup();
29
30 let privkey = ed25519_dalek::Keypair::generate(&mut thread_rng());
31 let message_arr = b"hello";
32 let mut instruction = new_ed25519_instruction(&privkey, message_arr);
33 let mint_keypair = Keypair::new();
34 let feature_set = Arc::new(FeatureSet::all_enabled());
35
36 let tx = Transaction::new_signed_with_payer(
37 &[instruction.clone()],
38 Some(&mint_keypair.pubkey()),
39 &[&mint_keypair],
40 Hash::default(),
41 );
42
43 assert!(tx.verify_precompiles(&feature_set).is_ok());
44
45 let index = thread_rng().gen_range(0, instruction.data.len());
46 instruction.data[index] = instruction.data[index].wrapping_add(12);
47 let tx = Transaction::new_signed_with_payer(
48 &[instruction],
49 Some(&mint_keypair.pubkey()),
50 &[&mint_keypair],
51 Hash::default(),
52 );
53 assert!(tx.verify_precompiles(&feature_set).is_err());
54 }
55}