-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add
debug_traceTransaction
with opcode logger tests (#786)
* chore: add tests Signed-off-by: nikolay <[email protected]> * chore: remove only Signed-off-by: nikolay <[email protected]> * chore: edit tests Signed-off-by: nikolay <[email protected]> * chore: remove only Signed-off-by: nikolay <[email protected]> * chore: add ci Signed-off-by: nikolay <[email protected]> * chore: add -d mode Signed-off-by: nikolay <[email protected]> * chore: test Signed-off-by: nikolay <[email protected]> * chore: add tests Signed-off-by: nikolay <[email protected]> * chore: add tests Signed-off-by: nikolay <[email protected]> * chore: edit name Signed-off-by: nikolay <[email protected]> * chore: add tests Signed-off-by: nikolay <[email protected]> * chore: edit workflow Signed-off-by: nikolay <[email protected]> * chore: bump local node version Signed-off-by: nikolay <[email protected]> * chore: debug ci Signed-off-by: nikolay <[email protected]> * chore: debug Signed-off-by: nikolay <[email protected]> * chore: debug Signed-off-by: nikolay <[email protected]> * chore: debug Signed-off-by: nikolay <[email protected]> * chore: fix besu Signed-off-by: nikolay <[email protected]> * chore: add new line Signed-off-by: nikolay <[email protected]> * chore: add readme Signed-off-by: nikolay <[email protected]> * chore: fix contracts Signed-off-by: nikolay <[email protected]> * chore: pin version Signed-off-by: nikolay <[email protected]> --------- Signed-off-by: nikolay <[email protected]>
- Loading branch information
Showing
12 changed files
with
37,357 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,50 @@ | ||
name: Opcode logger testing | ||
|
||
on: | ||
pull_request: | ||
branches: [ main, release/** ] | ||
push: | ||
branches: [ main, release/** ] | ||
tags: [ v* ] | ||
|
||
jobs: | ||
check: | ||
name: | ||
Opcode logger comparison between besu and hedera | ||
runs-on: [self-hosted, Linux, large, ephemeral] | ||
steps: | ||
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Use Node.js [18.15] | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version: 18.15 | ||
cache: npm | ||
|
||
- name: Create .env file | ||
run: cp local.env .env | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Upgrade @hashgraph/hedera-local to v2.27.1 | ||
run: npm install @hashgraph/[email protected] --save | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773 # v1.2.0 | ||
with: | ||
version: nightly | ||
|
||
- name: Run besu node | ||
run: npm run besu:start | ||
|
||
- name: Run opcode tests against besu | ||
run: npx hardhat test --grep "besu comparison" --network besu_local | ||
|
||
- name: Start the hedera local node | ||
run: npx hedera start -d | ||
|
||
- name: Run opcode tests against hedera local node | ||
run: npx hardhat test --grep @OpcodeLogger |
This file contains 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
165 changes: 165 additions & 0 deletions
165
contracts-abi/contracts/solidity/opcode-logger/OpcodeLogger.sol/OpcodeLogger.json
This file contains 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,165 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "call", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "callCode", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "callsCounter", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "delegateCall", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "resetCounter", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address payable", | ||
"name": "_target", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_calldata", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "staticCall", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "updateOwner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains 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,77 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
contract OpcodeLogger { | ||
address public owner; | ||
mapping(address => uint256) public callsCounter; | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
callsCounter[owner]++; | ||
} | ||
|
||
function updateOwner() external returns (address) { | ||
owner = msg.sender; | ||
callsCounter[owner]++; | ||
|
||
return owner; | ||
} | ||
|
||
function resetCounter() external { | ||
callsCounter[msg.sender] = 0; | ||
} | ||
|
||
function call(address payable _target, bytes memory _calldata) external payable returns (bool, uint256) { | ||
bool isSuccess; | ||
uint256 res; | ||
|
||
assembly { | ||
let resPlaceholder := mload(0x40) | ||
isSuccess := call(gas(), _target, callvalue(), add(_calldata, 0x20), mload(_calldata), resPlaceholder, 0x20) | ||
res := mload(resPlaceholder) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return (isSuccess, res); | ||
} | ||
|
||
function delegateCall(address payable _target, bytes memory _calldata) external returns (bool) { | ||
bool isSuccess; | ||
|
||
assembly { | ||
isSuccess := delegatecall(gas(), _target, add(_calldata, 0x20), mload(_calldata), 0, 0) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return isSuccess; | ||
} | ||
|
||
function staticCall(address payable _target, bytes memory _calldata) external returns (bool, uint256) { | ||
bool isSuccess; | ||
uint256 res; | ||
|
||
assembly { | ||
let resPlaceholder := mload(0x40) | ||
isSuccess := staticcall(gas(), _target, add(_calldata, 0x20), mload(_calldata), resPlaceholder, 0x20) | ||
res := mload(resPlaceholder) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return (isSuccess, res); | ||
} | ||
|
||
function callCode(address payable _target, bytes memory _calldata) external payable returns (bool) { | ||
bool isSuccess; | ||
|
||
assembly { | ||
isSuccess := callcode(gas(), _target, callvalue(), add(_calldata, 0x20), mload(_calldata), 0, 0) | ||
} | ||
|
||
callsCounter[msg.sender]++; | ||
|
||
return isSuccess; | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.