-
Notifications
You must be signed in to change notification settings - Fork 2
gt op #356
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
gt op #356
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,121 @@ | ||
| // SPDX-License-Identifier: CAL | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {OpTest} from "test/abstract/OpTest.sol"; | ||
| import {LibOpGreaterThan} from "src/lib/op/logic/LibOpGreaterThan.sol"; | ||
| import {IntegrityCheckState, BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheck.sol"; | ||
| import { | ||
| IInterpreterV4, | ||
| OperandV2, | ||
| SourceIndexV2, | ||
| FullyQualifiedNamespace | ||
| } from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
| import {InterpreterState} from "src/lib/state/LibInterpreterState.sol"; | ||
| import {LibOperand} from "test/lib/operand/LibOperand.sol"; | ||
| import {StackItem} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol"; | ||
|
|
||
| contract LibOpGreaterThanTest is OpTest { | ||
| /// Directly test the integrity logic of LibOpGreaterThan. No matter the | ||
| /// operand inputs, the calc inputs must be 2, and the calc outputs must be | ||
| /// 1. | ||
| function testOpGreaterThanIntegrityHappy( | ||
| 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) = | ||
| LibOpGreaterThan.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 LibOpGreaterThan. | ||
| function testOpGreaterThanRun(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, LibOpGreaterThan.referenceFn, LibOpGreaterThan.integrity, LibOpGreaterThan.run, inputs | ||
| ); | ||
| } | ||
|
|
||
| /// Test the eval of greater than opcode parsed from a string. Tests 2 | ||
| /// inputs. Both inputs are 0. | ||
| function testOpGreaterThanEval2ZeroInputs() external view { | ||
| checkHappy("_: greater-than(0 0);", 0, ""); | ||
| } | ||
|
|
||
| /// Test the eval of greater than opcode parsed from a string. Tests 2 | ||
| /// inputs. The first input is 0, the second input is 1. | ||
| function testOpGreaterThanEval2InputsFirstZeroSecondOne() external view { | ||
| checkHappy("_: greater-than(0 1);", 0, ""); | ||
| } | ||
|
|
||
| /// Test the eval of greater than opcode parsed from a string. Tests 2 | ||
| /// inputs. The first input is 1, the second input is 0. | ||
| function testOpGreaterThanEval2InputsFirstOneSecondZero() external view { | ||
| checkHappy("_: greater-than(1 0);", bytes32(uint256(1)), ""); | ||
| } | ||
|
|
||
| /// Test the eval of greater than opcode parsed from a string. Tests 2 | ||
| /// inputs. Both inputs are 1. | ||
| function testOpGreaterThanEval2InputsBothOne() external view { | ||
| checkHappy("_: greater-than(1 1);", 0, ""); | ||
| } | ||
|
|
||
| /// Test 1.1 gt 1.2, which should return 0. | ||
| function testOpGreaterThanEval1_1Gt1_2() external view { | ||
| checkHappy("_: greater-than(1.1 1.2);", 0, ""); | ||
| } | ||
|
|
||
| /// Test 1.0 gt 1 which should return 0. | ||
| function testOpGreaterThanEval1_0Gt1() external view { | ||
| checkHappy("_: greater-than(1.0 1);", 0, ""); | ||
| } | ||
|
|
||
| /// Test -1.1 gt -1.2, which should return 1. | ||
| function testOpGreaterThanEvalNeg1_1GtNeg1_2() external view { | ||
| checkHappy("_: greater-than(-1.1 -1.2);", bytes32(uint256(1)), ""); | ||
| } | ||
|
|
||
| /// Test -1 gt 0, which should return 0. | ||
| function testOpGreaterThanEvalNeg1Gt0() external view { | ||
| checkHappy("_: greater-than(-1 0);", 0, ""); | ||
| } | ||
|
|
||
| /// Test that a greater than without inputs fails integrity check. | ||
| function testOpGreaterThanEvalFail0Inputs() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 0, 2, 0)); | ||
| bytes memory bytecode = iDeployer.parse2("_: greater-than();"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| /// Test that a greater than with 1 input fails integrity check. | ||
| function testOpGreaterThanEvalFail1Input() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 1, 2, 1)); | ||
| bytes memory bytecode = iDeployer.parse2("_: greater-than(0x00);"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| /// Test that a greater than with 3 inputs fails integrity check. | ||
| function testOpGreaterThanEvalFail3Inputs() public { | ||
| vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 3, 2, 3)); | ||
| bytes memory bytecode = iDeployer.parse2("_: greater-than(0x00 0x00 0x00);"); | ||
| (bytecode); | ||
| } | ||
|
|
||
| function testOpGreaterThanZeroOutputs() external { | ||
| checkBadOutputs(": greater-than(1 2);", 2, 1, 0); | ||
| } | ||
|
|
||
| function testOpGreaterThanTwoOutputs() external { | ||
| checkBadOutputs("_ _: greater-than(1 2);", 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.
Uh oh!
There was an error while loading. Please reload this page.