github.com/klaytn/klaytn@v1.10.2/params/protocol_params_test.go (about)

     1  package params
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  var testCaseWithBinaryCodeFormat = []struct {
    10  	cf                     CodeInfo
    11  	getCodeFormatExpectVal CodeFormat
    12  	validateExpectVal      bool
    13  	getVmVersionExpectVal  VmVersion
    14  	stringExpectVal        string
    15  }{
    16  	{0b00000000, CodeFormatEVM, true, VmVersion0, "CodeFormatEVM"},
    17  	{0b00010000, CodeFormatEVM, true, VmVersion1, "CodeFormatEVM"},
    18  	{0b00000001, CodeFormatLast, false, VmVersion0, "UndefinedCodeFormat"},
    19  	{0b00010001, CodeFormatLast, false, VmVersion1, "UndefinedCodeFormat"},
    20  }
    21  
    22  func TestGetCodeFormat(t *testing.T) {
    23  	for _, tc := range testCaseWithBinaryCodeFormat {
    24  		assert.Equal(t, tc.getCodeFormatExpectVal, tc.cf.GetCodeFormat())
    25  	}
    26  }
    27  
    28  func TestString(t *testing.T) {
    29  	for _, tc := range testCaseWithBinaryCodeFormat {
    30  		assert.Equal(t, tc.stringExpectVal, tc.cf.GetCodeFormat().String())
    31  	}
    32  }
    33  
    34  func TestValidate(t *testing.T) {
    35  	for _, tc := range testCaseWithBinaryCodeFormat {
    36  		assert.Equal(t, tc.validateExpectVal, tc.cf.GetCodeFormat().Validate())
    37  	}
    38  }
    39  
    40  func TestGetVmVersion(t *testing.T) {
    41  	for _, tc := range testCaseWithBinaryCodeFormat {
    42  		assert.Equal(t, tc.getVmVersionExpectVal, tc.cf.GetVmVersion())
    43  	}
    44  }
    45  
    46  func TestSetVmVersion(t *testing.T) {
    47  	testCaseSetIstanbulHFField := []struct {
    48  		cf                        CodeFormat
    49  		isDeployedAfterIstanbulHF bool
    50  		ifDeployedAfterLondonHF   bool
    51  		expectCi                  CodeInfo
    52  	}{
    53  		{CodeFormatEVM, false, false, 0b00000000},
    54  		{CodeFormatEVM, true, false, 0b00010000},
    55  		{CodeFormatEVM, true, true, 0b00010000},
    56  	}
    57  	for _, tc := range testCaseSetIstanbulHFField {
    58  		assert.Equal(t, tc.expectCi, NewCodeInfoWithRules(tc.cf, Rules{IsIstanbul: tc.isDeployedAfterIstanbulHF}))
    59  	}
    60  }