github.com/reapchain/go-reapchain@v0.2.15-0.20210609012950-9735c110c705/core/vm/instructions_test.go (about)

     1  package vm
     2  
     3  import (
     4  	"math/big"
     5  	"testing"
     6  
     7  	"github.com/ethereum/go-ethereum/common"
     8  	"github.com/ethereum/go-ethereum/params"
     9  )
    10  
    11  func TestByteOp(t *testing.T) {
    12  	var (
    13  		env   = NewEVM(Context{}, nil, params.TestChainConfig, Config{EnableJit: false, ForceJit: false})
    14  		stack = newstack()
    15  	)
    16  	tests := []struct {
    17  		v        string
    18  		th       uint64
    19  		expected *big.Int
    20  	}{
    21  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, big.NewInt(0xAB)},
    22  		{"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, big.NewInt(0xCD)},
    23  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, big.NewInt(0x00)},
    24  		{"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, big.NewInt(0xCD)},
    25  		{"0000000000000000000000000000000000000000000000000000000000102030", 31, big.NewInt(0x30)},
    26  		{"0000000000000000000000000000000000000000000000000000000000102030", 30, big.NewInt(0x20)},
    27  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, big.NewInt(0x0)},
    28  		{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFFFFFFFFFFFFFF, big.NewInt(0x0)},
    29  	}
    30  	pc := uint64(0)
    31  	for _, test := range tests {
    32  		val := new(big.Int).SetBytes(common.Hex2Bytes(test.v))
    33  		th := new(big.Int).SetUint64(test.th)
    34  		stack.push(val)
    35  		stack.push(th)
    36  		opByte(&pc, env, nil, nil, stack)
    37  		actual := stack.pop()
    38  		if actual.Cmp(test.expected) != 0 {
    39  			t.Fatalf("Expected  [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual)
    40  		}
    41  	}
    42  }