Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 1e88c13

Browse files
mvinesmergify[bot]
authored andcommitted
Add token account checks
1 parent 71ab7ea commit 1e88c13

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

feature-proposal/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spl-feature-proposal"
3-
version = "1.0.0-pre2"
3+
version = "1.0.0-pre3"
44
description = "Solana Program Library Feature Proposal Program"
55
authors = ["Solana Maintainers <[email protected]>"]
66
repository = "https://github.com/solana-labs/solana-program-library"

feature-proposal/program/src/processor.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,36 @@ pub fn process_instruction(
212212
mint_info.clone(),
213213
],
214214
)?;
215+
invoke(
216+
&spl_token::instruction::set_authority(
217+
&spl_token::id(),
218+
acceptance_token_info.key,
219+
Some(&feature_proposal_info.key),
220+
spl_token::instruction::AuthorityType::CloseAccount,
221+
feature_proposal_info.key,
222+
&[],
223+
)?,
224+
&[
225+
spl_token_program_info.clone(),
226+
acceptance_token_info.clone(),
227+
feature_proposal_info.clone(),
228+
],
229+
)?;
230+
invoke(
231+
&spl_token::instruction::set_authority(
232+
&spl_token::id(),
233+
acceptance_token_info.key,
234+
Some(&program_id),
235+
spl_token::instruction::AuthorityType::AccountOwner,
236+
feature_proposal_info.key,
237+
&[],
238+
)?,
239+
&[
240+
spl_token_program_info.clone(),
241+
acceptance_token_info.clone(),
242+
feature_proposal_info.clone(),
243+
],
244+
)?;
215245

216246
// Mint `tokens_to_mint` tokens into `delivery_token_account` owned by
217247
// `feature_proposal`

feature-proposal/program/tests/functional.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use futures::{Future, FutureExt};
55
use solana_program::{
66
feature::{self, Feature},
7+
program_option::COption,
78
program_pack::Pack,
89
pubkey::Pubkey,
910
system_program,
@@ -54,6 +55,9 @@ async fn test_basic() {
5455
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
5556

5657
let feature_id_address = get_feature_id_address(&feature_proposal.pubkey());
58+
let mint_address = get_mint_address(&feature_proposal.pubkey());
59+
let delivery_token_address = get_delivery_token_address(&feature_proposal.pubkey());
60+
let acceptance_token_address = get_acceptance_token_address(&feature_proposal.pubkey());
5761

5862
// Create a new feature proposal
5963
let mut transaction = Transaction::new_with_payer(
@@ -80,6 +84,38 @@ async fn test_basic() {
8084
assert_eq!(feature_id_acccount.owner, system_program::id());
8185
assert_eq!(feature_id_acccount.data.len(), Feature::size_of());
8286

87+
// Confirm mint account state
88+
let mint = get_account::<spl_token::state::Mint>(&mut banks_client, mint_address)
89+
.await
90+
.unwrap();
91+
assert_eq!(mint.supply, 42);
92+
assert_eq!(mint.decimals, 9);
93+
assert!(mint.freeze_authority.is_none());
94+
assert_eq!(mint.mint_authority, COption::Some(mint_address));
95+
96+
// Confirm delivery token account state
97+
let delivery_token =
98+
get_account::<spl_token::state::Account>(&mut banks_client, delivery_token_address)
99+
.await
100+
.unwrap();
101+
assert_eq!(delivery_token.amount, 42);
102+
assert_eq!(delivery_token.mint, mint_address);
103+
assert_eq!(delivery_token.owner, feature_proposal.pubkey());
104+
assert!(delivery_token.close_authority.is_none());
105+
106+
// Confirm acceptance token account state
107+
let acceptance_token =
108+
get_account::<spl_token::state::Account>(&mut banks_client, acceptance_token_address)
109+
.await
110+
.unwrap();
111+
assert_eq!(acceptance_token.amount, 0);
112+
assert_eq!(acceptance_token.mint, mint_address);
113+
assert_eq!(acceptance_token.owner, id());
114+
assert_eq!(
115+
acceptance_token.close_authority,
116+
COption::Some(feature_proposal.pubkey())
117+
);
118+
83119
// Tally #1: Does nothing because the acceptance criteria has not been met
84120
let mut transaction =
85121
Transaction::new_with_payer(&[tally(&feature_proposal.pubkey())], Some(&payer.pubkey()));
@@ -100,9 +136,6 @@ async fn test_basic() {
100136
));
101137

102138
// Transfer tokens to the acceptance account
103-
let delivery_token_address = get_delivery_token_address(&feature_proposal.pubkey());
104-
let acceptance_token_address = get_acceptance_token_address(&feature_proposal.pubkey());
105-
106139
let mut transaction = Transaction::new_with_payer(
107140
&[spl_token::instruction::transfer(
108141
&spl_token::id(),

0 commit comments

Comments
 (0)