Skip to content

Commit

Permalink
test: fix test gas
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou authored and oguimbal committed Jan 25, 2023
1 parent a306045 commit 7543144
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
40 changes: 32 additions & 8 deletions test/HyVM/Opcodes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,38 @@ contract OpcodesTest is Test {
assertEq(result, 0x20);
}

// TODO gas test fails
// function testGas() public {
// // bytecode generated using: easm test/opcodes/gas
// (bool success, bytes memory data) = hyvm.delegatecall(hex"5a6200520845030360005260ff6000f3");
// assertEq(success, true);
// uint256 result = abi.decode(data, (uint256));
// assertEq(result, 0x02);
// }
function testGas() public {
// bytecode generated using: easm test/opcodes/gas
(bool success, bytes memory data) = hyvm.delegatecall(hex"5a5a900360005260ff6000f3");
assertEq(success, true);
uint256 result = abi.decode(data, (uint256));
// result will be 67 as there are instructions to read opcodes from bytecode
// between the 2 gas instructions
// see CONTINUE() macro:
// opcodes below equals to 65 in gas hence gas opocode return the correct value
// 3 push1 00
// 3 mload
// 3 dup1
// 3 calldataload
// 3 push1 f8
// 3 shr
// 3 swap1
// 3 push1 01
// 3 add
// 3 push1 00
// 3 mstore
// 3 push1 02
// 5 mul
// 3 push1 20
// 3 add
// 3 mload
// 3 push1 f0
// 3 shr
// 8 jump
// 1 jumpdest
// 2 gas
assertEq(result, 0x43);
}

function testPush1() public {
// bytecode generated using: easm test/opcodes/push1
Expand Down
13 changes: 3 additions & 10 deletions test/HyVM/opcodes/gas
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@

# https://www.evm.codes/playground?unit=Wei&codeType=Mnemonic
GAS
# 21000 Cost of the transaction
PUSH3 0x005208
# PUSH6 0xffffffffffff could simulate GASLIMIT
GASLIMIT
SUB
# Result is the amount of gas used up to and including the GAS instruction
GAS
SWAP1
SUB

# return result
PUSH1 0x0
PUSH1 0x00
MSTORE
PUSH1 0xff
PUSH1 0x00
Expand Down

0 comments on commit 7543144

Please sign in to comment.