Skip to content

Commit d2e0ed7

Browse files
committed
fixing PR comments
1 parent 5cbc985 commit d2e0ed7

2 files changed

Lines changed: 153 additions & 149 deletions

File tree

solana/programs/bridge/src/base_to_solana/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ mod private {
3737
use super::*;
3838

3939
#[constant]
40+
// This is for registering output roots test
41+
// pub const TRUSTED_ORACLE: Pubkey = pubkey!("6FfuqkJTptvr6dCZnyp3tq3M4HkvyTE5DHyvqC537Lqt");
4042
pub const TRUSTED_ORACLE: Pubkey = pubkey!("CB8GXDdZDSD5uqfeow1qfp48ouayxXGpw7ycmoovuQMX");
4143

4244
#[constant]

solana/programs/bridge/src/base_to_solana/instructions/register_output_root.rs

Lines changed: 151 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ pub struct RegisterOutputRoot<'info> {
1414
#[account(mut, address = TRUSTED_ORACLE @ RegisterOutputRootError::Unauthorized)]
1515
pub payer: Signer<'info>,
1616

17-
#[account(address = TRUSTED_VALIDATOR @ RegisterOutputRootError::Unauthorized)]
18-
pub validator: Signer<'info>,
17+
// TODO: Uncomment this when we have a trusted validator
18+
// #[account(address = TRUSTED_VALIDATOR @ RegisterOutputRootError::Unauthorized)]
19+
// pub validator: Signer<'info>,
1920

2021
#[account(
2122
init,
@@ -60,160 +61,161 @@ pub enum RegisterOutputRootError {
6061
IncorrectBlockNumber,
6162
}
6263

63-
#[cfg(test)]
64-
mod tests {
65-
use super::*;
64+
// TODO: Uncomment this when we have a trusted validator
65+
// #[cfg(test)]
66+
// mod tests {
67+
// use super::*;
6668

67-
// Test-only trusted validator constant
68-
const TRUSTED_ORACLE_TEST: Pubkey = pubkey!("6FfuqkJTptvr6dCZnyp3tq3M4HkvyTE5DHyvqC537Lqt");
69-
const TRUSTED_VALIDATOR_TEST: Pubkey = pubkey!("9n3vTKJ49M4Xk3MhiCZY4LxXAdeEaDMVMuGxDwt54Hgx");
70-
use anchor_lang::{
71-
solana_program::{
72-
example_mocks::solana_sdk::system_program, instruction::Instruction,
73-
native_token::LAMPORTS_PER_SOL,
74-
},
75-
InstructionData,
76-
};
77-
use anchor_lang::solana_program::instruction::AccountMeta;
78-
use litesvm::LiteSVM;
79-
use solana_keypair::Keypair;
80-
use solana_message::Message;
81-
use solana_signer::Signer;
82-
use solana_transaction::Transaction;
83-
84-
use crate::{
85-
accounts, instruction::RegisterOutputRoot, test_utils::mock_clock, ID,
86-
common::BRIDGE_SEED,
87-
};
88-
89-
fn setup_bridge_and_svm() -> (LiteSVM, Keypair, Pubkey) {
90-
let mut svm = LiteSVM::new();
91-
svm.add_program_from_file(ID, "../../target/deploy/bridge.so")
92-
.unwrap();
93-
94-
// Create test accounts
95-
let payer = Keypair::new();
96-
let payer_pk = payer.pubkey();
97-
svm.airdrop(&payer_pk, LAMPORTS_PER_SOL * 10).unwrap();
98-
99-
// Mock the clock
100-
let timestamp = 1747440000; // May 16th, 2025
101-
mock_clock(&mut svm, timestamp);
102-
103-
// Find the Bridge PDA
104-
let bridge_pda = Pubkey::find_program_address(&[BRIDGE_SEED], &ID).0;
105-
106-
// Initialize the bridge first
107-
let accounts = accounts::Initialize {
108-
payer: payer_pk,
109-
bridge: bridge_pda,
110-
system_program: system_program::ID,
111-
}
112-
.to_account_metas(None);
113-
114-
let ix = Instruction {
115-
program_id: ID,
116-
accounts,
117-
data: crate::instruction::Initialize {}.data(),
118-
};
119-
120-
let tx = Transaction::new(
121-
&[&payer],
122-
Message::new(&[ix], Some(&payer_pk)),
123-
svm.latest_blockhash(),
124-
);
125-
126-
svm.send_transaction(tx).unwrap();
127-
128-
(svm, payer, bridge_pda)
129-
}
130-
131-
#[test]
132-
fn test_register_output_root_with_trusted_validator() {
133-
let (mut svm, _regular_payer, bridge_pda) = setup_bridge_and_svm();
134-
135-
// Create test trusted oracle keypair
136-
let test_oracle_keypair = Keypair::from_bytes(&[
137-
169,46,7,83,108,249,201,221,43,19,226,141,187,150,2,108,88,89,47,87,103,22,105,135,249,146,55,84,129,218,105,66,
138-
78,12,144,20,159,189,227,58,36,89,213,181,252,139,164,54,7,39,121,246,107,77,168,231,40,53,10,133,197,117,180,15
139-
]).unwrap();
69+
// // Test-only trusted validator constant
70+
// const TRUSTED_ORACLE_TEST: Pubkey = pubkey!("6FfuqkJTptvr6dCZnyp3tq3M4HkvyTE5DHyvqC537Lqt");
71+
// const TRUSTED_VALIDATOR_TEST: Pubkey = pubkey!("9n3vTKJ49M4Xk3MhiCZY4LxXAdeEaDMVMuGxDwt54Hgx");
72+
// use anchor_lang::{
73+
// solana_program::{
74+
// example_mocks::solana_sdk::system_program, instruction::Instruction,
75+
// native_token::LAMPORTS_PER_SOL,
76+
// },
77+
// InstructionData,
78+
// };
79+
// use anchor_lang::solana_program::instruction::AccountMeta;
80+
// use litesvm::LiteSVM;
81+
// use solana_keypair::Keypair;
82+
// use solana_message::Message;
83+
// use solana_signer::Signer;
84+
// use solana_transaction::Transaction;
85+
86+
// use crate::{
87+
// accounts, instruction::RegisterOutputRoot, test_utils::mock_clock, ID,
88+
// common::BRIDGE_SEED,
89+
// };
90+
91+
// fn setup_bridge_and_svm() -> (LiteSVM, Keypair, Pubkey) {
92+
// let mut svm = LiteSVM::new();
93+
// svm.add_program_from_file(ID, "../../target/deploy/bridge.so")
94+
// .unwrap();
95+
96+
// // Create test accounts
97+
// let payer = Keypair::new();
98+
// let payer_pk = payer.pubkey();
99+
// svm.airdrop(&payer_pk, LAMPORTS_PER_SOL * 10).unwrap();
100+
101+
// // Mock the clock
102+
// let timestamp = 1747440000; // May 16th, 2025
103+
// mock_clock(&mut svm, timestamp);
104+
105+
// // Find the Bridge PDA
106+
// let bridge_pda = Pubkey::find_program_address(&[BRIDGE_SEED], &ID).0;
107+
108+
// // Initialize the bridge first
109+
// let accounts = accounts::Initialize {
110+
// payer: payer_pk,
111+
// bridge: bridge_pda,
112+
// system_program: system_program::ID,
113+
// }
114+
// .to_account_metas(None);
115+
116+
// let ix = Instruction {
117+
// program_id: ID,
118+
// accounts,
119+
// data: crate::instruction::Initialize {}.data(),
120+
// };
121+
122+
// let tx = Transaction::new(
123+
// &[&payer],
124+
// Message::new(&[ix], Some(&payer_pk)),
125+
// svm.latest_blockhash(),
126+
// );
127+
128+
// svm.send_transaction(tx).unwrap();
129+
130+
// (svm, payer, bridge_pda)
131+
// }
132+
133+
// #[test]
134+
// fn test_register_output_root_with_trusted_validator() {
135+
// let (mut svm, _regular_payer, bridge_pda) = setup_bridge_and_svm();
136+
137+
// // Create test trusted oracle keypair
138+
// let test_oracle_keypair = Keypair::from_bytes(&[
139+
// 169,46,7,83,108,249,201,221,43,19,226,141,187,150,2,108,88,89,47,87,103,22,105,135,249,146,55,84,129,218,105,66,
140+
// 78,12,144,20,159,189,227,58,36,89,213,181,252,139,164,54,7,39,121,246,107,77,168,231,40,53,10,133,197,117,180,15
141+
// ]).unwrap();
140142

141-
// Create our test trusted validator keypair
142-
let test_validator_keypair = Keypair::from_bytes(&[
143-
7,203,36,165,34,16,183,13,229,220,44,231,46,32,229,21,245,102,103,75,136,63,19,95,73,20,32,100,117,147,9,50,
144-
130,103,239,111,221,79,12,179,120,215,230,145,126,141,29,118,104,180,179,63,226,116,1,101,226,229,190,176,241,235,41,101
145-
]).unwrap();
143+
// // Create our test trusted validator keypair
144+
// let test_validator_keypair = Keypair::from_bytes(&[
145+
// 7,203,36,165,34,16,183,13,229,220,44,231,46,32,229,21,245,102,103,75,136,63,19,95,73,20,32,100,117,147,9,50,
146+
// 130,103,239,111,221,79,12,179,120,215,230,145,126,141,29,118,104,180,179,63,226,116,1,101,226,229,190,176,241,235,41,101
147+
// ]).unwrap();
146148

147-
// Verify keypairs match our constants
148-
assert_eq!(test_oracle_keypair.pubkey(), TRUSTED_ORACLE_TEST, "Test oracle pubkey must match TRUSTED_ORACLE_TEST constant");
149-
assert_eq!(test_validator_keypair.pubkey(), TRUSTED_VALIDATOR_TEST, "Test validator pubkey must match TRUSTED_VALIDATOR_TEST constant");
149+
// // Verify keypairs match our constants
150+
// assert_eq!(test_oracle_keypair.pubkey(), TRUSTED_ORACLE_TEST, "Test oracle pubkey must match TRUSTED_ORACLE_TEST constant");
151+
// assert_eq!(test_validator_keypair.pubkey(), TRUSTED_VALIDATOR_TEST, "Test validator pubkey must match TRUSTED_VALIDATOR_TEST constant");
150152

151-
// Airdrop to our test validator
152-
svm.airdrop(&test_oracle_keypair.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
153-
svm.airdrop(&test_validator_keypair.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
153+
// // Airdrop to our test validator
154+
// svm.airdrop(&test_oracle_keypair.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
155+
// svm.airdrop(&test_validator_keypair.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
154156

155-
let output_root = [1u8; 32];
156-
let block_number = 300u64;
157-
158-
// Find the output root PDA
159-
let output_root_pda = Pubkey::find_program_address(
160-
&[OUTPUT_ROOT_SEED, &block_number.to_le_bytes()],
161-
&ID,
162-
).0;
163-
164-
// Build the RegisterOutputRoot instruction using the test validator
165-
let accounts = accounts::RegisterOutputRoot {
166-
payer: test_oracle_keypair.pubkey(),
167-
validator: test_validator_keypair.pubkey(),
168-
root: output_root_pda,
169-
bridge: bridge_pda,
170-
system_program: system_program::ID,
171-
}
172-
.to_account_metas(None);
173-
174-
let ix = Instruction {
175-
program_id: ID,
176-
accounts,
177-
data: RegisterOutputRoot {
178-
output_root,
179-
block_number,
180-
}.data(),
181-
};
182-
183-
let tx = Transaction::new(
184-
&[&test_oracle_keypair, &test_validator_keypair],
185-
Message::new(&[ix], Some(&test_oracle_keypair.pubkey())),
186-
svm.latest_blockhash(),
187-
);
188-
189-
// Execute the transaction
190-
let result = svm.send_transaction(tx);
157+
// let output_root = [1u8; 32];
158+
// let block_number = 300u64;
159+
160+
// // Find the output root PDA
161+
// let output_root_pda = Pubkey::find_program_address(
162+
// &[OUTPUT_ROOT_SEED, &block_number.to_le_bytes()],
163+
// &ID,
164+
// ).0;
165+
166+
// // Build the RegisterOutputRoot instruction using the test validator
167+
// let accounts = accounts::RegisterOutputRoot {
168+
// payer: test_oracle_keypair.pubkey(),
169+
// validator: test_validator_keypair.pubkey(),
170+
// root: output_root_pda,
171+
// bridge: bridge_pda,
172+
// system_program: system_program::ID,
173+
// }
174+
// .to_account_metas(None);
175+
176+
// let ix = Instruction {
177+
// program_id: ID,
178+
// accounts,
179+
// data: RegisterOutputRoot {
180+
// output_root,
181+
// block_number,
182+
// }.data(),
183+
// };
184+
185+
// let tx = Transaction::new(
186+
// &[&test_oracle_keypair, &test_validator_keypair],
187+
// Message::new(&[ix], Some(&test_oracle_keypair.pubkey())),
188+
// svm.latest_blockhash(),
189+
// );
190+
191+
// // Execute the transaction
192+
// let result = svm.send_transaction(tx);
191193

192-
match result {
193-
Ok(_) => {
194-
println!("✅ SUCCESS! Trusted validator approach works!");
194+
// match result {
195+
// Ok(_) => {
196+
// println!("✅ SUCCESS! Trusted validator approach works!");
195197

196-
// Verify the output root was created correctly
197-
let output_root_account = svm.get_account(&output_root_pda).expect("Output root should be created");
198-
assert_eq!(output_root_account.owner, ID);
198+
// // Verify the output root was created correctly
199+
// let output_root_account = svm.get_account(&output_root_pda).expect("Output root should be created");
200+
// assert_eq!(output_root_account.owner, ID);
199201

200-
// Deserialize and verify the output root data
201-
let output_root_data = OutputRoot::try_deserialize(&mut &output_root_account.data[..]).unwrap();
202-
assert_eq!(output_root_data.root, output_root);
202+
// // Deserialize and verify the output root data
203+
// let output_root_data = OutputRoot::try_deserialize(&mut &output_root_account.data[..]).unwrap();
204+
// assert_eq!(output_root_data.root, output_root);
203205

204-
// Verify the bridge state was updated
205-
let bridge_account = svm.get_account(&bridge_pda).expect("Bridge should exist");
206-
let bridge_data = Bridge::try_deserialize(&mut &bridge_account.data[..]).unwrap();
207-
assert_eq!(bridge_data.base_block_number, block_number);
206+
// // Verify the bridge state was updated
207+
// let bridge_account = svm.get_account(&bridge_pda).expect("Bridge should exist");
208+
// let bridge_data = Bridge::try_deserialize(&mut &bridge_account.data[..]).unwrap();
209+
// assert_eq!(bridge_data.base_block_number, block_number);
208210

209-
println!("✅ Output root PDA created successfully!");
210-
println!("✅ Bridge state updated correctly!");
211-
}
212-
Err(e) => {
213-
let error_str = format!("{:?}", e);
214-
println!("❌ Transaction failed: {}", error_str);
215-
panic!("Expected transaction to succeed, but got error: {}", error_str);
216-
}
217-
}
218-
}
219-
}
211+
// println!("✅ Output root PDA created successfully!");
212+
// println!("✅ Bridge state updated correctly!");
213+
// }
214+
// Err(e) => {
215+
// let error_str = format!("{:?}", e);
216+
// println!("❌ Transaction failed: {}", error_str);
217+
// panic!("Expected transaction to succeed, but got error: {}", error_str);
218+
// }
219+
// }
220+
// }
221+
// }

0 commit comments

Comments
 (0)