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

Use new helper to simplify escrow tests #108

Merged
merged 11 commits into from
Aug 9, 2024
5 changes: 3 additions & 2 deletions basics/favorites/anchor/programs/favorites/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub mod favorites {

// Our instruction handler! It sets the user's favorite number and color
pub fn set_favorites(context: Context<SetFavorites>, number: u64, color: String, hobbies: Vec<String>) -> Result<()> {
let user_public_key = context.accounts.user.key();
msg!("Greetings from {}", context.program_id);
let user_public_key = context.accounts.user.key();
msg!(
"User {user_public_key}'s favorite number is {number}, favorite color is: {color}, and their hobbies are {hobbies:?}",
);
Expand Down Expand Up @@ -53,7 +53,8 @@ pub struct SetFavorites<'info> {
payer = user,
space = ANCHOR_DISCRIMINATOR_SIZE + Favorites::INIT_SPACE,
seeds=[b"favorites", user.key().as_ref()],
bump)]
bump
)]
pub favorites: Account<'info, Favorites>,

pub system_program: Program<'info, System>,
Expand Down
4 changes: 3 additions & 1 deletion basics/favorites/anchor/tests/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ describe('Favorites', () => {
it('Updates the favorites', async () => {
const newFavoriteHobbies = ['skiing', 'skydiving', 'biking', 'swimming'];
try {
await program.methods.setFavorites(favoriteNumber, favoriteColor, newFavoriteHobbies).signers([user]).rpc();
const signature = await program.methods.setFavorites(favoriteNumber, favoriteColor, newFavoriteHobbies).signers([user]).rpc();

console.log(`Transaction signature: ${signature}`);
} catch (error) {
console.error((error as Error).message);
const customErrorMessage = getCustomErrorMessage(systemProgramErrors, error);
Expand Down
1 change: 1 addition & 0 deletions tokens/escrow/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This project is based on [Dean Little's Anchor Escrow,](https://github.com/deanm
One of the challenges when teaching is avoiding ambiguity — names have to be carefully chosen to be clear and not possible to confuse with other times.

- Custom instructions were replaced by `@solana-developers/helpers` for many tasks to reduce the file size.
- Shared functionality to transfer tokens is now in `instructions/shared.rs`
- The upstream project has a custom file layout. We use the 'multiple files' Anchor layout.
- Contexts are separate data structures from functions that use the contexts. There is no need for OO-like `impl` patterns here - there's no mutable state stored in the Context, and the 'methods' do not mutate that state. Besides, it's easier to type!
- The name 'deposit' was being used in multiple contexts, and `deposit` can be tough because it's a verb and a noun:
Expand Down
2 changes: 1 addition & 1 deletion tokens/escrow/anchor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.0",
"@solana-developers/helpers": "^2.3.0",
"@solana-developers/helpers": "^2.4.0",
"@solana/spl-token": "^0.4.6"
},
"license": "MIT",
Expand Down
Loading