Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,8 @@ syn = { version = "2.0.87" }
sysinfo = { version = "0.30" }
tar = { version = "0.4" }
tempfile = { version = "3.8.1" }
test-case = { version = "3.3.1" }
# pinned test-case to 3.3.1 because they support only the latest stable version of rust
test-case = { version = "=3.3.1" }
test-log = { version = "0.2.14" }
test-pallet = { path = "substrate/frame/support/test/pallet", default-features = false, package = "frame-support-test-pallet" }
test-parachain-adder = { path = "polkadot/parachain/test-parachains/adder" }
Expand Down
8 changes: 8 additions & 0 deletions prdoc/pr_9841.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: replace forloop solc fixture type with test-case macro
doc:
- audience: Runtime Dev
description: For all tests of revm instructions replaced `for fixture_type` with
test-case macro
crates:
- name: pallet-revive
bump: patch
14 changes: 7 additions & 7 deletions substrate/frame/revive/fixtures/contracts/Arithmetic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ contract Arithmetic {
require(100 / 5 == 20, "DIV basic");

// SDIV tests
require(int(-100) / 5 == -20, "SDIV neg/pos");
require(int(100) / -5 == -20, "SDIV pos/neg");
require(int(-100) / -5 == 20, "SDIV neg/neg");
require(int256(-100) / 5 == -20, "SDIV neg/pos");
require(int256(100) / -5 == -20, "SDIV pos/neg");
require(int256(-100) / -5 == 20, "SDIV neg/neg");

// REM/MOD tests
require(100 % 7 == 2, "REM basic");

// SMOD tests
require(int(-100) % 7 == -2, "SMOD neg dividend");
require(int(100) % -7 == 2, "SMOD neg divisor");
require(int256(-100) % 7 == -2, "SMOD neg dividend");
require(int256(100) % -7 == 2, "SMOD neg divisor");

// ADDMOD tests
require((10 + 15) % 7 == 4, "ADDMOD basic");
Expand All @@ -39,12 +39,12 @@ contract Arithmetic {
require(0 ** 5 == 0, "EXP zero base");

// SIGNEXTEND tests
uint result1;
uint256 result1;
assembly {
result1 := signextend(0, 0xff)
}
require(result1 == type(uint256).max, "SIGNEXTEND negative byte");
uint result2;
uint256 result2;
assembly {
result2 := signextend(0, 0x7f)
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/revive/fixtures/contracts/Bitwise.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ contract Bitwise {
require(10 == 10, "EQ basic");
require(type(uint256).max == type(uint256).max, "EQ max");

require(int(-5) < int(10), "SLT basic");
require(int256(-5) < int256(10), "SLT basic");
require(type(int256).min < 0, "SLT min");

require(int(5) > int(-10), "SGT basic");
require(int256(5) > int256(-10), "SGT basic");
require(0 > type(int256).min, "SGT min");

require((5 & 3) == 1, "AND basic");
require((5 | 3) == 7, "OR basic");
require((5 ^ 3) == 6, "XOR basic");
require(~uint(0) == type(uint256).max, "NOT basic");
require(~uint256(0) == type(uint256).max, "NOT basic");

require((1 << 3) == 8, "SHL basic");
require((8 >> 3) == 1, "SHR basic");
Expand Down
24 changes: 12 additions & 12 deletions substrate/frame/revive/fixtures/contracts/BlockInfo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
pragma solidity ^0.8.0;

contract BlockInfo {
function blockNumber() public view returns (uint) {
return block.number;
function blockNumber() public view returns (uint64) {
return uint64(block.number);
}

function coinbase() public view returns (address) {
return block.coinbase;
}

function timestamp() public view returns (uint) {
return block.timestamp;
function timestamp() public view returns (uint64) {
return uint64(block.timestamp);
}

function difficulty() public view returns (uint) {
return block.difficulty;
function difficulty() public view returns (uint64) {
return uint64(block.difficulty);
}

function gaslimit() public view returns (uint) {
return block.gaslimit;
function gaslimit() public view returns (uint64) {
return uint64(block.gaslimit);
}

function chainid() public view returns (uint) {
return block.chainid;
function chainid() public view returns (uint64) {
return uint64(block.chainid);
}

function basefee() public view returns (uint) {
return block.basefee;
function basefee() public view returns (uint64) {
return uint64(block.basefee);
}
}
14 changes: 7 additions & 7 deletions substrate/frame/revive/fixtures/contracts/Callee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
pragma solidity >=0.8.0;

contract Callee {
uint public stored;
uint64 public stored;

function echo(uint _data) external pure returns (uint data) {
function echo(uint64 _data) external pure returns (uint64 data) {
data = _data;
}

function whoSender() external view returns (address) {
return msg.sender;
}

function store(uint _data) external {
function store(uint64 _data) external {
stored = _data;
}

function revert() public pure returns (uint256) {
function revert() public pure returns (uint64) {
require(false, "This is a revert");
return 42; // never reached
}

function invalid() public pure returns (uint256 result) {
function invalid() public pure {
assembly {
invalid() // 0xFE opcode
invalid()
}
}

function stop() public pure returns (uint256 result) {
function stop() public pure {
assembly {
stop()
}
Expand Down
53 changes: 30 additions & 23 deletions substrate/frame/revive/fixtures/contracts/Caller.sol
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;

// Contract that always reverts in constructor
contract ChildRevert {
constructor() {
revert("ChildRevert: revert in constructor");
}
}

contract Caller {
function normal(
address _callee,
uint _value,
bytes memory _data,
uint _gas
) external returns (bool success, bytes memory output) {
function normal(address _callee, uint64 _value, bytes memory _data, uint64 _gas)
external
returns (bool success, bytes memory output)
{
(success, output) = _callee.call{value: _value, gas: _gas}(_data);
}

function delegate(
address _callee,
bytes memory _data,
uint _gas
) external returns (bool success, bytes memory output) {
function delegate(address _callee, bytes memory _data, uint64 _gas)
external
returns (bool success, bytes memory output)
{
(success, output) = _callee.delegatecall{gas: _gas}(_data);
}

function staticCall(
// Don't rename to `static` (it's a Rust keyword).
address _callee,
bytes memory _data,
uint _gas
uint64 _gas
) external view returns (bool success, bytes memory output) {
(success, output) = _callee.staticcall{gas: _gas}(_data);
}

function create(
bytes memory initcode
) external payable returns (address addr) {
function create(bytes memory initcode) external payable returns (address addr) {
assembly {
// CREATE with no value
addr := create(0, add(initcode, 0x20), mload(initcode))
if iszero(addr) {
// bubble failure
let returnDataSize := returndatasize()
returndatacopy(0, 0, returnDataSize)
let returnDataSize := returndatasize()
returndatacopy(0, 0, returnDataSize)
revert(0, returnDataSize)
}
}
}

function create2(
bytes memory initcode,
bytes32 salt
) external payable returns (address addr) {
function createRevert() external returns (address addr) {
try new ChildRevert() returns (ChildRevert c) {
addr = address(c);
} catch (bytes memory reason) {
revert(string(reason));
}
}

function create2(bytes memory initcode, bytes32 salt) external payable returns (address addr) {
assembly {
// CREATE2 with no value
addr := create2(0, add(initcode, 0x20), mload(initcode), salt)
if iszero(addr) {
// bubble failure
let returnDataSize := returndatasize()
returndatacopy(0, 0, returnDataSize)
let returnDataSize := returndatasize()
returndatacopy(0, 0, returnDataSize)
revert(0, returnDataSize)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ contract CallerWithConstructor {
CallerWithConstructorCallee callee;

constructor() {
callee = new CallerWithConstructorCallee();
callee = new CallerWithConstructorCallee();
}

function callBar() public view returns (uint) {
return callee.bar();
function callBar() public view returns (uint64) {
return callee.bar();
}
}

contract CallerWithConstructorCallee {
function bar() public pure returns (uint) {
return 42;
function bar() public pure returns (uint64) {
return 42;
}
}

2 changes: 1 addition & 1 deletion substrate/frame/revive/fixtures/contracts/Fibonacci.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

contract Fibonacci {
function fib(uint n) public pure returns (uint) {
function fib(uint64 n) public pure returns (uint64) {
if (n <= 1) {
return n;
}
Expand Down
20 changes: 10 additions & 10 deletions substrate/frame/revive/fixtures/contracts/Host.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
pragma solidity ^0.8.24;

contract Host {
function balance(address account) public view returns (uint256) {
return account.balance;
function balance(address account) public view returns (uint64) {
return uint64(account.balance);
}

function extcodesizeOp(address account) public view returns (uint256) {
function extcodesizeOp(address account) public view returns (uint64) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size;
return uint64(size);
}

function extcodehashOp(address account) public view returns (bytes32) {
Expand All @@ -22,23 +22,23 @@ contract Host {
return hash;
}

function blockhashOp(uint256 blockNumber) public view returns (bytes32) {
function blockhashOp(uint64 blockNumber) public view returns (bytes32) {
bytes32 hash;
assembly {
hash := blockhash(blockNumber)
}
return hash;
}

function sloadOp(uint256 slot) public view returns (uint256) {
function sloadOp(uint64 slot) public view returns (uint64) {
uint256 value;
assembly {
value := sload(slot)
}
return value;
return uint64(value);
}

function sstoreOp(uint256 slot, uint256 value) public {
function sstoreOp(uint64 slot, uint64 value) public {
assembly {
sstore(slot, value)
}
Expand All @@ -54,7 +54,7 @@ contract Host {
}
}

function selfbalance() public view returns (uint256) {
return address(this).balance;
function selfbalance() public view returns (uint64) {
return uint64(address(this).balance);
}
}
11 changes: 4 additions & 7 deletions substrate/frame/revive/fixtures/contracts/HostEvmOnly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ contract HostEvmOnly {
selfdestruct(recipient)
}
}
function extcodecopyOp(
address account,
uint256 offset,
uint256 size
) public view returns (bytes memory code) {

function extcodecopyOp(address account, uint64 offset, uint64 size) public view returns (bytes memory code) {
code = new bytes(size);
assembly {
extcodecopy(account, add(code, 32), offset, size)
Expand All @@ -24,10 +21,10 @@ contract HostEvmOnlyFactory {
// Deploy a new instance of HostEvmOnly
HostEvmOnly newInstance = new HostEvmOnly();
newContract = address(newInstance);

// Call selfdestruct on the newly created contract
newInstance.selfdestructOp(recipient);

return newContract;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
pragma solidity ^0.8.24;

contract HostTransientMemory {
function transientMemoryTest(
uint256 slot,
uint256 a
) public returns (uint256) {
function transientMemoryTest(uint64 slot, uint64 a) public returns (uint64) {
uint256 value;
assembly {
tstore(slot, a)
Expand All @@ -14,6 +11,6 @@ contract HostTransientMemory {
assembly {
value := tload(slot)
}
return value - a;
return uint64(value - a);
}
}
Loading
Loading