Repository: NethermindEth/juno (go)

Issue:
Reduce overall testing time of juno through changes in REST tests
Tests currently take a long time because the rest api tests which are meant to fail (within /pkg/rest/tests/rest_test.go) take a long time to timeout. 

This means that, while the rest of the test suite finishes in less than 10 seconds, all the Test(...)Fail take ~ 10s each, 13 times, incrementing this substantially and wasting time.

It would be good to have 1 timeout test with the normal rate, and the other failing tests to have a much smaller timeout or use a different method to check for failure than to wait out the full 10s.

Pull request description:
Speed up fail rest tests
Resolves #256 

## Changes:
- Extracted the hardcoded retry mechanism implemented in the http Do function.
- Allows the http client to take a retry mechanism as parameter which will then be used in the Do function.
- Test time before this PR
```
ok  	github.com/NethermindEth/juno/pkg/rest/tests	123.929s
```
- Test time after this PR
```
ok  	github.com/NethermindEth/juno/pkg/rest/tests	5.299s
```

## Types of changes

What types of changes does your code introduce?
_Put an `x` in the boxes that apply_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update
- [ ] Code style update (formatting, renaming)
- [X] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Other (please describe): 

## Testing
**Requires testing**

- [X] Yes
- [] No

**In case you checked yes, did you write tests??**

- [X] Yes
- [ ] No


