11use anchor_lang:: prelude:: * ;
22
33use crate :: {
4- constants:: { CFG_SEED , MSG_SEED } ,
4+ constants:: CFG_SEED ,
55 internal:: check_and_pay_for_gas,
66 state:: { Cfg , MessageToRelay } ,
77} ;
88
99#[ derive( Accounts ) ]
10- #[ instruction( outgoing_message: Pubkey ) ]
1110pub struct PayForRelay < ' info > {
1211 /// The account that pays for transaction fees and account creation.
1312 /// Must be mutable to deduct lamports for account rent and gas fees.
@@ -25,7 +24,7 @@ pub struct PayForRelay<'info> {
2524 #[ account( mut , address = cfg. gas_config. gas_fee_receiver @ PayForRelayError :: IncorrectGasFeeReceiver ) ]
2625 pub gas_fee_receiver : AccountInfo < ' info > ,
2726
28- #[ account( init, payer = payer, seeds = [ MSG_SEED , outgoing_message . as_ref ( ) ] , bump , space = 8 + MessageToRelay :: INIT_SPACE ) ]
27+ #[ account( init, payer = payer, space = 8 + MessageToRelay :: INIT_SPACE ) ]
2928 pub message_to_relay : Account < ' info , MessageToRelay > ,
3029
3130 /// System program required for creating new accounts.
@@ -71,6 +70,7 @@ mod tests {
7170 solana_program:: { instruction:: Instruction , system_program} ,
7271 InstructionData ,
7372 } ;
73+ use solana_keypair:: Keypair ;
7474 use solana_message:: Message ;
7575 use solana_signer:: Signer ;
7676 use solana_transaction:: Transaction ;
@@ -88,14 +88,13 @@ mod tests {
8888 let gas_limit: u64 = 123_456 ;
8989
9090 // New account to be initialized by the instruction
91- let ( message_to_relay, _) =
92- Pubkey :: find_program_address ( & [ MSG_SEED , outgoing_message. as_ref ( ) ] , & crate :: ID ) ;
91+ let message_to_relay = Keypair :: new ( ) ;
9392
9493 let accounts = accounts:: PayForRelay {
9594 payer : payer_pk,
9695 cfg : config_pda,
9796 gas_fee_receiver : TEST_GAS_FEE_RECEIVER ,
98- message_to_relay,
97+ message_to_relay : message_to_relay . pubkey ( ) ,
9998 system_program : system_program:: ID ,
10099 }
101100 . to_account_metas ( None ) ;
@@ -111,7 +110,7 @@ mod tests {
111110 } ;
112111
113112 let tx = Transaction :: new (
114- & [ & payer] ,
113+ & [ & payer, & message_to_relay ] ,
115114 Message :: new ( & [ ix] , Some ( & payer_pk) ) ,
116115 svm. latest_blockhash ( ) ,
117116 ) ;
@@ -120,7 +119,7 @@ mod tests {
120119 . expect ( "failed to send transaction" ) ;
121120
122121 // Assert message account was initialized with expected fields
123- let msg_account = svm. get_account ( & message_to_relay) . unwrap ( ) ;
122+ let msg_account = svm. get_account ( & message_to_relay. pubkey ( ) ) . unwrap ( ) ;
124123 let msg = MessageToRelay :: try_deserialize ( & mut & msg_account. data [ ..] ) . unwrap ( ) ;
125124 assert_eq ! ( msg. outgoing_message, outgoing_message) ;
126125 assert_eq ! ( msg. gas_limit, gas_limit) ;
0 commit comments