Skip to content

Commit 0fa87f6

Browse files
committed
processor: assign
1 parent a172a52 commit 0fa87f6

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

program/src/processor.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ fn process_create_account_with_seed(
255255
)
256256
}
257257

258+
fn process_assign(accounts: &[AccountInfo], owner: Pubkey) -> ProgramResult {
259+
accounts!(
260+
accounts,
261+
signers,
262+
0 => account_info,
263+
);
264+
265+
let address = Address::create(account_info.key, None)?;
266+
267+
assign(account_info, &address, &owner, &signers)
268+
}
269+
258270
pub fn process(_program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> ProgramResult {
259271
match solana_bincode::limited_deserialize::<SystemInstruction>(input, MAX_INPUT_LEN)
260272
.map_err(|_| ProgramError::InvalidInstructionData)?
@@ -277,6 +289,10 @@ pub fn process(_program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) ->
277289
msg!("Instruction: CreateAccountWithSeed");
278290
process_create_account_with_seed(accounts, base, seed, lamports, space, owner)
279291
}
292+
SystemInstruction::Assign { owner } => {
293+
msg!("Instruction: Assign");
294+
process_assign(accounts, owner)
295+
}
280296
/* TODO: Remaining instruction implementations... */
281297
_ => Err(ProgramError::InvalidInstructionData),
282298
}

program/tests/assign.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
mod setup;
2+
3+
use {
4+
mollusk_svm::result::Check, solana_account::Account, solana_program_error::ProgramError,
5+
solana_pubkey::Pubkey, solana_system_interface::instruction::assign,
6+
};
7+
8+
const OWNER: Pubkey = Pubkey::new_from_array([8; 32]);
9+
10+
#[test]
11+
fn fail_account_not_signer() {
12+
let mollusk = setup::setup();
13+
14+
let pubkey = Pubkey::new_unique();
15+
16+
let mut instruction = assign(&pubkey, &OWNER);
17+
instruction.accounts[0].is_signer = false;
18+
19+
mollusk.process_and_validate_instruction(
20+
&instruction,
21+
&[(pubkey, Account::default())],
22+
&[Check::err(ProgramError::MissingRequiredSignature)],
23+
);
24+
}
25+
26+
#[test]
27+
fn success() {
28+
let mollusk = setup::setup();
29+
30+
let pubkey = Pubkey::new_unique();
31+
32+
mollusk.process_and_validate_instruction(
33+
&assign(&pubkey, &OWNER),
34+
&[(pubkey, Account::default())],
35+
&[
36+
Check::success(),
37+
Check::account(&pubkey).owner(&OWNER).build(),
38+
],
39+
);
40+
}
41+
42+
#[test]
43+
fn success_already_assigned() {
44+
let mollusk = setup::setup();
45+
46+
let pubkey = Pubkey::new_unique();
47+
48+
let account = Account {
49+
owner: OWNER, // Already assigned
50+
..Account::default()
51+
};
52+
53+
mollusk.process_and_validate_instruction(
54+
&assign(&pubkey, &OWNER),
55+
&[(pubkey, account)],
56+
&[
57+
Check::success(),
58+
Check::account(&pubkey).owner(&OWNER).build(),
59+
],
60+
);
61+
}

0 commit comments

Comments
 (0)