diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-01-05 18:52:10 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-01-05 18:52:10 +0800 |
commit | bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88 (patch) | |
tree | d4743eaa073d1bc7788f5d4fc3771da37f3cb0b5 /core/vm/jit_util_test.go | |
parent | 2126d8148806b6d8597d6a1c761080e9dc98d745 (diff) | |
download | dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.gz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.bz2 dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.lz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.xz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.zst dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.zip |
core/vm: improved EVM run loop & instruction calling (#3378)
The run loop, which previously contained custom opcode executes have been
removed and has been simplified to a few checks.
Each operation consists of 4 elements: execution function, gas cost function,
stack validation function and memory size function. The execution function
implements the operation's runtime behaviour, the gas cost function implements
the operation gas costs function and greatly depends on the memory and stack,
the stack validation function validates the stack and makes sure that enough
items can be popped off and pushed on and the memory size function calculates
the memory required for the operation and returns it.
This commit also allows the EVM to go unmetered. This is helpful for offline
operations such as contract calls.
Diffstat (limited to 'core/vm/jit_util_test.go')
-rw-r--r-- | core/vm/jit_util_test.go | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/core/vm/jit_util_test.go b/core/vm/jit_util_test.go deleted file mode 100644 index 2123efe59..000000000 --- a/core/vm/jit_util_test.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package vm - -import "testing" - -type matchTest struct { - input []OpCode - match []OpCode - matches int -} - -func TestMatchFn(t *testing.T) { - tests := []matchTest{ - matchTest{ - []OpCode{PUSH1, PUSH1, MSTORE, JUMP}, - []OpCode{PUSH1, MSTORE}, - 1, - }, - matchTest{ - []OpCode{PUSH1, PUSH1, MSTORE, JUMP}, - []OpCode{PUSH1, MSTORE, PUSH1}, - 0, - }, - matchTest{ - []OpCode{}, - []OpCode{PUSH1}, - 0, - }, - } - - for i, test := range tests { - var matchCount int - MatchFn(test.input, test.match, func(i int) bool { - matchCount++ - return true - }) - if matchCount != test.matches { - t.Errorf("match count failed on test[%d]: expected %d matches, got %d", i, test.matches, matchCount) - } - } -} - -type parseTest struct { - base OpCode - size int - output OpCode -} - -func TestParser(t *testing.T) { - tests := []parseTest{ - parseTest{PUSH1, 32, PUSH}, - parseTest{DUP1, 16, DUP}, - parseTest{SWAP1, 16, SWAP}, - parseTest{MSTORE, 1, MSTORE}, - } - - for _, test := range tests { - for i := 0; i < test.size; i++ { - code := append([]byte{byte(byte(test.base) + byte(i))}, make([]byte, i+1)...) - output := Parse(code) - if len(output) == 0 { - t.Fatal("empty output") - } - if output[0] != test.output { - t.Errorf("%v failed: expected %v but got %v", test.base+OpCode(i), test.output, output[0]) - } - } - } -} |