github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/precompiles/selector_test.go (about) 1 package precompiles_test 2 3 import ( 4 "testing" 5 6 gethCrypto "github.com/onflow/go-ethereum/crypto" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/fvm/evm/precompiles" 10 ) 11 12 func TestFunctionSelector(t *testing.T) { 13 t.Parallel() 14 15 expected := gethCrypto.Keccak256([]byte("test()"))[:4] 16 require.Equal(t, expected, precompiles.ComputeFunctionSelector("test", nil).Bytes()) 17 18 expected = gethCrypto.Keccak256([]byte("test(uint32,uint16)"))[:precompiles.FunctionSelectorLength] 19 require.Equal(t, expected, 20 precompiles.ComputeFunctionSelector("test", []string{"uint32", "uint16"}).Bytes()) 21 22 selector := []byte{1, 2, 3, 4} 23 data := []byte{5, 6, 7, 8} 24 retSelector, retData := precompiles.SplitFunctionSelector(append(selector, data...)) 25 require.Equal(t, selector, retSelector[:]) 26 require.Equal(t, data, retData) 27 }