github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/core/vm/gas_table_test.go (about)

     1  package vm
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  func TestMemoryGasCost(t *testing.T) {
     9  	tests := []struct {
    10  		size     uint64
    11  		cost     uint64
    12  		overflow bool
    13  	}{
    14  		{0x1fffffffe0, 36028809887088637, false},
    15  		{0x1fffffffe1, 0, true},
    16  	}
    17  	for i, tt := range tests {
    18  		v, err := memoryGasCost(&Memory{}, tt.size)
    19  		if (err == errGasUintOverflow) != tt.overflow {
    20  			t.Errorf("test %d: overflow mismatch: have %v, want %v", i, err == errGasUintOverflow, tt.overflow)
    21  		}
    22  		if v != tt.cost {
    23  			t.Errorf("test %d: gas cost mismatch: have %v, want %v", i, v, tt.cost)
    24  		}
    25  	}
    26  }
    27  
    28  var eip2200Tests = []struct {
    29  	original byte
    30  	gaspool  uint64
    31  	input    string
    32  	used     uint64
    33  	refund   uint64
    34  	failure  error
    35  }{
    36  	{0, math.MaxUint64, "0x60006000556000600055", 1612, 0, nil},
    37  	{0, math.MaxUint64, "0x60006000556001600055", 20812, 0, nil},
    38  	{0, math.MaxUint64, "0x60016000556000600055", 20812, 19200, nil},
    39  	{0, math.MaxUint64, "0x60016000556002600055", 20812, 0, nil},
    40  	{0, math.MaxUint64, "0x60016000556001600055", 20812, 0, nil},
    41  	{1, math.MaxUint64, "0x60006000556000600055", 5812, 15000, nil},
    42  	{1, math.MaxUint64, "0x60006000556001600055", 5812, 4200, nil},
    43  	{1, math.MaxUint64, "0x60006000556002600055", 5812, 0, nil},
    44  	{1, math.MaxUint64, "0x60026000556000600055", 5812, 15000, nil},
    45  	{1, math.MaxUint64, "0x60026000556003600055", 5812, 0, nil},
    46  	{1, math.MaxUint64, "0x60026000556001600055", 5812, 4200, nil},
    47  	{1, math.MaxUint64, "0x60026000556002600055", 5812, 0, nil},
    48  	{1, math.MaxUint64, "0x60016000556000600055", 5812, 15000, nil},
    49  	{1, math.MaxUint64, "0x60016000556002600055", 5812, 0, nil},
    50  	{1, math.MaxUint64, "0x60016000556001600055", 1612, 0, nil},
    51  	{0, math.MaxUint64, "0x600160005560006000556001600055", 40818, 19200, nil},
    52  	{1, math.MaxUint64, "0x600060005560016000556000600055", 10818, 19200, nil},
    53  	{1, 2306, "0x6001600055", 2306, 0, ErrOutOfGas},
    54  	{1, 2307, "0x6001600055", 806, 0, nil},
    55  }