github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/core/asm/asm_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:34</date> 10 //</624450077204680704> 11 12 13 package asm 14 15 import ( 16 "testing" 17 18 "encoding/hex" 19 ) 20 21 //测试拆解有效EVM代码的说明 22 func TestInstructionIteratorValid(t *testing.T) { 23 cnt := 0 24 script, _ := hex.DecodeString("61000000") 25 26 it := NewInstructionIterator(script) 27 for it.Next() { 28 cnt++ 29 } 30 31 if err := it.Error(); err != nil { 32 t.Errorf("Expected 2, but encountered error %v instead.", err) 33 } 34 if cnt != 2 { 35 t.Errorf("Expected 2, but got %v instead.", cnt) 36 } 37 } 38 39 //测试反汇编无效EVM代码的指令 40 func TestInstructionIteratorInvalid(t *testing.T) { 41 cnt := 0 42 script, _ := hex.DecodeString("6100") 43 44 it := NewInstructionIterator(script) 45 for it.Next() { 46 cnt++ 47 } 48 49 if it.Error() == nil { 50 t.Errorf("Expected an error, but got %v instead.", cnt) 51 } 52 } 53 54 //测试反汇编空EVM代码的说明 55 func TestInstructionIteratorEmpty(t *testing.T) { 56 cnt := 0 57 script, _ := hex.DecodeString("") 58 59 it := NewInstructionIterator(script) 60 for it.Next() { 61 cnt++ 62 } 63 64 if err := it.Error(); err != nil { 65 t.Errorf("Expected 0, but encountered error %v instead.", err) 66 } 67 if cnt != 0 { 68 t.Errorf("Expected 0, but got %v instead.", cnt) 69 } 70 } 71