github.com/klaytn/klaytn@v1.12.1/blockchain/asm/asm_test.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from core/asm/asm_test.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package asm 22 23 import ( 24 "encoding/hex" 25 "testing" 26 ) 27 28 // Tests disassembling the instructions for valid evm code 29 func TestInstructionIteratorValid(t *testing.T) { 30 cnt := 0 31 script, _ := hex.DecodeString("61000000") 32 33 it := NewInstructionIterator(script) 34 for it.Next() { 35 cnt++ 36 } 37 38 if err := it.Error(); err != nil { 39 t.Errorf("Expected 2, but encountered error %v instead.", err) 40 } 41 if cnt != 2 { 42 t.Errorf("Expected 2, but got %v instead.", cnt) 43 } 44 } 45 46 // Tests disassembling the instructions for invalid evm code 47 func TestInstructionIteratorInvalid(t *testing.T) { 48 cnt := 0 49 script, _ := hex.DecodeString("6100") 50 51 it := NewInstructionIterator(script) 52 for it.Next() { 53 cnt++ 54 } 55 56 if it.Error() == nil { 57 t.Errorf("Expected an error, but got %v instead.", cnt) 58 } 59 } 60 61 // Tests disassembling the instructions for empty evm code 62 func TestInstructionIteratorEmpty(t *testing.T) { 63 cnt := 0 64 script, _ := hex.DecodeString("") 65 66 it := NewInstructionIterator(script) 67 for it.Next() { 68 cnt++ 69 } 70 71 if err := it.Error(); err != nil { 72 t.Errorf("Expected 0, but encountered error %v instead.", err) 73 } 74 if cnt != 0 { 75 t.Errorf("Expected 0, but got %v instead.", cnt) 76 } 77 }