Skip to content

Add unit tests for Instructions, Fees, and Clock sysvars#357

Open
anand9125 wants to merge 3 commits intoanza-xyz:mainfrom
anand9125:sysvars-add-unit-tests-instructions-fees-clock
Open

Add unit tests for Instructions, Fees, and Clock sysvars#357
anand9125 wants to merge 3 commits intoanza-xyz:mainfrom
anand9125:sysvars-add-unit-tests-instructions-fees-clock

Conversation

@anand9125
Copy link

Summary

Adds unit tests for three sysvars that previously had no tests:

  • Instructions (sdk/src/sysvars/instructions.rs) – parsing and introspecting the Instructions sysvar
  • Fees (sdk/src/sysvars/fees.rs) – FeeCalculator, FeeRateGovernor, and Fees construction and logic
  • Clock (sdk/src/sysvars/clock.rs) – from_bytes / from_bytes_unchecked and layout constants

Instructions sysvar

  • Helpers to build mock sysvar buffers (instruction blobs and full layout).
  • Tests for num_instructions(), load_current_index(), load_instruction_at(), get_instruction_relative() (in bounds, out of bounds, negative index).
  • Tests for IntrospectedInstruction: num_account_metas(), get_program_id(), get_instruction_data(), get_instruction_account_at(), and account flags (is_signer, is_writable).
  • 9 tests total.

Fees sysvar

  • Tests for FeeCalculator::new, FeeRateGovernor::default(), create_fee_calculator(), burn() (50%, 0%, 100%), and Fees::new().
  • 7 tests total.

Clock sysvar

  • Helper to serialize a Clock to bytes (repr(C) layout).
  • Tests for Clock::LEN, from_bytes() (valid, too short, empty), from_bytes_unchecked(), and default constants.
  • 6 tests total.

Testing

cargo test -p pinocchio

@anand9125
Copy link
Author

Hey @febo pls review this pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant