Skip to content

Commit

Permalink
test: fix prevrandoa / difficulty test
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou authored and oguimbal committed Feb 21, 2024
1 parent 668a8a9 commit b7836b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ It is not possible to pin the Huffc version in CI consistently as pre-released v
You can find `easm`, the basic EVM assembly compiler that is used to compile tests [here](https://github.com/oguimbal/EVM-Assembler).
You can use [pyevmasm](https://github.com/crytic/pyevmasm) to disassemble bytecode.

### How to test

It is possible to test for different versions of solidity or different EVM versions.
It is set to `paris` by default in the `foundry.toml` file but it is also
compatible with `shanghai`.

```bash
forge test
```

### How to deploy

Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ remappings = [
"forge-std=lib/forge-std/src/",
"foundry-huff=lib/foundry-huff/src/",
]
evm_version = 'paris'


[profile.default.rpc_endpoints]
eth = 'https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}'
Expand Down
17 changes: 13 additions & 4 deletions test/HyVM/Opcodes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1148,13 +1148,22 @@ contract OpcodesTest is Test {
assertTrue(success, "expectRevert: call did not revert");
}

function testPrevrandao(uint256 prevrandao) public {
/// @dev difficulty is used for evm_version before Paris.
//// If used on unsupported EVM versions it will revert.
/// In that case it will use prevrandao instead.
function testPrevrandaoDifficulty(uint256 prevrandaoDifficulty) public {
// bytecode generated using: easm test/opcodes/prevrandao
// EVM-Assembler does not implement it, so it is added manually
vm.prevrandao(bytes32(prevrandao));
// EVM-Assembler does not implement PREVRANDAO, so it is added manually
// Note: It is the same underlying opcode for prevrandao and difficulty
// It is only a name change.
// https://eips.ethereum.org/EIPS/eip-4399
try vm.difficulty(prevrandaoDifficulty) {}
catch {
vm.prevrandao(bytes32(prevrandaoDifficulty));
}
(bool success, bytes memory data) = hyvm.delegatecall(hex"4460005260206000f3");
assertEq(success, true);
(uint256 result) = abi.decode(data, (uint256));
assertEq(result, prevrandao);
assertEq(result, prevrandaoDifficulty);
}
}

0 comments on commit b7836b1

Please sign in to comment.