github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/handler/addressAllocator_test.go (about) 1 package handler_test 2 3 import ( 4 "testing" 5 6 gethCommon "github.com/onflow/go-ethereum/common" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/fvm/evm/handler" 10 "github.com/onflow/flow-go/fvm/evm/types" 11 ) 12 13 func TestAddressAllocator(t *testing.T) { 14 aa := handler.NewAddressAllocator() 15 16 adr := aa.AllocatePrecompileAddress(3) 17 expectedAddress := types.NewAddress(gethCommon.HexToAddress("0x0000000000000000000000010000000000000003")) 18 require.Equal(t, expectedAddress, adr) 19 // check conforming to types 20 require.False(t, types.IsACOAAddress(adr)) 21 22 // test default value fall back 23 adr = aa.AllocateCOAAddress(1) 24 expectedAddress = types.NewAddress(gethCommon.HexToAddress("0x000000000000000000000002ffeeddccbbaa9977")) 25 require.Equal(t, expectedAddress, adr) 26 // check conforming to types 27 require.True(t, types.IsACOAAddress(adr)) 28 29 // continous allocation logic 30 adr = aa.AllocateCOAAddress(2) 31 expectedAddress = types.NewAddress(gethCommon.HexToAddress("0x000000000000000000000002ffddbb99775532ee")) 32 require.Equal(t, expectedAddress, adr) 33 // check conforming to types 34 require.True(t, types.IsACOAAddress(adr)) 35 36 // factory 37 factory := aa.COAFactoryAddress() 38 expectedAddress = types.NewAddress(gethCommon.HexToAddress("0x0000000000000000000000020000000000000000")) 39 require.Equal(t, expectedAddress, factory) 40 }