Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test program crates for token and memo #35

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ target/

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

.DS_Store
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"bencher",
"fuzz/*",
"harness",
"programs/*",
"test-programs/*",
]
resolver = "2"
Expand Down
5 changes: 3 additions & 2 deletions harness/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use {
/// Loader keys, re-exported from `solana_sdk` for convenience.
pub mod loader_keys {
pub use solana_sdk::{
bpf_loader::ID as LOADER_V2, bpf_loader_upgradeable::ID as LOADER_V3,
loader_v4::ID as LOADER_V4, native_loader::ID as NATIVE_LOADER,
bpf_loader::ID as LOADER_V2, bpf_loader_deprecated::ID as LOADER_V1,
bpf_loader_upgradeable::ID as LOADER_V3, loader_v4::ID as LOADER_V4,
native_loader::ID as NATIVE_LOADER,
};
}

Expand Down
16 changes: 16 additions & 0 deletions programs/memo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "mollusk-memo"
Copy link
Owner

@buffalojoec buffalojoec Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "mollusk-memo"
name = "mollusk-svm-programs-memo"

version = "0.1.0"
edition = "2021"
Comment on lines +3 to +4
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you align this manifest with the others, like the harness?

description = "SVM program test harness."
documentation = "https://docs.rs/mollusk-svm"
authors = { workspace = true }
repository = { workspace = true }
readme = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
version = { workspace = true }


[features]
default = ["memo", "memo-v1"]
memo = []
memo-v1 = []

[lib]
deanmlittle marked this conversation as resolved.
Show resolved Hide resolved
crate-type = ["lib"]

[dependencies]
mollusk-svm = { workspace = true }
solana-sdk = { workspace = true }
Binary file added programs/memo/src/elf/memo-v1.so
Binary file not shown.
Binary file added programs/memo/src/elf/memo.so
Binary file not shown.
5 changes: 5 additions & 0 deletions programs/memo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Last updated at mainnet-beta slot height: 298485997
#[cfg(feature = "memo")]
pub mod memo;
Comment on lines +1 to +3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here on the doc type please.

Suggested change
// Last updated at mainnet-beta slot height: 298485997
#[cfg(feature = "memo")]
pub mod memo;
//! Last updated at mainnet-beta slot height: 298485997
#[cfg(feature = "memo")]
pub mod memo;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also will have to just adjust the scripts a bit.

#[cfg(feature = "memo-v1")]
pub mod memo_v1;
23 changes: 23 additions & 0 deletions programs/memo/src/memo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use {
mollusk_svm::Mollusk,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

pub const ID: Pubkey = solana_sdk::pubkey!("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");

pub fn add_program(mollusk: &mut Mollusk) {
mollusk.add_program_with_elf_and_loader(
&ID,
include_bytes!("elf/memo.so"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro adds a static slice, so we could optionally just make this a constant in the module, since it might be a little funky for devs trying to access the ELF again through the target/debug folder.

&mollusk_svm::program::loader_keys::LOADER_V2,
);
}

pub fn account() -> AccountSharedData {
mollusk_svm::program::create_program_account_loader_v3(&ID)
}

/// Get the key and account for the SPL Memo program.
pub fn keyed_account() -> (Pubkey, AccountSharedData) {
(ID, account())
}
23 changes: 23 additions & 0 deletions programs/memo/src/memo_v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use {
mollusk_svm::Mollusk,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

pub const ID: Pubkey = solana_sdk::pubkey!("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo");

pub fn add_program(mollusk: &mut Mollusk) {
//BPFLoader1111111111111111111111111111111111
mollusk.add_program_with_elf_and_loader(
&ID,
include_bytes!("elf/memo-v1.so"),
&mollusk_svm::program::loader_keys::LOADER_V1,
);
}

/// Get the key and account for the system program.
pub fn keyed_account() -> (Pubkey, AccountSharedData) {
(
ID,
mollusk_svm::program::create_program_account_loader_v3(&ID),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks like this one doesn't have account() either.

)
}
3 changes: 3 additions & 0 deletions programs/memo/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
solana program dump MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr ./src/elf/memo.so -u mainnet-beta
solana program dump Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo ./src/elf/memo-v1.so -u mainnet-beta
solana slot -u mainnet-beta | xargs -I {} sed -i '' 's|// Last updated at mainnet-beta slot height: .*|// Last updated at mainnet-beta slot height: {}|' ./src/lib.rs
16 changes: 16 additions & 0 deletions programs/token/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "mollusk-token"
Copy link
Owner

@buffalojoec buffalojoec Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "mollusk-token"
name = "mollusk-svm-programs-token"

version = "0.1.0"
edition = "2021"
Comment on lines +3 to +4
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here on the manifest configuration.

description = "SVM program test harness."
documentation = "https://docs.rs/mollusk-svm"
authors = { workspace = true }
repository = { workspace = true }
readme = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
version = { workspace = true }


[features]
default = ["token", "associated-token", "token-2022"]
token = []
associated-token = []
token-2022 = []

[lib]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[lib]
[lib]
crate-type = ["lib"]


[dependencies]
mollusk-svm = { workspace = true }
solana-sdk = { workspace = true }
22 changes: 22 additions & 0 deletions programs/token/src/associated_token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use {
mollusk_svm::Mollusk,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

pub const ID: Pubkey = solana_sdk::pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");

pub fn add_program(mollusk: &mut Mollusk) {
mollusk.add_program_with_elf_and_loader(
&ID,
include_bytes!("elf/associated_token.so"),
&mollusk_svm::program::loader_keys::LOADER_V2,
);
}

/// Get the key and account for the system program.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get the key and account for the system program.
/// Get the key and account for the SPL Associated Token program.

pub fn keyed_account() -> (Pubkey, AccountSharedData) {
(
ID,
mollusk_svm::program::create_program_account_loader_v3(&ID),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only module where you don't offer an account() helper. Can we include it?

)
}
Binary file added programs/token/src/elf/associated_token.so
Binary file not shown.
Binary file added programs/token/src/elf/token.so
Binary file not shown.
Binary file added programs/token/src/elf/token_2022.so
Binary file not shown.
7 changes: 7 additions & 0 deletions programs/token/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg(feature = "associated-token")]
pub mod associated_token;
// Last updated at mainnet-beta slot height: 298486032
Comment on lines +1 to +3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we move this to the top as a crate/module doc? ie:

Suggested change
#[cfg(feature = "associated-token")]
pub mod associated_token;
// Last updated at mainnet-beta slot height: 298486032
//! Last updated at mainnet-beta slot height: 298486032
#[cfg(feature = "associated-token")]
pub mod associated_token;

#[cfg(feature = "token")]
pub mod token;
#[cfg(feature = "token-2022")]
pub mod token2022;
23 changes: 23 additions & 0 deletions programs/token/src/token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use {
mollusk_svm::Mollusk,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

pub const ID: Pubkey = solana_sdk::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

pub fn add_program(mollusk: &mut Mollusk) {
mollusk.add_program_with_elf_and_loader(
&ID,
include_bytes!("elf/token.so"),
&mollusk_svm::program::loader_keys::LOADER_V2,
);
}

pub fn account() -> AccountSharedData {
mollusk_svm::program::create_program_account_loader_v3(&ID)
}

/// Get the key and account for the system program.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get the key and account for the system program.
/// Get the key and account for the SPL Token program.

pub fn keyed_account() -> (Pubkey, AccountSharedData) {
(ID, account())
}
23 changes: 23 additions & 0 deletions programs/token/src/token2022.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use {
mollusk_svm::Mollusk,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

pub const ID: Pubkey = solana_sdk::pubkey!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");

pub fn add_program(mollusk: &mut Mollusk) {
mollusk.add_program_with_elf_and_loader(
&ID,
include_bytes!("elf/token_2022.so"),
&mollusk_svm::program::loader_keys::LOADER_V2,
);
}

pub fn account() -> AccountSharedData {
mollusk_svm::program::create_program_account_loader_v3(&ID)
}

/// Get the key and account for the system program.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get the key and account for the system program.
/// Get the key and account for the SPL Token-2022 program.

pub fn keyed_account() -> (Pubkey, AccountSharedData) {
(ID, account())
}
4 changes: 4 additions & 0 deletions programs/token/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
solana program dump TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA ./src/elf/token.so -u mainnet-beta
solana program dump TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb ./src/elf/token_2022.so -u mainnet-beta
solana program dump ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL ./src/elf/associated_token.so -u mainnet-beta
solana slot -u mainnet-beta | xargs -I {} sed -i '' 's|// Last updated at mainnet-beta slot height: .*|// Last updated at mainnet-beta slot height: {}|' ./src/lib.rs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, nice!