github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/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 instructions 26 func TestInstructionIterator(t *testing.T) { 27 for i, tc := range []struct { 28 want int 29 code string 30 wantErr string 31 }{ 32 {2, "61000000", ""}, // valid code 33 {0, "6100", "incomplete push instruction at 0"}, // invalid code 34 {2, "5900", ""}, // push0 35 {0, "", ""}, // empty 36 37 } { 38 var ( 39 have int 40 code, _ = hex.DecodeString(tc.code) 41 it = NewInstructionIterator(code) 42 ) 43 for it.Next() { 44 have++ 45 } 46 var haveErr = "" 47 if it.Error() != nil { 48 haveErr = it.Error().Error() 49 } 50 if haveErr != tc.wantErr { 51 t.Errorf("test %d: encountered error: %q want %q", i, haveErr, tc.wantErr) 52 continue 53 } 54 if have != tc.want { 55 t.Errorf("wrong instruction count, have %d want %d", have, tc.want) 56 } 57 } 58 }