github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/rest/routes/network_test.go (about) 1 package routes 2 3 import ( 4 "fmt" 5 "net/http" 6 "net/url" 7 "testing" 8 9 mocktestify "github.com/stretchr/testify/mock" 10 "github.com/stretchr/testify/require" 11 12 "github.com/onflow/flow-go/access" 13 "github.com/onflow/flow-go/access/mock" 14 "github.com/onflow/flow-go/model/flow" 15 ) 16 17 func networkURL(t *testing.T) string { 18 u, err := url.ParseRequestURI("/v1/network/parameters") 19 require.NoError(t, err) 20 21 return u.String() 22 } 23 24 func TestGetNetworkParameters(t *testing.T) { 25 backend := &mock.API{} 26 27 t.Run("get network parameters on mainnet", func(t *testing.T) { 28 29 req := getNetworkParametersRequest(t) 30 31 params := access.NetworkParameters{ 32 ChainID: flow.Mainnet, 33 } 34 35 backend.Mock. 36 On("GetNetworkParameters", mocktestify.Anything). 37 Return(params) 38 39 expected := networkParametersExpectedStr(flow.Mainnet) 40 41 assertOKResponse(t, req, expected, backend) 42 mocktestify.AssertExpectationsForObjects(t, backend) 43 }) 44 } 45 46 func networkParametersExpectedStr(chainID flow.ChainID) string { 47 return fmt.Sprintf(`{ 48 "chain_id": "%s" 49 }`, chainID) 50 } 51 52 func getNetworkParametersRequest(t *testing.T) *http.Request { 53 req, err := http.NewRequest("GET", networkURL(t), nil) 54 require.NoError(t, err) 55 return req 56 }