Add Comprehensive Tests for ContractOp::exec in vm/op_contract.rs#2
Open
astral-bitlight wants to merge 21 commits intozoedberg:0.11.1-3from
Open
Add Comprehensive Tests for ContractOp::exec in vm/op_contract.rs#2astral-bitlight wants to merge 21 commits intozoedberg:0.11.1-3from
astral-bitlight wants to merge 21 commits intozoedberg:0.11.1-3from
Conversation
…kContractState and MockGlobalStateIter
…e initial_depth_reset to has_been_reset
…or clarity and improve assertion messages
…ign_vec functions for assignment creation
… and global state
…::Sas functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This pull request introduces a comprehensive test suite for the
execmethod of allContractOpvariants located inrgb-core/src/vm/op_contract.rs. The primary goal of this effort was to significantly improve the test coverage for this critical component of the RGB Core virtual machine, ensuring its robustness and verifying its deterministic behavior.Key Contributions:
vm/op_contract/tests.rs) has been created to house all tests related toContractOpexecution.MockContractState: Implements theContractStateAccesstrait, providing a controlled environment for simulating contract state interactions during tests.MockGlobalStateIter: Implements theGlobalStateItertrait, crucial for testing operations that access historical global state (e.g.,LdC).TestEnvHelper: A builder struct to simplify the setup of test contexts (CoreRegs,VmContext) and mock operation data (Genesis, Transitions, assignments, global state, metadata).ContractOp::exec:ContractOpvariant'sexecmethod has been tested for both successful execution paths and all anticipated failure scenarios (specifically, those triggering thefail!()macro).ST0flag being set tofalseandExecStep::Stopon failure.Svs,Sas,Sps,Vts).VmContextdata (previous state, current operation's state, contract-wide state).BytecodeandInstructionSetTrait Implementation Tests:instr_range(),instr_byte(),encode_args(),decode(),isa_ids(),src_regs(),dst_regs(), andcomplexity()forContractOp. This ensures the integrity of the instruction definitions themselves.Impact on Coverage:
This work has resulted in a substantial increase in test coverage for the target file and has also positively impacted overall project coverage:
vm/op_contract/mod.rs(Target File):0.00%->100.00%0.00%->99.69%0.00%->80.81%~7.75%to~50.12%.operation/*andvm/contract.rsdue to the comprehensive nature of the test setup. (Refer to the detailed test report for precise figures across all files).Motivation:
The
ContractOp::execmethod is central to the RGB Core virtual machine's execution logic. Ensuring its reliability through thorough testing is crucial for the integrity and security of the RGB protocol's consensus layer. This PR aims to provide a high degree of confidence in this foundational component.