From b724f1c3aee67eb28ef9877905494b3a09e6c833 Mon Sep 17 00:00:00 2001 From: losman0s Date: Sun, 9 Jan 2022 20:11:21 +0100 Subject: [PATCH] Update tests with missing mut signer attributes --- lang/syn/src/parser/accounts/mod.rs | 2 +- .../programs/cashiers-check/src/lib.rs | 6 +- tests/chat/programs/chat/src/lib.rs | 7 +- tests/errors/programs/errors/src/lib.rs | 3 +- tests/escrow/programs/escrow/src/lib.rs | 2 +- tests/lockup/programs/lockup/src/lib.rs | 6 +- tests/lockup/programs/registry/src/lib.rs | 44 ++++------- tests/misc/programs/misc/src/context.rs | 75 +++++++++++-------- tests/multisig/programs/multisig/src/lib.rs | 6 +- tests/swap/programs/swap/src/lib.rs | 2 +- tests/tictactoe/programs/tictactoe/src/lib.rs | 12 +-- tests/zero-copy/programs/zero-copy/src/lib.rs | 22 ++---- 12 files changed, 82 insertions(+), 105 deletions(-) diff --git a/lang/syn/src/parser/accounts/mod.rs b/lang/syn/src/parser/accounts/mod.rs index 96451fd545..2945e63178 100644 --- a/lang/syn/src/parser/accounts/mod.rs +++ b/lang/syn/src/parser/accounts/mod.rs @@ -100,7 +100,7 @@ fn constraints_cross_checks(fields: &[AccountField]) -> ParseResult<()> { } _ => { // composite payer, check not supported - continue + continue; } }; diff --git a/tests/cashiers-check/programs/cashiers-check/src/lib.rs b/tests/cashiers-check/programs/cashiers-check/src/lib.rs index f77d8145cc..250339f41b 100644 --- a/tests/cashiers-check/programs/cashiers-check/src/lib.rs +++ b/tests/cashiers-check/programs/cashiers-check/src/lib.rs @@ -130,8 +130,7 @@ pub struct CashCheck<'info> { check_signer: AccountInfo<'info>, #[account(mut, has_one = owner)] to: Account<'info, TokenAccount>, - #[account(signer)] - owner: AccountInfo<'info>, + owner: Signer<'info>, token_program: AccountInfo<'info>, } @@ -148,8 +147,7 @@ pub struct CancelCheck<'info> { check_signer: AccountInfo<'info>, #[account(mut, has_one = owner)] from: Account<'info, TokenAccount>, - #[account(signer)] - owner: AccountInfo<'info>, + owner: Signer<'info>, token_program: AccountInfo<'info>, } diff --git a/tests/chat/programs/chat/src/lib.rs b/tests/chat/programs/chat/src/lib.rs index bb6a897ef3..b5b7c5679b 100644 --- a/tests/chat/programs/chat/src/lib.rs +++ b/tests/chat/programs/chat/src/lib.rs @@ -49,8 +49,8 @@ pub struct CreateUser<'info> { space = 320, )] user: Account<'info, User>, - #[account(signer)] - authority: AccountInfo<'info>, + #[account(mut)] + authority: Signer<'info>, system_program: AccountInfo<'info>, } @@ -68,8 +68,7 @@ pub struct SendMessage<'info> { has_one = authority, )] user: Account<'info, User>, - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, #[account(mut)] chat_room: Loader<'info, ChatRoom>, } diff --git a/tests/errors/programs/errors/src/lib.rs b/tests/errors/programs/errors/src/lib.rs index 7270987c5e..d0833751bc 100644 --- a/tests/errors/programs/errors/src/lib.rs +++ b/tests/errors/programs/errors/src/lib.rs @@ -60,8 +60,7 @@ pub struct HasOneError<'info> { #[derive(Accounts)] pub struct SignerError<'info> { - #[account(signer)] - my_account: AccountInfo<'info>, + my_account: Signer<'info>, } #[account] diff --git a/tests/escrow/programs/escrow/src/lib.rs b/tests/escrow/programs/escrow/src/lib.rs index 9887568821..f436417d63 100644 --- a/tests/escrow/programs/escrow/src/lib.rs +++ b/tests/escrow/programs/escrow/src/lib.rs @@ -102,7 +102,7 @@ pub mod escrow { #[derive(Accounts)] #[instruction(initializer_amount: u64)] pub struct InitializeEscrow<'info> { - #[account(signer)] + #[account(signer, mut)] pub initializer: AccountInfo<'info>, #[account( mut, diff --git a/tests/lockup/programs/lockup/src/lib.rs b/tests/lockup/programs/lockup/src/lib.rs index 4bf4b7128c..d7013d861a 100644 --- a/tests/lockup/programs/lockup/src/lib.rs +++ b/tests/lockup/programs/lockup/src/lib.rs @@ -250,8 +250,7 @@ pub struct Withdraw<'info> { // Vesting. #[account(mut, has_one = beneficiary, has_one = vault)] vesting: Account<'info, Vesting>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(mut)] vault: Account<'info, TokenAccount>, #[account( @@ -281,8 +280,7 @@ pub struct WhitelistDeposit<'info> { #[derive(Accounts)] pub struct WhitelistTransfer<'info> { lockup: ProgramState<'info, Lockup>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, whitelisted_program: AccountInfo<'info>, // Whitelist interface. diff --git a/tests/lockup/programs/registry/src/lib.rs b/tests/lockup/programs/registry/src/lib.rs index 69e400d1dc..a6083a6bbd 100644 --- a/tests/lockup/programs/registry/src/lib.rs +++ b/tests/lockup/programs/registry/src/lib.rs @@ -596,8 +596,7 @@ impl<'info> Initialize<'info> { pub struct UpdateRegistrar<'info> { #[account(mut, has_one = authority)] registrar: Account<'info, Registrar>, - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] @@ -607,8 +606,7 @@ pub struct CreateMember<'info> { // Member. #[account(zero)] member: Box>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account( "&balances.spt.owner == member_signer.key", "balances.spt.mint == registrar.pool_mint", @@ -672,8 +670,7 @@ pub struct Ctor<'info> { #[derive(Accounts)] pub struct SetLockupProgram<'info> { - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] @@ -691,8 +688,7 @@ pub struct IsRealized<'info> { pub struct UpdateMember<'info> { #[account(mut, has_one = beneficiary)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, } #[derive(Accounts)] @@ -700,8 +696,7 @@ pub struct Deposit<'info> { // Member. #[account(has_one = beneficiary)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(mut, constraint = vault.to_account_info().key == &member.balances.vault)] vault: Account<'info, TokenAccount>, // Depositor. @@ -727,7 +722,7 @@ pub struct DepositLocked<'info> { // Note: no need to verify the depositor_authority since the SPL program // will fail the transaction if it's not correct. #[account(signer)] - depositor_authority: AccountInfo<'info>, + pub depositor_authority: AccountInfo<'info>, #[account(constraint = token_program.key == &token::ID)] token_program: AccountInfo<'info>, #[account( @@ -746,8 +741,7 @@ pub struct DepositLocked<'info> { registrar: Box>, #[account(has_one = registrar, has_one = beneficiary)] member: Box>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, } #[derive(Accounts)] @@ -762,8 +756,7 @@ pub struct Stake<'info> { // Member. #[account(mut, has_one = beneficiary, has_one = registrar)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(constraint = BalanceSandbox::from(&balances) == member.balances)] balances: BalanceSandboxAccounts<'info>, #[account(constraint = BalanceSandbox::from(&balances_locked) == member.balances_locked)] @@ -801,8 +794,7 @@ pub struct StartUnstake<'info> { pending_withdrawal: Account<'info, PendingWithdrawal>, #[account(has_one = beneficiary, has_one = registrar)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(constraint = BalanceSandbox::from(&balances) == member.balances)] balances: BalanceSandboxAccounts<'info>, #[account(constraint = BalanceSandbox::from(&balances_locked) == member.balances_locked)] @@ -827,8 +819,7 @@ pub struct EndUnstake<'info> { #[account(has_one = registrar, has_one = beneficiary)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(mut, has_one = registrar, has_one = member, constraint = !pending_withdrawal.burned)] pending_withdrawal: Account<'info, PendingWithdrawal>, @@ -859,8 +850,7 @@ pub struct Withdraw<'info> { // Member. #[account(has_one = registrar, has_one = beneficiary)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(mut, constraint = vault.to_account_info().key == &member.balances.vault)] vault: Account<'info, TokenAccount>, #[account( @@ -886,8 +876,7 @@ pub struct WithdrawLocked<'info> { vesting: Box>, #[account(mut, constraint = vesting_vault.key == &vesting.vault)] vesting_vault: AccountInfo<'info>, - #[account(signer)] - vesting_signer: AccountInfo<'info>, + vesting_signer: Signer<'info>, #[account(constraint = token_program.key == &token::ID)] token_program: AccountInfo<'info>, #[account( @@ -906,8 +895,7 @@ pub struct WithdrawLocked<'info> { registrar: Box>, #[account(has_one = registrar, has_one = beneficiary)] member: Box>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, } #[derive(Accounts)] @@ -977,8 +965,7 @@ pub struct ClaimRewardCommon<'info> { // Member. #[account(mut, has_one = registrar, has_one = beneficiary)] member: Account<'info, Member>, - #[account(signer)] - beneficiary: AccountInfo<'info>, + beneficiary: Signer<'info>, #[account(constraint = BalanceSandbox::from(&balances) == member.balances)] balances: BalanceSandboxAccounts<'info>, #[account(constraint = BalanceSandbox::from(&balances_locked) == member.balances_locked)] @@ -1014,8 +1001,7 @@ pub struct ExpireReward<'info> { )] vendor_signer: AccountInfo<'info>, // Receiver. - #[account(signer)] - expiry_receiver: AccountInfo<'info>, + expiry_receiver: Signer<'info>, #[account(mut)] expiry_receiver_token: AccountInfo<'info>, // Misc. diff --git a/tests/misc/programs/misc/src/context.rs b/tests/misc/programs/misc/src/context.rs index d40479e86e..26395e3af0 100644 --- a/tests/misc/programs/misc/src/context.rs +++ b/tests/misc/programs/misc/src/context.rs @@ -1,7 +1,7 @@ use crate::account::*; -use anchor_lang::prelude::*; -use anchor_lang::accounts::loader::Loader; use anchor_lang::accounts::cpi_state::CpiState; +use anchor_lang::accounts::loader::Loader; +use anchor_lang::prelude::*; use anchor_spl::associated_token::AssociatedToken; use anchor_spl::token::{Mint, Token, TokenAccount}; use misc2::misc2::MyState as Misc2State; @@ -28,10 +28,11 @@ pub struct TestTokenSeedsInit<'info> { token::authority = authority, )] pub my_pda: Account<'info, TokenAccount>, + #[account(mut)] pub authority: AccountInfo<'info>, - pub system_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, pub rent: Sysvar<'info, Rent>, - pub token_program: AccountInfo<'info>, + pub token_program: Program<'info, Token>, } #[derive(Accounts)] @@ -44,6 +45,7 @@ pub struct TestInitAssociatedToken<'info> { )] pub token: Account<'info, TokenAccount>, pub mint: Account<'info, Mint>, + #[account(mut)] pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, pub system_program: Program<'info, System>, @@ -83,9 +85,10 @@ pub struct TestPdaInit<'info> { payer = my_payer, )] pub my_pda: Account<'info, DataU16>, - pub my_payer: AccountInfo<'info>, + #[account(mut)] + pub my_payer: Signer<'info>, pub foo: AccountInfo<'info>, - pub system_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, } #[derive(Accounts)] @@ -98,8 +101,9 @@ pub struct TestPdaInitZeroCopy<'info> { payer = my_payer, )] pub my_pda: Loader<'info, DataZeroCopy>, - pub my_payer: AccountInfo<'info>, - pub system_program: AccountInfo<'info>, + #[account(mut)] + pub my_payer: Signer<'info>, + pub system_program: Program<'info, System>, } #[derive(Accounts)] @@ -191,29 +195,29 @@ pub struct TestI8<'info> { pub struct TestInit<'info> { #[account(init, payer = payer)] pub data: Account<'info, DataI8>, - #[account(signer)] - pub payer: AccountInfo<'info>, - pub system_program: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, + pub system_program: Program<'info, System>, } #[derive(Accounts)] pub struct TestInitZeroCopy<'info> { #[account(init, payer = payer, space = 8 + size_of::())] pub data: Loader<'info, DataZeroCopy>, - #[account(signer)] - pub payer: AccountInfo<'info>, - pub system_program: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, + pub system_program: Program<'info, System>, } #[derive(Accounts)] pub struct TestInitMint<'info> { #[account(init, mint::decimals = 6, mint::authority = payer, mint::freeze_authority = payer, payer = payer)] pub mint: Account<'info, Mint>, - #[account(signer)] - pub payer: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, - pub system_program: AccountInfo<'info>, - pub token_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, + pub token_program: Program<'info, Token>, } #[derive(Accounts)] @@ -221,11 +225,11 @@ pub struct TestInitToken<'info> { #[account(init, token::mint = mint, token::authority = payer, payer = payer)] pub token: Account<'info, TokenAccount>, pub mint: Account<'info, Mint>, - #[account(signer)] - pub payer: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, - pub system_program: AccountInfo<'info>, - pub token_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, + pub token_program: Program<'info, Token>, } #[derive(Accounts)] @@ -240,6 +244,7 @@ pub struct TestCompositePayer<'info> { pub struct TestFetchAll<'info> { #[account(init, payer = authority)] pub data: Account<'info, DataWithFilter>, + #[account(mut)] pub authority: Signer<'info>, pub system_program: Program<'info, System>, } @@ -248,6 +253,7 @@ pub struct TestFetchAll<'info> { pub struct TestInitWithEmptySeeds<'info> { #[account(init, seeds = [], bump, payer = authority, space = 8 + size_of::())] pub pda: Account<'info, Data>, + #[account(mut)] pub authority: Signer<'info>, pub system_program: Program<'info, System>, } @@ -262,6 +268,7 @@ pub struct TestEmptySeedsConstraint<'info> { pub struct InitWithSpace<'info> { #[account(init, payer = payer)] pub data: Account<'info, DataU16>, + #[account(mut)] pub payer: Signer<'info>, pub system_program: Program<'info, System>, } @@ -270,6 +277,7 @@ pub struct InitWithSpace<'info> { pub struct TestInitIfNeeded<'info> { #[account(init_if_needed, payer = payer, space = 500)] pub data: Account<'info, DataU16>, + #[account(mut)] pub payer: Signer<'info>, pub system_program: Program<'info, System>, } @@ -278,6 +286,7 @@ pub struct TestInitIfNeeded<'info> { pub struct TestInitIfNeededChecksOwner<'info> { #[account(init_if_needed, payer = payer, space = 100, owner = *owner.key, seeds = [b"hello"], bump)] pub data: UncheckedAccount<'info>, + #[account(mut)] pub payer: Signer<'info>, pub system_program: Program<'info, System>, pub owner: AccountInfo<'info>, @@ -298,11 +307,11 @@ pub struct TestInitIfNeededChecksSeeds<'info> { pub struct TestInitMintIfNeeded<'info> { #[account(init_if_needed, mint::decimals = decimals, mint::authority = mint_authority, mint::freeze_authority = freeze_authority, payer = payer)] pub mint: Account<'info, Mint>, - #[account(signer)] - pub payer: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, - pub system_program: AccountInfo<'info>, - pub token_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, + pub token_program: Program<'info, Token>, pub mint_authority: AccountInfo<'info>, pub freeze_authority: AccountInfo<'info>, } @@ -312,11 +321,11 @@ pub struct TestInitTokenIfNeeded<'info> { #[account(init_if_needed, token::mint = mint, token::authority = authority, payer = payer)] pub token: Account<'info, TokenAccount>, pub mint: Account<'info, Mint>, - #[account(signer)] - pub payer: AccountInfo<'info>, + #[account(mut)] + pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, - pub system_program: AccountInfo<'info>, - pub token_program: AccountInfo<'info>, + pub system_program: Program<'info, System>, + pub token_program: Program<'info, Token>, pub authority: AccountInfo<'info>, } @@ -330,6 +339,7 @@ pub struct TestInitAssociatedTokenIfNeeded<'info> { )] pub token: Account<'info, TokenAccount>, pub mint: Account<'info, Mint>, + #[account(mut)] pub payer: Signer<'info>, pub rent: Sysvar<'info, Rent>, pub system_program: Program<'info, System>, @@ -367,7 +377,7 @@ pub struct InitDecreaseLamports<'info> { pub data: AccountInfo<'info>, #[account(mut)] pub user: Signer<'info>, - pub system_program: Program<'info, System> + pub system_program: Program<'info, System>, } #[derive(Accounts)] @@ -376,6 +386,5 @@ pub struct InitIfNeededChecksRentExemption<'info> { pub data: AccountInfo<'info>, #[account(mut)] pub user: Signer<'info>, - pub system_program: Program<'info, System> + pub system_program: Program<'info, System>, } - diff --git a/tests/multisig/programs/multisig/src/lib.rs b/tests/multisig/programs/multisig/src/lib.rs index 07811d6321..18b5062bf8 100644 --- a/tests/multisig/programs/multisig/src/lib.rs +++ b/tests/multisig/programs/multisig/src/lib.rs @@ -177,8 +177,7 @@ pub struct CreateTransaction<'info> { #[account(zero)] transaction: ProgramAccount<'info, Transaction>, // One of the owners. Checked in the handler. - #[account(signer)] - proposer: AccountInfo<'info>, + proposer: Signer<'info>, } #[derive(Accounts)] @@ -187,8 +186,7 @@ pub struct Approve<'info> { #[account(mut, has_one = multisig)] transaction: ProgramAccount<'info, Transaction>, // One of the multisig owners. Checked in the handler. - #[account(signer)] - owner: AccountInfo<'info>, + owner: Signer<'info>, } #[derive(Accounts)] diff --git a/tests/swap/programs/swap/src/lib.rs b/tests/swap/programs/swap/src/lib.rs index 55f07db5b9..1b85a6917f 100644 --- a/tests/swap/programs/swap/src/lib.rs +++ b/tests/swap/programs/swap/src/lib.rs @@ -226,7 +226,7 @@ pub struct SwapTransitive<'info> { // Must be the authority over all open orders accounts used. #[account(signer)] authority: AccountInfo<'info>, - #[account(mut)] + #[account(signer)] pc_wallet: AccountInfo<'info>, // Programs. dex_program: AccountInfo<'info>, diff --git a/tests/tictactoe/programs/tictactoe/src/lib.rs b/tests/tictactoe/programs/tictactoe/src/lib.rs index 5a79f980cb..9acef504d3 100644 --- a/tests/tictactoe/programs/tictactoe/src/lib.rs +++ b/tests/tictactoe/programs/tictactoe/src/lib.rs @@ -64,14 +64,12 @@ pub struct Status<'info> { pub struct Initializedashboard<'info> { #[account(zero)] dashboard: Account<'info, Dashboard>, - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] pub struct Initialize<'info> { - #[account(signer)] - player_x: AccountInfo<'info>, + player_x: Signer<'info>, #[account(mut)] dashboard: Account<'info, Dashboard>, #[account(zero)] @@ -80,16 +78,14 @@ pub struct Initialize<'info> { #[derive(Accounts)] pub struct Playerjoin<'info> { - #[account(signer)] - player_o: AccountInfo<'info>, + player_o: Signer<'info>, #[account(mut, constraint = game.game_state != 0 && game.player_x != Pubkey::default())] game: Account<'info, Game>, } #[derive(Accounts)] pub struct Playermove<'info> { - #[account(signer)] - player: AccountInfo<'info>, + player: Signer<'info>, #[account(mut)] game: Account<'info, Game>, } diff --git a/tests/zero-copy/programs/zero-copy/src/lib.rs b/tests/zero-copy/programs/zero-copy/src/lib.rs index d029d521ec..9577bf3f5f 100644 --- a/tests/zero-copy/programs/zero-copy/src/lib.rs +++ b/tests/zero-copy/programs/zero-copy/src/lib.rs @@ -64,24 +64,21 @@ pub mod zero_copy { #[derive(Accounts)] pub struct SetEvent<'info> { - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] pub struct CreateFoo<'info> { #[account(zero)] foo: AccountLoader<'info, Foo>, - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] pub struct UpdateFoo<'info> { #[account(mut, has_one = authority)] foo: AccountLoader<'info, Foo>, - #[account(signer)] - authority: AccountInfo<'info>, + authority: Signer<'info>, } #[derive(Accounts)] @@ -91,8 +88,7 @@ pub struct UpdateFooSecond<'info> { constraint = &foo.load()?.get_second_authority() == second_authority.key, )] foo: AccountLoader<'info, Foo>, - #[account(signer)] - second_authority: AccountInfo<'info>, + second_authority: Signer<'info>, } #[derive(Accounts)] @@ -104,8 +100,8 @@ pub struct CreateBar<'info> { payer = authority, owner = *program_id )] bar: AccountLoader<'info, Bar>, - #[account(signer)] - authority: AccountInfo<'info>, + #[account(mut)] + authority: Signer<'info>, foo: AccountLoader<'info, Foo>, system_program: AccountInfo<'info>, } @@ -118,8 +114,7 @@ pub struct UpdateBar<'info> { bump, )] pub bar: AccountLoader<'info, Bar>, - #[account(signer)] - pub authority: AccountInfo<'info>, + pub authority: Signer<'info>, pub foo: AccountLoader<'info, Foo>, } @@ -133,8 +128,7 @@ pub struct CreateLargeAccount<'info> { pub struct UpdateLargeAccount<'info> { #[account(mut)] event_q: AccountLoader<'info, EventQ>, - #[account(signer)] - from: AccountInfo<'info>, + from: Signer<'info>, } #[account(zero_copy)]