github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/core/asm/asm_test.go (about)

     1  package asm
     2  
     3  import (
     4  	"testing"
     5  
     6  	"encoding/hex"
     7  )
     8  
     9  // Tests disassembling the instructions for valid evm code
    10  func TestInstructionIteratorValid(t *testing.T) {
    11  	cnt := 0
    12  	script, _ := hex.DecodeString("61000000")
    13  
    14  	it := NewInstructionIterator(script)
    15  	for it.Next() {
    16  		cnt++
    17  	}
    18  
    19  	if err := it.Error(); err != nil {
    20  		t.Errorf("Expected 2, but encountered error %v instead.", err)
    21  	}
    22  	if cnt != 2 {
    23  		t.Errorf("Expected 2, but got %v instead.", cnt)
    24  	}
    25  }
    26  
    27  // Tests disassembling the instructions for invalid evm code
    28  func TestInstructionIteratorInvalid(t *testing.T) {
    29  	cnt := 0
    30  	script, _ := hex.DecodeString("6100")
    31  
    32  	it := NewInstructionIterator(script)
    33  	for it.Next() {
    34  		cnt++
    35  	}
    36  
    37  	if it.Error() == nil {
    38  		t.Errorf("Expected an error, but got %v instead.", cnt)
    39  	}
    40  }
    41  
    42  // Tests disassembling the instructions for empty evm code
    43  func TestInstructionIteratorEmpty(t *testing.T) {
    44  	cnt := 0
    45  	script, _ := hex.DecodeString("")
    46  
    47  	it := NewInstructionIterator(script)
    48  	for it.Next() {
    49  		cnt++
    50  	}
    51  
    52  	if err := it.Error(); err != nil {
    53  		t.Errorf("Expected 0, but encountered error %v instead.", err)
    54  	}
    55  	if cnt != 0 {
    56  		t.Errorf("Expected 0, but got %v instead.", cnt)
    57  	}
    58  }