@@ -37,7 +37,7 @@ pub struct ProcessEnlistPlayerIx {
3737
3838impl StarFrameInstruction for ProcessEnlistPlayerIx {
3939 type DecodeArg < ' a > = ( ) ;
40- type ValidateArg < ' a > = u8 ;
40+ type ValidateArg < ' a > = ( ) ;
4141 type CleanupArg < ' a > = ( ) ;
4242 type ReturnType = ( ) ;
4343 // type RunArg<'a> = (FactionId, &'a Vec<u8>);
@@ -46,20 +46,15 @@ impl StarFrameInstruction for ProcessEnlistPlayerIx {
4646 // type ReturnType = usize;
4747
4848 fn split_to_args < ' a > ( r : & Self ) -> IxArgs < Self > {
49- IxArgs {
50- validate : r. bump ,
51- run : r. faction_id ,
52- // run: (r.faction_id, &r.buncha_data),
53- cleanup : ( ) ,
54- decode : ( ) ,
55- }
49+ IxArgs :: run ( r. faction_id )
5650 }
5751
5852 fn run_instruction < ' info > (
5953 account_set : & mut Self :: Accounts < ' _ , ' _ , ' info > ,
6054 faction_id : Self :: RunArg < ' _ > ,
6155 syscalls : & mut impl SyscallInvoke < ' info > ,
6256 ) -> Result < Self :: ReturnType > {
57+ // let cloned_account = account_set.player_account.clone();
6358 let clock = syscalls. get_clock ( ) ?;
6459 let bump = account_set. player_faction_account . access_seeds ( ) . bump ;
6560 * account_set. player_faction_account . data_mut ( ) ? = PlayerFactionData {
@@ -74,15 +69,18 @@ impl StarFrameInstruction for ProcessEnlistPlayerIx {
7469}
7570
7671#[ derive( AccountSet ) ]
77- #[ validate( arg = u8 ) ]
78- #[ account_set( skip_default_idl) ]
7972pub struct ProcessEnlistPlayer < ' info > {
8073 /// The player faction account
81- #[ validate( arg = ( Create ( ( ) ) ,
74+ #[ validate( arg = ( Create ( CreateAccount :: new ( & self . system_program , & self . player_account ) ) ,
8275 Seeds ( PlayerFactionAccountSeeds {
8376 player_account: * self . player_account. key( )
8477 } ) ) ) ]
8578 pub player_faction_account : Init < Seeded < DataAccount < ' info , PlayerFactionData > > > ,
79+ #[ validate( arg =Seeds ( PlayerFactionAccountSeeds {
80+ player_account: * self . player_account. key( )
81+ } ) ) ]
82+ pub player_faction_account2 :
83+ Seeded < DataAccount < ' info , PlayerFactionData > , PlayerFactionAccountSeeds , CurrentProgram > ,
8684 /// The player account
8785 #[ account_set( funder) ]
8886 pub player_account : Writable < Signer < SystemAccount < ' info > > > ,
@@ -136,11 +134,14 @@ unsafe impl Zeroable for FactionId {}
136134
137135// TODO - Macro should derive this and with the idl feature enabled would also derive `AccountToIdl` and `TypeToIdl`
138136impl ProgramAccount for PlayerFactionData {
139- type OwnerProgram = StarFrameDeclaredProgram ;
140137 const DISCRIMINANT : <Self :: OwnerProgram as StarFrameProgram >:: AccountDiscriminant =
141138 [ 47 , 44 , 255 , 15 , 103 , 77 , 139 , 247 ] ;
142139}
143140
141+ impl HasOwnerProgram for PlayerFactionData {
142+ type OwnerProgram = FactionEnlistment ;
143+ }
144+
144145impl HasSeeds for PlayerFactionData {
145146 type Seeds = PlayerFactionAccountSeeds ;
146147}
@@ -156,15 +157,17 @@ mod tests {
156157 use super :: * ;
157158 use bytemuck:: checked:: try_from_bytes;
158159 use solana_program_test:: { processor, ProgramTest } ;
160+ use solana_sdk:: account:: Account ;
159161 use solana_sdk:: clock:: Clock ;
160- use solana_sdk:: signature:: Signer ;
162+ use solana_sdk:: signature:: { Keypair , Signer } ;
161163 use star_frame:: borsh:: to_vec;
162164 use star_frame:: itertools:: Itertools ;
163165 use star_frame:: solana_program:: instruction:: AccountMeta ;
166+ use star_frame:: solana_program:: native_token:: LAMPORTS_PER_SOL ;
164167
165168 #[ tokio:: test]
166169 async fn banks_test ( ) -> Result < ( ) > {
167- const SBF_FILE : bool = false ;
170+ const SBF_FILE : bool = true ;
168171 let program_test = if SBF_FILE {
169172 let target_dir = std:: env:: current_dir ( ) ?
170173 . join ( "../../../target/deploy" )
@@ -186,24 +189,27 @@ mod tests {
186189 )
187190 } ;
188191
189- let test_context = program_test. start_with_context ( ) . await ;
192+ let mut test_context = program_test. start_with_context ( ) . await ;
193+ let ( player_account, ( faction_account, bump) ) = loop {
194+ let key = Keypair :: new ( ) ;
195+ let seeds = PlayerFactionAccountSeeds {
196+ player_account : key. pubkey ( ) ,
197+ } ;
198+ let player_faction =
199+ Pubkey :: find_program_address ( & seeds. seeds ( ) , & StarFrameDeclaredProgram :: PROGRAM_ID ) ;
200+ if player_faction. 1 == 255 {
201+ let data = Account {
202+ lamports : LAMPORTS_PER_SOL * 100 ,
203+ ..Default :: default ( )
204+ } ;
205+ test_context. set_account ( & key. pubkey ( ) , & data. into ( ) ) ;
206+ break ( key, player_faction) ;
207+ }
208+ } ;
190209 let mut banks_client = test_context. banks_client ;
191210
192- let player_account = test_context. payer ;
193-
194- let seeds = PlayerFactionAccountSeeds {
195- player_account : player_account. pubkey ( ) ,
196- } ;
197- let ( faction_account, bump) =
198- Pubkey :: find_program_address ( & seeds. seeds ( ) , & StarFrameDeclaredProgram :: PROGRAM_ID ) ;
199- println ! ( "Bump: {}" , bump) ;
200211 let faction_id = FactionId :: MUD ;
201212
202- // let mut random_bytes = [0u8; 1];
203- // let mut rng = rand::thread_rng();
204- // rand::rngs::ThreadRng::try_fill(&mut rng, &mut random_bytes[..]).unwrap();
205- // let bunch_bytes = random_bytes.to_vec();
206-
207213 let enlist_ix = ProcessEnlistPlayerIx {
208214 bump,
209215 faction_id,
0 commit comments