Skip to content

Commit 010fe9e

Browse files
committed
complete steel tests
1 parent b5c348c commit 010fe9e

File tree

6 files changed

+53
-48
lines changed

6 files changed

+53
-48
lines changed

tokens/spl-token-minter/steel/api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ thiserror.workspace = true
1212
spl-token.workspace = true
1313
mpl-token-metadata.workspace = true
1414
const-crypto.workspace = true
15+
spl-associated-token-account.workspace = true

tokens/spl-token-minter/steel/api/src/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Create {
1919
#[repr(C)]
2020
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
2121
pub struct Mint {
22-
pub amount: [u8; 8],
22+
pub quantity: [u8; 8],
2323
}
2424

2525
instruction!(SteelInstruction, Mint);

tokens/spl-token-minter/steel/api/src/sdk.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,28 @@ pub fn create(
3939
.to_bytes(),
4040
}
4141
}
42-
pub fn mint(signer: Pubkey, to: Pubkey, authority: Pubkey, amount: u64) -> Instruction {
42+
pub fn mint(
43+
signer: Pubkey,
44+
recipient: Pubkey,
45+
associated_token_account: Pubkey,
46+
authority: Pubkey,
47+
quantity: u64,
48+
) -> Instruction {
4349
let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID);
4450
Instruction {
4551
program_id: crate::ID,
4652
accounts: vec![
4753
AccountMeta::new(signer, true),
54+
AccountMeta::new(recipient, false),
4855
AccountMeta::new(mint_pda.0, false),
49-
AccountMeta::new(to, false),
56+
AccountMeta::new(associated_token_account, false),
5057
AccountMeta::new(authority, false),
5158
AccountMeta::new_readonly(spl_token::ID, false),
59+
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
60+
AccountMeta::new_readonly(system_program::ID, false),
5261
],
5362
data: Mint {
54-
amount: amount.to_le_bytes(),
63+
quantity: quantity.to_le_bytes(),
5564
}
5665
.to_bytes(),
5766
}

tokens/spl-token-minter/steel/program/src/create.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ pub fn process_create(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
2424
system_program.is_program(&system_program::ID)?;
2525
token_program.is_program(&spl_token::ID)?;
2626
rent_sysvar.is_sysvar(&sysvar::rent::ID)?;
27-
msg!("metadata program key {}", metadata_program.key);
28-
msg!("metadata program ID {}", mpl_token_metadata::ID);
29-
// metadata_program.is_program(&mpl_token_metadata::ID)?;
30-
31-
if metadata_program.key.ne(&mpl_token_metadata::ID) {
32-
return Err(ProgramError::InvalidAccountData);
33-
}
3427

3528
// First create the account for the Mint
3629
//

tokens/spl-token-minter/steel/program/src/mint.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,53 @@ use steel::*;
55
pub fn process_mint(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
66
// parse args.
77
let args = Mint::try_from_bytes(data)?;
8-
let amount = u64::from_le_bytes(args.amount);
8+
let quantity = u64::from_le_bytes(args.quantity);
99

1010
// Load accounts.
11-
let [signer_info, mint_info, to_info, authority_info, token_program] = accounts else {
11+
let [signer_info, recipient_info, mint_info, associated_token_account_info, authority_info, token_program, associated_token_program, system_program] =
12+
accounts
13+
else {
1214
return Err(ProgramError::NotEnoughAccountKeys);
1315
};
1416

15-
msg!("Minting tokens to associated token account...");
16-
msg!("Mint: {:?}", mint_info);
17-
msg!("Token Address: {:?}", &to_info);
18-
19-
// validation
2017
signer_info.is_signer()?;
2118
mint_info.as_mint()?;
2219
token_program.is_program(&spl_token::ID)?;
2320

24-
to_info.as_associated_token_account(signer_info.key, mint_info.key)?;
21+
if associated_token_account_info.lamports() == 0 {
22+
msg!("Creating associated token account...");
23+
create_associated_token_account(
24+
signer_info,
25+
recipient_info,
26+
associated_token_account_info,
27+
mint_info,
28+
system_program,
29+
token_program,
30+
associated_token_program,
31+
)?;
32+
} else {
33+
msg!("Associated token account exists.");
34+
}
35+
msg!(
36+
"Associated Token Address: {}",
37+
associated_token_account_info.key
38+
);
39+
40+
msg!("Minting {} tokens to associated token account...", quantity);
2541

2642
solana_program::program::invoke(
2743
&spl_token::instruction::mint_to(
2844
&spl_token::id(),
2945
mint_info.key,
30-
to_info.key,
46+
associated_token_account_info.key,
3147
authority_info.key,
3248
&[authority_info.key],
33-
amount,
49+
quantity,
3450
)?,
3551
&[
3652
token_program.clone(),
3753
mint_info.clone(),
38-
to_info.clone(),
54+
associated_token_account_info.clone(),
3955
authority_info.clone(),
4056
],
4157
)?;

tokens/spl-token-minter/steel/program/tests/test.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,23 @@ async fn run_test() {
3434

3535
let mint_pda =
3636
Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &spl_token_minter_api::ID);
37-
// dbg!(mint_pda);
38-
// let to_ata =
39-
// spl_associated_token_account::get_associated_token_address(&payer.pubkey(), &mint_pda.0);
40-
let to_ata = spl_associated_token_account::get_associated_token_address_with_program_id(
41-
&payer.pubkey(),
37+
38+
let recipient = Keypair::new();
39+
40+
let to_ata = spl_associated_token_account::get_associated_token_address(
41+
&recipient.pubkey(),
4242
&mint_pda.0,
43-
&spl_token::ID,
4443
);
45-
// dbg!(to_ata);
4644

4745
// Submit mint transaction.
48-
let ix = mint(payer.pubkey(), to_ata, payer.pubkey(), 100);
46+
let ix = mint(
47+
payer.pubkey(),
48+
recipient.pubkey(),
49+
to_ata,
50+
payer.pubkey(),
51+
100,
52+
);
4953
let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
5054
let res = banks.process_transaction(tx).await;
5155
assert!(res.is_ok());
52-
53-
// // Verify counter was initialized.
54-
// let counter_address = counter_pda().0;
55-
// let counter_account = banks.get_account(counter_address).await.unwrap().unwrap();
56-
// let counter = Counter::try_from_bytes(&counter_account.data).unwrap();
57-
// assert_eq!(counter_account.owner, steel_api::ID);
58-
// assert_eq!(counter.value, 0);
59-
60-
// // Submit add transaction.
61-
// let ix = add(payer.pubkey(), 42);
62-
// let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash);
63-
// let res = banks.process_transaction(tx).await;
64-
// assert!(res.is_ok());
65-
66-
// // Verify counter was incremented.
67-
// let counter_account = banks.get_account(counter_address).await.unwrap().unwrap();
68-
// let counter = Counter::try_from_bytes(&counter_account.data).unwrap();
69-
// assert_eq!(counter.value, 42);
7056
}

0 commit comments

Comments
 (0)