Skip to content

Commit

Permalink
Opcodes tests (#1)
Browse files Browse the repository at this point in the history
* TODO fix test opcode GAS

* Adds tests PUSH opcodes

* Adds test DUP opcodes

* Adds tests SWAP opcodes

* Ignore .DS_Store

* Adds tests CALL opcode

* Adds tests CALLCODE opcode

* Adds tests DELEGATECALL opcode
  • Loading branch information
obatirou authored Sep 1, 2022
1 parent cc88e38 commit efc150b
Show file tree
Hide file tree
Showing 75 changed files with 1,662 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ flattened.txt
# Ignore Broadcasts
broadcast

private
private

# macOS
.DS_Store
651 changes: 651 additions & 0 deletions test/Opcodes.t.sol

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions test/opcodes/call
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See callContract for more info on this call

# Set in memory a dummy parameter
PUSH1 0x1
PUSH1 0x0
MSTORE

# Call to callContract with dummy parameter
PUSH1 0x0
PUSH1 0x0
PUSH1 0x20
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
CALL

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
18 changes: 18 additions & 0 deletions test/opcodes/callFail
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See callContract for more info on this call

# Call to callContract with no paramter
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
CALL

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
23 changes: 23 additions & 0 deletions test/opcodes/callcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See callcodeContract for more info on this call

# Set first slot in the current contract
PUSH1 0x1
PUSH1 0x0
SSTORE

# Callcode to callcodeContract contract
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
CALLCODE

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
23 changes: 23 additions & 0 deletions test/opcodes/callcodeFail
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See callcodeContract for more info on this call

# Reset first slot in current contract
PUSH1 0x0
PUSH1 0x0
SSTORE

# Callcode to callcodeContract contract
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
CALLCODE

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
12 changes: 12 additions & 0 deletions test/opcodes/contracts/callContract
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# creates an exception if first word of calldata is 0
# Source: https://www.evm.codes/ playground for CALL
# 0x67600035600757FE5B60005260086018F3
# you can decompile it with pyevmasm to get
# mnemonic creation code and logic (below)

PUSH1 0x0
CALLDATALOAD
PUSH1 0x7
JUMPI
INVALID
JUMPDEST
12 changes: 12 additions & 0 deletions test/opcodes/contracts/callcodeContract
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# creates an exception if first slot of storage is 0
# Source: https://www.evm.codes/ playground for CALLCODE
# 0x67600054600757FE5B60005260086018F3
# you can decompile it with pyevmasm to get
# mnemonic creation code and logic (below)

PUSH1 0x0
SLOAD
PUSH1 0x7
JUMPI
INVALID
JUMPDEST
23 changes: 23 additions & 0 deletions test/opcodes/delegatecall
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See callcodeContract for more info on this call

# Set first slot in the current contract
PUSH1 0x1
PUSH1 0x0
SSTORE

# Callcode contract
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
DELEGATECALL

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
23 changes: 23 additions & 0 deletions test/opcodes/delegatecallFail
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See callcodeContract for more info on this call

# Reset first slot in current contract
PUSH1 0x0
PUSH1 0x0
SSTORE

# Delegatecall to callcodeContract contract
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH1 0x0
PUSH20 0x1231231231231231231231231231231231231231
PUSH2 0xFFFF
DELEGATECALL

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
11 changes: 11 additions & 0 deletions test/opcodes/dup1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PUSH1 0x1
DUP1

# Store the 2 stack instructions and return result
PUSH1 0x0
MSTORE
PUSH1 0x20
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
19 changes: 19 additions & 0 deletions test/opcodes/dup10
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP10

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
20 changes: 20 additions & 0 deletions test/opcodes/dup11
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP11

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
21 changes: 21 additions & 0 deletions test/opcodes/dup12
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PUSH1 0xb
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP12

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
22 changes: 22 additions & 0 deletions test/opcodes/dup13
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PUSH1 0xc
PUSH1 0xb
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP13

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
23 changes: 23 additions & 0 deletions test/opcodes/dup14
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PUSH1 0xd
PUSH1 0xc
PUSH1 0xb
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP14

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
24 changes: 24 additions & 0 deletions test/opcodes/dup15
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PUSH1 0xe
PUSH1 0xd
PUSH1 0xc
PUSH1 0xb
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP15

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
25 changes: 25 additions & 0 deletions test/opcodes/dup16
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PUSH1 0xf
PUSH1 0xe
PUSH1 0xd
PUSH1 0xc
PUSH1 0xb
PUSH1 0xa
PUSH1 0x9
PUSH1 0x8
PUSH1 0x7
PUSH1 0x6
PUSH1 0x5
PUSH1 0x4
PUSH1 0x3
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP16

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
11 changes: 11 additions & 0 deletions test/opcodes/dup2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PUSH1 0x1
PUSH1 0x0

DUP2

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
12 changes: 12 additions & 0 deletions test/opcodes/dup3
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PUSH1 0x2
PUSH1 0x1
PUSH1 0x0

DUP3

# return result
PUSH1 0x0
MSTORE
PUSH1 0xff
PUSH1 0x00
RETURN
Loading

0 comments on commit efc150b

Please sign in to comment.