• Discover
  • Partner with us
  • Chapters
  • Blog

Learn everything about Solana

Course Introduction
Solana Introduction
Solana Smart Contract Fundamentals - Transactions
Solana Smart Contract Fundamentals - Instructions
Solana Smart Contract Fundamentals - Accounts
Solana Smart Contract Fundamentals - Program Derived Addresses (PDAs)

Installation Rust
Counter I - Implementing State and Instructions
Counter II - Implementing Process Instruction
Counter III - Build & Test
Submit Your Homework 1: Update Increment and Decrement Functions

Token Transfer I - Implementing process_instruction
Token Transfer II - Testing
Submit Your Homework 2: Change Transfer Amount

What Are We Going to Build?
Review I - Implementing State
Review II - Defining Instructions
Review III - Implementing Add_Review
Review IV - Implementing Update_Review
Review V - Build & Deploy
Review VI - Frontend

Build Your Final Project

In this lesson, we are going to see how we can test our project with rust, using cargo test.

In case you are stuck, you can checkout finished version from here

You can copy the cargo nocapture code used in the video below.

cargo test -- --nocapture

Here is the changes we have made to lib.rs in this video:

#[cfg(test)]
mod test {
    use super::*;
    use solana_program::{clock::Epoch, pubkey::Pubkey};
    use std::mem;

    #[test]
    fn test_counter() {
        let program_id = Pubkey::default();
        let key = Pubkey::default();
        let mut lamports = 0;
        let mut data = vec![0; mem::size_of::<u32>()];
        let owner = Pubkey::default();

        let account = AccountInfo::new(
            &key,
            false,
            true,
            &mut lamports,
            &mut data,
            &owner,
            false,
            Epoch::default(),
        );

        let accounts = vec![account];

        let increment_instruction_data: Vec<u8> = vec![0];
        let decrement_instruction_data: Vec<u8> = vec![1];
        let mut update_instruction_data: Vec<u8> = vec![2];
        let reset_instruction_data: Vec<u8> = vec![3];

        process_instruction(&program_id, &accounts, &increment_instruction_data).unwrap();

        assert_eq!(
            CounterAccount::try_from_slice(&accounts[0].data.borrow())
                .unwrap()
                .counter,
            1
        );

        process_instruction(&program_id, &accounts, &decrement_instruction_data).unwrap();

        assert_eq!(
            CounterAccount::try_from_slice(&accounts[0].data.borrow())
                .unwrap()
                .counter,
            0
        );

        let update_value = 33u32;
        update_instruction_data.extend_from_slice(&update_value.to_le_bytes());

        process_instruction(&program_id, &accounts, &update_instruction_data).unwrap();

        assert_eq!(
            CounterAccount::try_from_slice(&accounts[0].data.borrow())
                .unwrap()
                .counter,
            33
        );

        process_instruction(&program_id, &accounts, &reset_instruction_data).unwrap();

        assert_eq!(
            CounterAccount::try_from_slice(&accounts[0].data.borrow())
                .unwrap()
                .counter,
            0
        );
    }
}
Previous
Next

Lesson discussion

Swap insights and ask questions about “Learn everything about Solana”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
WebsiteDiscoverPartner with UsBlogEvents
Discover
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsBrand GuidelineFAQsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://risein.com is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://risein.com disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Rise In, All rights reserved