Patch:
diff --git a/pkg/feeder/feeder.go b/pkg/feeder/feeder.go
index 40866322..eadb7bc3 100644
--- a/pkg/feeder/feeder.go
+++ b/pkg/feeder/feeder.go
@@ -23,7 +23,8 @@ type HttpClient interface {
 
 // Client represents a client for the StarkNet feeder gateway.
 type Client struct {
-	httpClient *HttpClient
+	httpClient        *HttpClient
+	retryFuncForDoReq func(req *http.Request, httpClient HttpClient, err error) (*http.Response, error)
 
 	BaseURL            *url.URL
 	BaseAPI, UserAgent string
@@ -41,7 +42,25 @@ func NewClient(baseURL, baseAPI string, client *HttpClient) *Client {
 		p = &c
 		client = &p
 	}
-	return &Client{BaseURL: u, BaseAPI: baseAPI, httpClient: client}
+
+	// retry mechanism for do requests
+	retryFuncForDoReq := func(req *http.Request, httpClient HttpClient, err error) (*http.Response, error) {
+		var res *http.Response
+		for i := 0; err != nil && i < 2; i++ {
+			time.Sleep(time.Second * 5)
+			res, err = httpClient.Do(req)
+		}
+		return res, err
+	}
+
+	return &Client{BaseURL: u, BaseAPI: baseAPI, httpClient: client, retryFuncForDoReq: retryFuncForDoReq}
+}
+
+func NewClientWithRetryFuncForDoReq(baseURL, baseAPI string, client *HttpClient, retryFunc func(req *http.Request, httpClient HttpClient, err error) (*http.Response, error)) *Client {
+	newClient := NewClient(baseURL, baseAPI, client)
+	newClient.retryFuncForDoReq = retryFunc
+
+	return newClient
 }
 
 func formattedBlockIdentifier(blockHash, blockNumber string) map[string]string {
@@ -106,10 +125,8 @@ func (c *Client) do(req *http.Request, v any) (*http.Response, error) {
 	metr.IncreaseRequestsSent()
 	res, err := (*c.httpClient).Do(req)
 	// notest
-	for i := 0; err != nil && i < 2; i++ {
-		time.Sleep(time.Second * 5)
-		res, err = (*c.httpClient).Do(req)
-	}
+	_, err = c.retryFuncForDoReq(req, *c.httpClient, err)
+
 	// We tried three times and still received an error
 	if err != nil {
 		metr.IncreaseRequestsFailed()
@@ -240,6 +257,7 @@ func (c Client) GetBlock(blockHash, blockNumber string) (*StarknetBlock, error)
 	}
 	var res StarknetBlock
 	metr.IncreaseBlockSent()
+
 	_, err = c.do(req, &res)
 	if err != nil {
 		metr.IncreaseBlockFailed()
diff --git a/pkg/rest/rest.go b/pkg/rest/rest.go
index c7bab633..8cf262d3 100644
--- a/pkg/rest/rest.go
+++ b/pkg/rest/rest.go
@@ -16,7 +16,7 @@ func (rh *RestHandler) GetBlock(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetBlock(strings.Join(blockHash, ""), strings.Join(blockNumber, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -36,7 +36,7 @@ func (rh *RestHandler) GetCode(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetCode(strings.Join(contractAddress, ""), strings.Join(blockHash, ""), strings.Join(blockNumber, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -57,7 +57,7 @@ func (rh *RestHandler) GetStorageAt(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetStorageAt(strings.Join(key, ""), strings.Join(contractAddress, ""), strings.Join(blockNumber, ""), strings.Join(blockHash, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -75,7 +75,7 @@ func (rh *RestHandler) GetTransactionStatus(w http.ResponseWriter, r *http.Reque
 		res, err := rh.RestFeeder.GetTransactionStatus(strings.Join(txHash, ""), strings.Join(txId, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -93,7 +93,7 @@ func (rh *RestHandler) GetTransactionReceipt(w http.ResponseWriter, r *http.Requ
 		res, err := rh.RestFeeder.GetTransactionReceipt(strings.Join(txHash, ""), strings.Join(txId, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -111,7 +111,7 @@ func (rh *RestHandler) GetTransaction(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetTransaction(strings.Join(txHash, ""), strings.Join(txId, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -130,7 +130,7 @@ func (rh *RestHandler) GetFullContract(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetFullContract(strings.Join(contractAddress, ""), strings.Join(blockHash, ""), strings.Join(blockNumber, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -148,7 +148,7 @@ func (rh *RestHandler) GetStateUpdate(w http.ResponseWriter, r *http.Request) {
 		res, err := rh.RestFeeder.GetStateUpdate(strings.Join(blockHash, ""), strings.Join(blockNumber, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -162,7 +162,7 @@ func (rh *RestHandler) GetContractAddresses(w http.ResponseWriter, r *http.Reque
 	res, err := rh.RestFeeder.GetContractAddresses()
 	if err != nil {
 		w.WriteHeader(http.StatusBadRequest) // 400 http status code
-		fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+		fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 		return
 	}
 	json.NewEncoder(w).Encode(res)
@@ -176,7 +176,7 @@ func (rh *RestHandler) GetBlockHashById(w http.ResponseWriter, r *http.Request)
 		res, err := rh.RestFeeder.GetBlockHashById(strings.Join(blockId, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -193,7 +193,7 @@ func (rh *RestHandler) GetBlockIDByHash(w http.ResponseWriter, r *http.Request)
 		res, err := rh.RestFeeder.GetBlockIDByHash(strings.Join(blockHash, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -210,7 +210,7 @@ func (rh *RestHandler) GetTransactionHashByID(w http.ResponseWriter, r *http.Req
 		res, err := rh.RestFeeder.GetTransactionHashByID(strings.Join(transactionId, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)
@@ -227,7 +227,7 @@ func (rh *RestHandler) GetTransactionIDByHash(w http.ResponseWriter, r *http.Req
 		res, err := rh.RestFeeder.GetTransactionIDByHash(strings.Join(transactionHash, ""))
 		if err != nil {
 			w.WriteHeader(http.StatusBadRequest) // 400 http status code
-			fmt.Fprintf(w, "Invalid request body error:%s", err.Error())
+			fmt.Fprintf(w, "Invalid request body error: %s", err.Error())
 			return
 		}
 		json.NewEncoder(w).Encode(res)


Test patch:
diff --git a/pkg/rest/tests/rest_test.go b/pkg/rest/tests/rest_test.go
index 8c5db05c..63b1b0ad 100644
--- a/pkg/rest/tests/rest_test.go
+++ b/pkg/rest/tests/rest_test.go
@@ -5,6 +5,7 @@ import (
 	"bytes"
 	"context"
 	"encoding/json"
+	"errors"
 	"io/ioutil"
 	"net/http"
 	"net/http/httptest"
@@ -20,12 +21,16 @@ import (
 )
 
 var (
-	httpClient      = &feederfakes.FakeHttpClient{}
-	failHttpClient  = &feederfakes.FailHttpClient{}
-	client          *feeder.Client
-	failClient      *feeder.Client
-	restHandler     = rest.RestHandler{}
-	failRestHandler = rest.RestHandler{}
+	httpClient         = &feederfakes.FakeHttpClient{}
+	failHttpClient     = &feederfakes.FailHttpClient{}
+	client             *feeder.Client
+	failClient         *feeder.Client
+	restHandler        = rest.RestHandler{}
+	failRestHandler    = rest.RestHandler{}
+	failRequestTimeout = time.Millisecond * 400
+	baseURL            = "https://localhost:8100"
+	baseAPI            = "/feeder_gateway/"
+	baseQuery          = baseURL + baseAPI
 )
 
 func init() {
@@ -33,9 +38,12 @@ func init() {
 	p = httpClient
 	var pf feeder.HttpClient
 	pf = failHttpClient
-	client = feeder.NewClient("https://localhost:8100", "/feeder_gateway/", &p)
+	client = feeder.NewClient(baseURL, baseAPI, &p)
 	restHandler.RestFeeder = client
-	failClient = feeder.NewClient("https://localhost:8100", "/feeder_gateway/", &pf)
+	failClient = feeder.NewClientWithRetryFuncForDoReq(baseURL, baseAPI, &pf, func(req *http.Request, httpClient feeder.HttpClient, err error) (*http.Response, error) {
+		time.Sleep(failRequestTimeout)
+		return httpClient.Do(req)
+	})
 	failRestHandler.RestFeeder = failClient
 }
 
@@ -76,6 +84,35 @@ func TestRestClient(t *testing.T) {
 	cancel()
 }
 
+// TestRestClientRetryFunction
+func TestRestClientRetryFunction(t *testing.T) {
+	queryStr := baseQuery + "/get_block"
+
+	// Build Request
+	req, err := http.NewRequest("GET", queryStr, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	// Query Args
+	rq := req.URL.Query()
+	rq.Add("blockNumber", "1")
+	rq.Add("blockHash", "hash")
+	req.URL.RawQuery = rq.Encode()
+
+	// Build Response Object
+	rr := httptest.NewRecorder()
+
+	errorMessage := "feeder gateway failed"
+	httpClient.DoReturns(nil, errors.New(errorMessage))
+
+	// Send Request expecting an error
+	restHandler.GetBlock(rr, req)
+
+	// Assert error message
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: "+errorMessage)
+}
+
 //---------------------------------------------
 //------------------TestHandlers---------------
 //---------------------------------------------
@@ -83,7 +120,7 @@ func TestRestClient(t *testing.T) {
 // TestGetBlockHandler
 func TestGetBlockHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_block"
+	queryStr := baseQuery + "/get_block"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -132,7 +169,7 @@ func TestGetBlockHandler(t *testing.T) {
 
 // TestGetCodeHandler
 func TestGetCodeHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_code"
+	queryStr := baseQuery + "/get_code"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -177,7 +214,7 @@ func TestGetCodeHandler(t *testing.T) {
 
 // TestGetStorageAtHandler
 func TestGetStorageAtHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_storage_at"
+	queryStr := baseQuery + "/get_storage_at"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -230,7 +267,7 @@ func TestGetStorageAtHandler(t *testing.T) {
 
 // TestGetTransactionStatusHandler
 func TestGetTransactionStatusHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_status"
+	queryStr := baseQuery + "/get_transaction_status"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -280,7 +317,7 @@ func TestGetTransactionStatusHandler(t *testing.T) {
 
 // TestGetTransactionReceiptHandler
 func TestGetTransactionRecieptHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_receipt"
+	queryStr := baseQuery + "/get_transaction_receipt"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -330,7 +367,7 @@ func TestGetTransactionRecieptHandler(t *testing.T) {
 
 // TestGetTransactionHandler
 func TestGetTransactionHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction"
+	queryStr := baseQuery + "/get_transaction_id"
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
@@ -379,7 +416,7 @@ func TestGetTransactionHandler(t *testing.T) {
 
 // TestGetFullContractHandler
 func TestGetFullContractHandler(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_full_contract"
+	queryStr := baseQuery + "/get_full_contract"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -421,7 +458,7 @@ func TestGetFullContractHandler(t *testing.T) {
 // TestGetStateUpdateHandler
 func TestGetStateUpdateHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_state_update"
+	queryStr := baseQuery + "/get_state_update"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -471,7 +508,7 @@ func TestGetStateUpdateHandler(t *testing.T) {
 // TestGetContractAddressesHandler
 func TestGetContractAddressesHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_contract_addresses"
+	queryStr := baseQuery + "/get_contract_addresses"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -515,7 +552,7 @@ func TestGetContractAddressesHandler(t *testing.T) {
 // TestGetBlockHashByIDHandler
 func TestGetBlockHashbyIdHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_hash_by_id"
+	queryStr := baseQuery + "/get_block_hash_by_id"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -564,7 +601,7 @@ func TestGetBlockHashbyIdHandler(t *testing.T) {
 // TestGetBlockIDbyHashHandler
 func TestGetBlockIDByHashHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_id_by_hash"
+	queryStr := baseQuery + "/get_block_id_by_hash"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -613,7 +650,7 @@ func TestGetBlockIDByHashHandler(t *testing.T) {
 // TestGetTransactionHashbyIdHandler
 func TestGetTransactionHashbyIdHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_hash_by_id"
+	queryStr := baseQuery + "/get_transaction_hash_by_id"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -662,7 +699,7 @@ func TestGetTransactionHashbyIdHandler(t *testing.T) {
 // TestGetTransactionIDbyHashHandler
 func TestGetTransactionIDByHashHandler(t *testing.T) {
 	// Build Request
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_id_by_hash"
+	queryStr := baseQuery + "/get_transaction_id_by_hash"
 	req, err := http.NewRequest("GET", queryStr, nil)
 	if err != nil {
 		t.Fatal(err)
@@ -714,7 +751,7 @@ func TestGetTransactionIDByHashHandler(t *testing.T) {
 
 // TestGetBlockWithoutBlockIdentifier
 func TestGetBlockWithoutBlockIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block"
+	queryStr := baseQuery + "/get_block"
 
 	// Build Response without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -733,7 +770,7 @@ func TestGetBlockWithoutBlockIdentifier(t *testing.T) {
 }
 
 func TestGetCodeWithoutContractAddressAndBlockIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_code"
+	queryStr := baseQuery + "/get_code"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -758,7 +795,7 @@ func TestGetCodeWithoutContractAddressAndBlockIdentifier(t *testing.T) {
 }
 
 func TestGetStorageAtWithoutKey(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction"
+	queryStr := baseQuery + "/get_transaction"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -784,7 +821,7 @@ func TestGetStorageAtWithoutKey(t *testing.T) {
 }
 
 func TestGetTransactionStatusWithoutTransactionIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_status"
+	queryStr := baseQuery + "/get_transaction_status"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -803,7 +840,7 @@ func TestGetTransactionStatusWithoutTransactionIdentifier(t *testing.T) {
 }
 
 func TestGetTransactionReceiptWithoutTransactionIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_receipt"
+	queryStr := baseQuery + "/get_transaction_receipt"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -822,7 +859,7 @@ func TestGetTransactionReceiptWithoutTransactionIdentifier(t *testing.T) {
 }
 
 func TestGetTransactionWithoutTransactionIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction"
+	queryStr := baseQuery + "/get_transaction"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -841,7 +878,7 @@ func TestGetTransactionWithoutTransactionIdentifier(t *testing.T) {
 }
 
 func TestGetFullContractAtWithoutContractAddress(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction"
+	queryStr := baseQuery + "/get_transaction"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -866,7 +903,7 @@ func TestGetFullContractAtWithoutContractAddress(t *testing.T) {
 }
 
 func TestGetStateUpdateWithoutBlockIdentifier(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_state_update"
+	queryStr := baseQuery + "/get_state_update"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -886,7 +923,7 @@ func TestGetStateUpdateWithoutBlockIdentifier(t *testing.T) {
 
 // TestGetBlockHashByIDWithoutTransactionId
 func TestGetBlockHashByIDWithoutTransactionId(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_id_by_hash"
+	queryStr := baseQuery + "/get_block_id_by_hash"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -906,7 +943,7 @@ func TestGetBlockHashByIDWithoutTransactionId(t *testing.T) {
 
 // TestGetBlockIDByHashWithoutTransactionHash
 func TestGetBlockIDByHashWithoutTransactionHash(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_id_by_hash"
+	queryStr := baseQuery + "/get_block_id_by_hash"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -926,7 +963,7 @@ func TestGetBlockIDByHashWithoutTransactionHash(t *testing.T) {
 
 // TestGetTransactionHashByIDWithoutTransactionId
 func TestGetTransactionHashByIDWithoutTransactionId(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_id_by_hash"
+	queryStr := baseQuery + "/get_transaction_id_by_hash"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -946,7 +983,7 @@ func TestGetTransactionHashByIDWithoutTransactionId(t *testing.T) {
 
 // TestGetTransactionIDByHashWithoutTransactionHash
 func TestGetTransactionIDByHashWithoutTransactionHash(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_id_by_hash"
+	queryStr := baseQuery + "/get_transaction_id_by_hash"
 
 	// Build Request without Query Args
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -970,7 +1007,7 @@ func TestGetTransactionIDByHashWithoutTransactionHash(t *testing.T) {
 
 // TestGetBlockHandlerFeederFail
 func TestGetBlockHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block"
+	queryStr := baseQuery + "/get_block"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -991,12 +1028,12 @@ func TestGetBlockHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetBlock(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetCodeHandlerFeederFail
 func TestGetCodeHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_code"
+	queryStr := baseQuery + "/get_code"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1018,12 +1055,12 @@ func TestGetCodeHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetCode(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetStorageAtHandlerFeederFail
 func TestGetStorageAtHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_storage_at"
+	queryStr := baseQuery + "/get_storage_at"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1046,12 +1083,12 @@ func TestGetStorageAtHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetStorageAt(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetTransactionStatusHandlerFeederFail
 func TestGetTransactionStatusHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_status"
+	queryStr := baseQuery + "/get_transaction_status"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1072,12 +1109,12 @@ func TestGetTransactionStatusHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetTransactionStatus(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetTransactionReceiptHandlerFeederFail
 func TestGetTransactionReceiptHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_receipt"
+	queryStr := baseQuery + "/get_transaction_receipt"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1098,12 +1135,12 @@ func TestGetTransactionReceiptHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetTransactionReceipt(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetTransactionHandlerFeederFail
 func TestGetTransactionHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction"
+	queryStr := baseQuery + "/get_transaction"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1124,12 +1161,12 @@ func TestGetTransactionHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetTransaction(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetFullContractHandlerFeederFail
 func TestGetFullContractHandlerFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_full_contract"
+	queryStr := baseQuery + "/get_full_contract"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1151,12 +1188,12 @@ func TestGetFullContractHandlerFeederFail(t *testing.T) {
 	failRestHandler.GetFullContract(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetStateUpdateHandlerFeederFail
 func TestGetStateUpdateFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_state_update"
+	queryStr := baseQuery + "/get_state_update"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1177,12 +1214,12 @@ func TestGetStateUpdateFeederFail(t *testing.T) {
 	failRestHandler.GetStateUpdate(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetContractAddressesFeederFail
 func TestGetContractAddressesFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_contract_addresses"
+	queryStr := baseQuery + "/get_contract_addresses"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1197,12 +1234,12 @@ func TestGetContractAddressesFeederFail(t *testing.T) {
 	failRestHandler.GetContractAddresses(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetBlockIDByHashFeederFail
 func TestGetBlockIDByHashFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_id_by_hash"
+	queryStr := baseQuery + "/get_block_id_by_hash"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1222,12 +1259,12 @@ func TestGetBlockIDByHashFeederFail(t *testing.T) {
 	failRestHandler.GetBlockIDByHash(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetBlockHashByIDFeederFail
 func TestGetBlockHashByIDFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_block_hash_by_id"
+	queryStr := baseQuery + "/get_block_hash_by_id"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1247,12 +1284,12 @@ func TestGetBlockHashByIDFeederFail(t *testing.T) {
 	failRestHandler.GetBlockHashById(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetTransactionIDByHashFeederFail
 func TestGetTransactionIDByHashFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_id_by_hash"
+	queryStr := baseQuery + "/get_transaction_id_by_hash"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1272,12 +1309,12 @@ func TestGetTransactionIDByHashFeederFail(t *testing.T) {
 	failRestHandler.GetTransactionIDByHash(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }
 
 // TestGetBlockHashByIDFeederFail
 func TestGetTransactionHashByIDFeederFail(t *testing.T) {
-	queryStr := "http://localhost:8100/feeder_gateway/get_transaction_hash_by_id"
+	queryStr := baseQuery + "/get_transaction_hash_by_id"
 
 	// Build Request
 	req, err := http.NewRequest("GET", queryStr, nil)
@@ -1297,5 +1334,5 @@ func TestGetTransactionHashByIDFeederFail(t *testing.T) {
 	failRestHandler.GetTransactionHashByID(rr, req)
 
 	// Assert error message
-	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error:feeder gateway failed")
+	assert.DeepEqual(t, rr.Body.String(), "Invalid request body error: feeder gateway failed")
 }