-
Notifications
You must be signed in to change notification settings - Fork 2
2025 07 13 lt #357
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
Merged
Merged
2025 07 13 lt #357
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // SPDX-License-Identifier: CAL | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {OpTest} from "test/abstract/OpTest.sol"; | ||
| import {LibContext} from "rain.interpreter.interface/lib/caller/LibContext.sol"; | ||
| import {LibOpLessThan} from "src/lib/op/logic/LibOpLessThan.sol"; | ||
| import { | ||
| IInterpreterV4, | ||
| OperandV2, | ||
| SourceIndexV2, | ||
| FullyQualifiedNamespace, | ||
| EvalV4 | ||
| } from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
| import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol"; | ||
| import {InterpreterState} from "src/lib/state/LibInterpreterState.sol"; | ||
| import {IntegrityCheckState, BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheck.sol"; | ||
| import {LibOperand} from "test/lib/operand/LibOperand.sol"; | ||
| import {StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
|
|
||
| contract LibOpLessThanTest is OpTest { | ||
| /// Directly test the integrity logic of LibOpLessThan. No matter the | ||
| /// operand inputs, the calc inputs must be 2, and the calc outputs must be | ||
| /// 1. | ||
| function testOpLessThanIntegrityHappy( | ||
| IntegrityCheckState memory state, | ||
| uint8 inputs, | ||
| uint8 outputs, | ||
| uint16 operandData | ||
| ) external pure { | ||
| inputs = uint8(bound(inputs, 0, 0x0F)); | ||
| outputs = uint8(bound(outputs, 0, 0x0F)); | ||
| (uint256 calcInputs, uint256 calcOutputs) = | ||
| LibOpLessThan.integrity(state, LibOperand.build(inputs, outputs, operandData)); | ||
|
|
||
| // The inputs from the operand are ignored. The op is always 2 inputs. | ||
| assertEq(calcInputs, 2); | ||
| assertEq(calcOutputs, 1); | ||
| } | ||
|
|
||
| /// Directly test the runtime logic of LibOpLessThan. | ||
| function testOpLessThanRun(StackItem input1, StackItem input2) external view { | ||
| InterpreterState memory state = opTestDefaultInterpreterState(); | ||
| StackItem[] memory inputs = new StackItem[](2); | ||
| inputs[0] = input1; | ||
| inputs[1] = input2; | ||
| OperandV2 operand = LibOperand.build(uint8(inputs.length), 1, 0); | ||
| opReferenceCheck(state, operand, LibOpLessThan.referenceFn, LibOpLessThan.integrity, LibOpLessThan.run, inputs); | ||
| } | ||
|
|
||
| /// Test the eval of less than opcode parsed from a string. Tests 2 inputs. | ||
| /// Both inputs are 0. | ||
| function testOpLessThanEval2ZeroInputs() external view { | ||
| checkHappy("_: less-than(0 0);", 0, ""); | ||
| } | ||
|
|
||
| /// Test the eval of less than opcode parsed from a string. Tests 2 inputs. | ||
| /// The first input is 0, the second input is 1. | ||
| function testOpLessThanEval2InputsFirstZeroSecondOne() external view { | ||
| checkHappy("_: less-than(0 1);", bytes32(uint256(1)), ""); | ||
| } | ||
|
|
||
| /// Test the eval of less than opcode parsed from a string. Tests 2 inputs. | ||
| /// The first input is 1, the second input is 0. | ||
| function testOpLessThanNPEval2InputsFirstOneSecondZero() external view { | ||
| checkHappy("_: less-than(1 0);", bytes32(uint256(0)), ""); | ||
| } | ||
|
|
||
| /// Test the eval of less than opcode parsed from a string. Tests 2 inputs. | ||
| /// Both inputs are 1. | ||
| function testOpLessThanNPEval2InputsBothOne() external view { | ||
| checkHappy("_: less-than(1 1);", bytes32(uint256(0)), ""); | ||
| } | ||
|
|
||
| // Test 1.1 lt 1.2, which should return 1. | ||
| function testOpLessThanNP1_1Lt1_2() external view { | ||
| checkHappy("_: less-than(1.1 1.2);", bytes32(uint256(1)), ""); | ||
| } | ||
|
|
||
| /// Test 1.0 lt 1 which should return 0. | ||
| function testOpLessThanNP1_0Lt1() external view { | ||
| checkHappy("_: less-than(1.0 1);", bytes32(uint256(0)), ""); | ||
| } | ||
|
|
||
| // Test -1.1 lt -1.2, which should return 0. | ||
| function testOpLessThanNPMinus1_1LtMinus1_2() external view { | ||
| checkHappy("_: less-than(-1.1 -1.2);", bytes32(uint256(0)), ""); | ||
| } | ||
|
|
||
| /// Test -1 lt 0, which should return 1. | ||
| function testOpLessThanNPMinus1Lt0() external view { | ||
| checkHappy("_: less-than(-1 0);", bytes32(uint256(1)), ""); | ||
| } | ||
|
|
||
| /// Test that a less than to without inputs fails integrity check. | ||
| function testOpLessThanToNPEvalFail0Inputs() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 0, 2, 0)); | ||
| bytes memory bytecode = iDeployer.parse2("_: less-than();"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| /// Test that a less than to with 1 input fails integrity check. | ||
| function testOpLessThanToNPEvalFail1Input() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 1, 2, 1)); | ||
| bytes memory bytecode = iDeployer.parse2("_: less-than(0x00);"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| /// Test that a less than to with 3 inputs fails integrity check. | ||
| function testOpLessThanToNPEvalFail3Inputs() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 3, 2, 3)); | ||
| bytes memory bytecode = iDeployer.parse2("_: less-than(0x00 0x00 0x00);"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| function testOpLessThanNPZeroOutputs() external { | ||
| checkBadOutputs(": less-than(0 0);", 2, 1, 0); | ||
| } | ||
|
|
||
| function testOpLessThanNPTwoOutputs() external { | ||
| checkBadOutputs("_ _: less-than(30 0);", 2, 1, 2); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Fix inconsistent function naming in test comments.
Several test function names still contain the "NP" suffix from the old implementation (lines 64, 70, 75, 80, 85, 90), which should be removed for consistency.
📝 Committable suggestion
🤖 Prompt for AI Agents