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