Skip to content

Commit d642880

Browse files
author
Bengt Lofgren
committed
added filestrings to most places
1 parent d42b43c commit d642880

File tree

12 files changed

+194
-16
lines changed

12 files changed

+194
-16
lines changed

solana/modules/matching-engine-testing/tests/testing_engine/setup.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,19 @@ pub struct TestingActors {
581581
}
582582

583583
impl TestingActors {
584+
/// Create a new TestingActors struct
585+
///
586+
/// # Arguments
587+
///
588+
/// * `owner_keypair_path` - The path to the owner keypair
589+
///
590+
/// # Returns
584591
pub fn new(owner_keypair_path: &str) -> Self {
585592
let owner_kp = Rc::new(read_keypair_from_file(owner_keypair_path));
586593
let owner = TestingActor::new(owner_kp.clone(), None);
587594
let owner_assistant = TestingActor::new(owner_kp.clone(), None);
588595
let fee_recipient = TestingActor::new(Rc::new(Keypair::new()), None);
589596
let relayer = TestingActor::new(Rc::new(Keypair::new()), None);
590-
// TODO: Change player 1 solver to use the keyfile
591597
let mut solvers = vec![];
592598
solvers.extend(vec![
593599
Solver::new(Rc::new(Keypair::new()), None),
@@ -605,6 +611,7 @@ impl TestingActors {
605611
}
606612
}
607613

614+
/// Get the actors that should have token accounts
608615
pub fn token_account_actors(&mut self) -> Vec<&mut TestingActor> {
609616
let mut actors = Vec::new();
610617
actors.push(&mut self.fee_recipient);
@@ -644,7 +651,7 @@ impl TestingActors {
644651

645652
/// Add solvers to the testing actors
646653
#[allow(dead_code)]
647-
async fn add_solvers(
654+
pub async fn add_solvers(
648655
&mut self,
649656
test_context: &mut ProgramTestContext,
650657
num_solvers: usize,
@@ -675,6 +682,13 @@ pub enum ShimMode {
675682
VerifyAndPostSignature,
676683
}
677684

685+
/// The direction of the transfer
686+
///
687+
/// # Enums
688+
///
689+
/// * `FromArbitrumToEthereum` - The direction of the transfer from Arbitrum to Ethereum
690+
/// * `FromEthereumToArbitrum` - The direction of the transfer from Ethereum to Arbitrum
691+
/// * `Other` - The direction of the transfer is not supported
678692
#[allow(dead_code)]
679693
#[derive(Copy, Clone, PartialEq, Eq)]
680694
pub enum TransferDirection {

solana/modules/matching-engine-testing/tests/utils/account_fixtures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! # Account Fixtures
2+
//!
3+
//! This module provides fixtures for creating accounts in the test environment.
4+
//! It includes methods for creating accounts and for reading a keypair from a JSON fixture file.
5+
//! These accounts are located in the `tests/fixtures/accounts` directory.
6+
17
use anchor_lang::prelude::{pubkey, Pubkey};
28
use anyhow::Result as AnyhowResult;
39
use serde_json::Value;

solana/modules/matching-engine-testing/tests/utils/airdrop.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ use super::constants;
99
///
1010
/// # Arguments
1111
///
12-
/// * `test_context` - The test context
12+
/// * `test_context` - The program test context
1313
/// * `recipient` - The recipient of the airdrop
1414
/// * `amount` - The amount of SOL to airdrop
15-
1615
pub async fn airdrop(test_context: &mut ProgramTestContext, recipient: &Pubkey, amount: u64) {
1716
// Create the transfer instruction with values from the context
1817
let transfer_ix = system_instruction::transfer(&test_context.payer.pubkey(), recipient, amount);
@@ -32,6 +31,13 @@ pub async fn airdrop(test_context: &mut ProgramTestContext, recipient: &Pubkey,
3231
.unwrap();
3332
}
3433

34+
/// Airdrops USDC to a given recipient
35+
///
36+
/// # Arguments
37+
///
38+
/// * `test_context` - The program test context
39+
/// * `recipient_ata` - The recipient's ATA
40+
/// * `amount` - The amount of USDC to airdrop
3541
pub async fn airdrop_usdc(
3642
test_context: &mut ProgramTestContext,
3743
recipient_ata: &Pubkey,

solana/modules/matching-engine-testing/tests/utils/auction.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ use super::Chain;
66
use crate::testing_engine::setup::{TestingActor, TestingContext, TransferDirection};
77
use anyhow::{anyhow, Result as AnyhowResult};
88
use matching_engine::state::{Auction, AuctionInfo};
9+
10+
/// A struct representing the accounts for an auction
11+
///
12+
/// # Fields
13+
///
14+
/// * `posted_fast_vaa` - The address of the posted fast VAA
15+
/// * `offer_token` - The address of the offer token
16+
/// * `actor` - The actor of the auction (who places the initial offer, improves it, executes it, or settles it)
17+
/// * `auction_config` - The address of the auction config
18+
/// * `from_router_endpoint` - The address of the router endpoint for the source chain
19+
/// * `to_router_endpoint` - The address of the router endpoint for the destination chain
20+
/// * `custodian` - The address of the custodian
21+
/// * `usdc_mint` - The usdc mint address
922
#[derive(Clone)]
1023
pub struct AuctionAccounts {
1124
pub posted_fast_vaa: Option<Pubkey>,
@@ -178,6 +191,12 @@ impl ActiveAuctionState {
178191
}
179192
}
180193

194+
/// Compares two auctions to assert they are equal
195+
///
196+
/// # Arguments
197+
///
198+
/// * `auction_1` - The first auction
199+
/// * `auction_2` - The second auction
181200
pub async fn compare_auctions(auction_1: &Auction, auction_2: &Auction) {
182201
let auction_1_info = auction_1.info.unwrap();
183202
let auction_2_info = auction_2.info.unwrap();

solana/modules/matching-engine-testing/tests/utils/cctp_message.rs

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub enum TokenMessengerError {
131131
InvalidTokenMint,
132132
}
133133

134-
//https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/token-messenger-minter/src/token_messenger/state.rs#L35-L38
134+
// Imported from https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/token-messenger-minter/src/token_messenger/state.rs#L35-L38
135135
#[derive(Debug, InitSpace)]
136136
pub struct CctpRemoteTokenMessenger {
137137
pub domain: u32, // Big endian
@@ -147,7 +147,7 @@ impl From<&RemoteTokenMessenger> for CctpRemoteTokenMessenger {
147147
}
148148
}
149149

150-
// https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/message-transmitter/src/message.rs#L30
150+
// Imported from https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/message-transmitter/src/message.rs#L30
151151
#[derive(Clone, Debug)]
152152
pub struct Message<'a> {
153153
data: &'a [u8],
@@ -296,7 +296,7 @@ impl<'a> Message<'a> {
296296
}
297297
}
298298

299-
// https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/token-messenger-minter/src/token_messenger/burn_message.rs#L26
299+
// Imported from https://github.com/circlefin/solana-cctp-contracts/blob/4477f889732209dfc9a08b3aeaeb9203a324055c/programs/token-messenger-minter/src/token_messenger/burn_message.rs#L26
300300
#[derive(Clone, Debug)]
301301
pub struct BurnMessage<'a> {
302302
data: &'a [u8],
@@ -393,6 +393,15 @@ pub struct CircleAttester {
393393
}
394394

395395
impl CircleAttester {
396+
/// Creates an attestation for a given message
397+
///
398+
/// # Arguments
399+
///
400+
/// * `message` - The message to attest to
401+
///
402+
/// # Returns
403+
///
404+
/// A 65 byte array containing the attestation and the recovery id in the last byte
396405
pub fn create_attestation(&self, message: &[u8]) -> [u8; 65] {
397406
// Sign the message hash with the guardian key
398407
let secp = secp256k1::SECP256K1;
@@ -425,6 +434,14 @@ impl Default for CircleAttester {
425434
}
426435
}
427436

437+
/// A struct representing a CCTP token burn message
438+
///
439+
/// # Fields
440+
///
441+
/// * `destination_cctp_domain` - The destination CCTP domain
442+
/// * `cctp_message` - The CCTP message
443+
/// * `encoded_cctp_burn_message` - The encoded CCTP burn message
444+
/// * `cctp_attestation` - The CCTP attestation
428445
pub struct CctpTokenBurnMessage {
429446
pub destination_cctp_domain: u32,
430447
pub cctp_message: CctpMessage,
@@ -440,6 +457,17 @@ impl CctpTokenBurnMessage {
440457
}
441458
}
442459

460+
/// A struct representing a CCTP message header
461+
///
462+
/// # Fields
463+
///
464+
/// * `version` - The version of the CCTP message
465+
/// * `source_domain` - The source CCTP domain
466+
/// * `destination_domain` - The destination CCTP domain
467+
/// * `nonce` - The nonce of the CCTP message
468+
/// * `sender` - The sender of the CCTP message
469+
/// * `recipient` - The recipient of the CCTP message
470+
/// * `destination_caller` - The destination caller of the CCTP message
443471
pub struct CctpMessageHeader {
444472
pub version: u32,
445473
pub source_domain: u32,
@@ -470,6 +498,15 @@ impl CctpMessageHeader {
470498
}
471499
}
472500

501+
/// A struct representing a CCTP message body
502+
///
503+
/// # Fields
504+
///
505+
/// * `version` - The version of the CCTP message
506+
/// * `burn_token_address` - The address of the token to burn
507+
/// * `mint_recipient` - The address of the recipient of the token
508+
/// * `amount` - The amount of the token to burn
509+
/// * `message_sender` - The address of the sender of the message
473510
pub struct CctpMessageBody {
474511
pub version: u32,
475512
pub burn_token_address: [u8; 32],
@@ -520,6 +557,12 @@ impl From<&BurnMessage<'_>> for CctpMessageBody {
520557
}
521558
}
522559

560+
/// A struct representing a CCTP message
561+
///
562+
/// # Fields
563+
///
564+
/// * `header` - The header of the CCTP message
565+
/// * `body` - The body of the CCTP message
523566
pub struct CctpMessage {
524567
pub header: CctpMessageHeader,
525568
pub body: CctpMessageBody,
@@ -535,6 +578,18 @@ impl CctpMessage {
535578
}
536579
}
537580

581+
/// Crafts a CCTP token burn message
582+
///
583+
/// # Arguments
584+
///
585+
/// * `test_context` - The test context
586+
/// * `source_cctp_domain` - The source CCTP domain
587+
/// * `cctp_nonce` - The nonce of the CCTP message
588+
/// * `amount` - The amount of the token to burn
589+
/// * `message_transmitter_config_pubkey` - The pubkey of the message transmitter config
590+
/// * `remote_token_messenger` - The remote token messenger
591+
/// * `cctp_mint_recipient` - The address of the recipient of the token
592+
/// * `custodian_address` - The address of the custodian
538593
#[allow(clippy::too_many_arguments)]
539594
pub async fn craft_cctp_token_burn_message(
540595
test_context: &mut ProgramTestContext,
@@ -612,6 +667,15 @@ pub async fn craft_cctp_token_burn_message(
612667
})
613668
}
614669

670+
/// Converts an Ethereum address to a wormhole universal address
671+
///
672+
/// # Arguments
673+
///
674+
/// * `eth_address` - The Ethereum address to convert
675+
///
676+
/// # Returns
677+
///
678+
/// A 32-byte array containing the universal address
615679
pub fn ethereum_address_to_universal(eth_address: &str) -> [u8; 32] {
616680
// Remove '0x' prefix if present
617681
let address_str = eth_address
@@ -629,6 +693,15 @@ pub fn ethereum_address_to_universal(eth_address: &str) -> [u8; 32] {
629693
universal_address
630694
}
631695

696+
/// Gets the base fee for a deposit
697+
///
698+
/// # Arguments
699+
///
700+
/// * `deposit` - The deposit to get the base fee for
701+
///
702+
/// # Returns
703+
///
704+
/// The base fee for the deposit
632705
pub fn get_deposit_base_fee(deposit: &Deposit) -> u64 {
633706
let payload = deposit.payload.clone();
634707
let liquidity_layer_message = LiquidityLayerDepositMessage::parse(&payload).unwrap();
@@ -664,6 +737,12 @@ impl UsedNonces {
664737
}
665738
}
666739

740+
/// A struct representing a decoded CCTP message
741+
///
742+
/// # Fields
743+
///
744+
/// * `nonce` - The nonce of the CCTP message
745+
/// * `source_domain` - The source CCTP domain
667746
#[derive(Debug)]
668747
pub struct CctpMessageDecoded {
669748
pub nonce: u64,

solana/modules/matching-engine-testing/tests/utils/constants.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
#![allow(dead_code)]
22

3+
//! # Constants
4+
//!
5+
//! This module contains constants for the matching engine testing module.
6+
//!
7+
//! ## Exposed constants
8+
//!
9+
//! - `CORE_BRIDGE_PID` - The program ID of the core bridge
10+
//! - `CORE_BRIDGE_FEE_COLLECTOR` - The fee collector of the core bridge
11+
//! - `CORE_BRIDGE_CONFIG` - The config of the core bridge
12+
//! - `TOKEN_BRIDGE_PID` - The program ID of the token bridge
13+
//! - `TOKEN_BRIDGE_EMITTER_AUTHORITY` - The emitter authority of the token bridge
14+
//! - `TOKEN_BRIDGE_CUSTODY_AUTHORITY` - The custody authority of the token bridge
15+
//! - `TOKEN_BRIDGE_MINT_AUTHORITY` - The mint authority of the token bridge
16+
//! - `TOKEN_BRIDGE_TRANSFER_AUTHORITY` - The transfer authority of the token bridge
17+
//! - `USDC_MINT` - The mint address of USDC
18+
//! - `GUARDIAN_SECRET_KEY` - The guardian secret key
19+
//! - `TOKEN_ROUTER_PID` - The program ID of the token router
20+
//! - `CCTP_TOKEN_MESSENGER_MINTER_PID` - The program ID of the CCTP token messenger minter
21+
//! - `CCTP_MESSAGE_TRANSMITTER_PID` - The program ID of the CCTP message transmitter
22+
//! - `WORMHOLE_POST_MESSAGE_SHIM_PID` - The program ID of the Wormhole post message shim
23+
//! - `WORMHOLE_VERIFY_VAA_SHIM_PID` - The program ID of the Wormhole verify VAA shim
24+
//! - `WORMHOLE_POST_MESSAGE_SHIM_EVENT_AUTHORITY` - The event authority of the Wormhole post message shim
25+
//!
26+
//! ## Enums
27+
//!
28+
//! - `Chain` - An enum representing the different chains. Chain implements `as_cctp_domain` to get the CCTP domain for the chain.
29+
//!
30+
//! ## Examples
31+
//!
32+
//! ```rust
33+
//! use crate::constants::*;
34+
//! let eth_cctp_domain = Chain::Ethereum.as_cctp_domain();
35+
//! ```
36+
337
use solana_program::pubkey;
438
use solana_sdk::pubkey::Pubkey;
539
use solana_sdk::signature::Keypair;
@@ -79,36 +113,28 @@ pub const WORMHOLE_POST_MESSAGE_SHIM_EVENT_AUTHORITY_BUMP: u8 = 255;
79113
// pub const PLAYER_ONE_KEYPAIR_B64: &str = "4STrqllKVVva0Fphqyf++6uGTVReATBe2cI26oIuVBft77CQP9qQrMTU1nM9ql0EnCpSgmCmm20m8khMo9WdPQ==";
80114

81115
/// Keypairs as base58 strings (taken from consts.ts in ts tests using a converter)
82-
#[allow(dead_code)]
83116
pub const PAYER_KEYPAIR_B58: &str =
84117
"4NMwxzmYj2uvHuq8xoqhY8RXg0Pd5zkvmfWAL6YvbYFuViXVCBDK5Pru9GgqEVEZo6UXcPVH6rdR8JKgKxHGkXDp";
85-
#[allow(dead_code)]
86118
pub const OWNER_ASSISTANT_KEYPAIR_B58: &str =
87119
"2UbUgoidcNHxVEDG6ADNKGaGDqBTXTVw6B9pWvJtLNhbxcQDkdeEyBYBYYYxxDy92ckXUEaU9chWEGi5jc8Uc9e3";
88-
#[allow(dead_code)]
89120
pub const OWNER_KEYPAIR_B58: &str =
90121
"3M5rkG5DQVEGQFRtA1qruxPqJvYBbkGCdkCdB9ZjcnQnYL9ec8W78pLcQHVtjJzHP8phUXQ8V1SXbgZK9ZaFaS6U";
91-
#[allow(dead_code)]
92122
pub const PLAYER_ONE_KEYPAIR_B58: &str =
93123
"yqJrKqGqzuW6nEmfj62AgvZWqgGv9TqxfvPXiGvf8DxGDWz3UNkQdDfKDnBYpHQxPRVrYMupDKqbGVYHhfZApGb";
94124

95125
// Helper functions to get keypairs
96-
#[allow(dead_code)]
97126
pub fn get_payer_keypair() -> Keypair {
98127
Keypair::from_base58_string(PAYER_KEYPAIR_B58)
99128
}
100129

101-
#[allow(dead_code)]
102130
pub fn get_owner_assistant_keypair() -> Keypair {
103131
Keypair::from_base58_string(OWNER_ASSISTANT_KEYPAIR_B58)
104132
}
105133

106-
#[allow(dead_code)]
107134
pub fn get_owner_keypair() -> Keypair {
108135
Keypair::from_base58_string(OWNER_KEYPAIR_B58)
109136
}
110137

111-
#[allow(dead_code)]
112138
pub fn get_player_one_keypair() -> Keypair {
113139
Keypair::from_base58_string(PLAYER_ONE_KEYPAIR_B58)
114140
}

solana/modules/matching-engine-testing/tests/utils/mint.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! # Mint fixture
2+
//!
3+
//! This module provides a fixture for creating a mint account (like a USDC mint).
4+
15
use anchor_spl::token::spl_token;
26
use solana_cli_output::CliAccount;
37
use solana_program_test::ProgramTestContext;

solana/modules/matching-engine-testing/tests/utils/program_fixtures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! # Program Fixtures
2+
//!
3+
//! This module provides fixtures for initializing programs on the Solana blockchain.
4+
//! It includes functions to initialize the upgrade manager, CCTP token messenger minter,
5+
//! wormhole core bridge, CCTP message transmitter, local token router, and verify shims.
6+
17
use solana_program::bpf_loader_upgradeable;
28
use solana_program_test::ProgramTest;
39
use solana_sdk::pubkey::Pubkey;

solana/modules/matching-engine-testing/tests/utils/public_keys.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! # Public Keys
2+
//!
3+
//! This module provides a struct for representing public keys in the test environment.
4+
//! It includes methods for converting between different key types and for creating unique keys.
5+
16
use solana_sdk::{keccak, pubkey::Pubkey};
27

38
use super::Chain;

0 commit comments

Comments
 (0)