Skip to content

Commit

Permalink
max uint256 value tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Aug 22, 2024
1 parent 8f721ae commit 470cf76
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions test/src/lib/op/evm/LibOpMaxUint256NP.t.sol
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
// // // SPDX-License-Identifier: CAL
// // pragma solidity =0.8.25;
// SPDX-License-Identifier: CAL
pragma solidity =0.8.25;

// // import {OpTest} from "test/abstract/OpTest.sol";
// // import {LibOpMaxUint256NP} from "src/lib/op/evm/LibOpMaxUint256NP.sol";
// // import {IntegrityCheckStateNP, BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheckNP.sol";
// // import {
// // IInterpreterV4,
// // Operand,
// // SourceIndexV2,
// // FullyQualifiedNamespace
// // } from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
// // import {InterpreterStateNP, LibInterpreterStateNP} from "src/lib/state/LibInterpreterStateNP.sol";
// // import {LibContext} from "rain.interpreter.interface/lib/caller/LibContext.sol";
// // import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
// // import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
// // import {LibOperand} from "test/lib/operand/LibOperand.sol";
import {OpTest} from "test/abstract/OpTest.sol";
import {LibOpMaxUint256NP} from "src/lib/op/evm/LibOpMaxUint256NP.sol";
import {IntegrityCheckStateNP, BadOpInputsLength} from "src/lib/integrity/LibIntegrityCheckNP.sol";
import {
IInterpreterV4,
Operand,
SourceIndexV2,
FullyQualifiedNamespace
} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {InterpreterStateNP, LibInterpreterStateNP} from "src/lib/state/LibInterpreterStateNP.sol";
import {LibContext} from "rain.interpreter.interface/lib/caller/LibContext.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV3.sol";
import {LibOperand} from "test/lib/operand/LibOperand.sol";

// // /// @title LibOpMaxUint256NPTest
// // /// @notice Test the runtime and integrity time logic of LibOpMaxUint256NP.
// // contract LibOpMaxUint256NPTest is OpTest {
// // using LibInterpreterStateNP for InterpreterStateNP;
/// @title LibOpMaxUint256NPTest
/// @notice Test the runtime and integrity time logic of LibOpMaxUint256NP.
contract LibOpMaxUint256NPTest is OpTest {
using LibInterpreterStateNP for InterpreterStateNP;

// /// Directly test the integrity logic of LibOpMaxUint256NP.
// function testOpMaxUint256NPIntegrity(
// IntegrityCheckStateNP 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) =
// LibOpMaxUint256NP.integrity(state, LibOperand.build(inputs, outputs, operandData));
/// Directly test the integrity logic of LibOpMaxUint256NP.
function testOpMaxUint256NPIntegrity(
IntegrityCheckStateNP 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) =
LibOpMaxUint256NP.integrity(state, LibOperand.build(inputs, outputs, operandData));

// // assertEq(calcInputs, 0);
// // assertEq(calcOutputs, 1);
// // }
assertEq(calcInputs, 0);
assertEq(calcOutputs, 1);
}

// /// Directly test the runtime logic of LibOpMaxUint256NP. This tests that the
// /// opcode correctly pushes the max uint256 onto the stack.
// function testOpMaxUint256NPRun() external view {
// InterpreterStateNP memory state = opTestDefaultInterpreterState();
// uint256[] memory inputs = new uint256[](0);
// Operand operand = LibOperand.build(0, 1, 0);
// opReferenceCheck(
// state, operand, LibOpMaxUint256NP.referenceFn, LibOpMaxUint256NP.integrity, LibOpMaxUint256NP.run, inputs
// );
// }
/// Directly test the runtime logic of LibOpMaxUint256NP. This tests that the
/// opcode correctly pushes the max uint256 onto the stack.
function testOpMaxUint256NPRun() external view {
InterpreterStateNP memory state = opTestDefaultInterpreterState();
uint256[] memory inputs = new uint256[](0);
Operand operand = LibOperand.build(0, 1, 0);
opReferenceCheck(
state, operand, LibOpMaxUint256NP.referenceFn, LibOpMaxUint256NP.integrity, LibOpMaxUint256NP.run, inputs
);
}

// // /// Test the eval of LibOpMaxUint256NP parsed from a string.
// // function testOpMaxUint256NPEval() external {
// // checkHappy("_: max-value();", type(uint256).max, "");
// // }
/// Test the eval of LibOpMaxUint256NP parsed from a string.
function testOpMaxUint256NPEval() external {
checkHappy("_: uint256-max-value();", type(uint256).max, "");
}

// // /// Test that a max-value with inputs fails integrity check.
// // function testOpMaxUint256NPEvalFail() public {
// // vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 1, 0, 1));
// // bytes memory bytecode = iDeployer.parse2("_: max-value(0x00);");
// // (bytecode);
// // }
/// Test that a max-value with inputs fails integrity check.
function testOpMaxUint256NPEvalFail() public {
vm.expectRevert(abi.encodeWithSelector(BadOpInputsLength.selector, 1, 0, 1));
bytes memory bytecode = iDeployer.parse2("_: uint256-max-value(0x00);");
(bytecode);
}

// // function testOpMaxUint256NPZeroOutputs() external {
// // checkBadOutputs(": max-value();", 0, 1, 0);
// // }
function testOpMaxUint256NPZeroOutputs() external {
checkBadOutputs(": uint256-max-value();", 0, 1, 0);
}

// // function testOpMaxUint256NPTwoOutputs() external {
// // checkBadOutputs("_ _: max-value();", 0, 1, 2);
// // }
// // }
function testOpMaxUint256NPTwoOutputs() external {
checkBadOutputs("_ _: uint256-max-value();", 0, 1, 2);
}
}

0 comments on commit 470cf76

Please sign in to comment.