From 226c49f28f9af467913b14faae7b1177c657be9d Mon Sep 17 00:00:00 2001 From: Arnau B Date: Wed, 16 Dec 2020 12:29:46 +0100 Subject: [PATCH] Fix inconsistency between api doc and code: hermezEthereumAddress => hezEthereumAddress --- api/account_test.go | 9 +++++++-- api/api.go | 2 +- api/exits_test.go | 4 ++-- api/parsers.go | 10 +++++----- api/parsers_test.go | 2 +- api/txshistory_test.go | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/api/account_test.go b/api/account_test.go index 0f2f3bf..80c325b 100644 --- a/api/account_test.go +++ b/api/account_test.go @@ -81,14 +81,14 @@ func TestGetAccounts(t *testing.T) { assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts)) fetchedAccounts = []testAccount{} // Filter by ethAddr - path = fmt.Sprintf("%s?hermezEthereumAddress=%s&limit=%d", endpoint, tc.accounts[3].EthAddr, limit) + path = fmt.Sprintf("%s?hezEthereumAddress=%s&limit=%d", endpoint, tc.accounts[3].EthAddr, limit) err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter) assert.NoError(t, err) assert.Greater(t, len(fetchedAccounts), 0) assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts)) fetchedAccounts = []testAccount{} // both filters (incompatible) - path = fmt.Sprintf("%s?hermezEthereumAddress=%s&BJJ=%s&limit=%d", endpoint, tc.accounts[0].EthAddr, tc.accounts[0].PublicKey, limit) + path = fmt.Sprintf("%s?hezEthereumAddress=%s&BJJ=%s&limit=%d", endpoint, tc.accounts[0].EthAddr, tc.accounts[0].PublicKey, limit) err = doBadReq("GET", path, nil, 400) assert.NoError(t, err) fetchedAccounts = []testAccount{} @@ -144,6 +144,11 @@ func TestGetAccounts(t *testing.T) { assert.Equal(t, reversedAccounts[i], fetchedAccounts[len(fetchedAccounts)-1-i]) } + // 400 + path = fmt.Sprintf("%s?hezEthereumAddress=hez:0x123456", endpoint) + err = doBadReq("GET", path, nil, 400) + assert.NoError(t, err) + // Test GetAccount path = fmt.Sprintf("%s/%s", endpoint, fetchedAccounts[2].Idx) account := testAccount{} diff --git a/api/api.go b/api/api.go index 89c34ca..d374aa6 100644 --- a/api/api.go +++ b/api/api.go @@ -72,7 +72,7 @@ func NewAPI( if coordinatorEndpoints { // Account server.POST("/account-creation-authorization", a.postAccountCreationAuth) - server.GET("/account-creation-authorization/:hermezEthereumAddress", a.getAccountCreationAuth) + server.GET("/account-creation-authorization/:hezEthereumAddress", a.getAccountCreationAuth) // Transaction server.POST("/transactions-pool", a.postPoolTx) server.GET("/transactions-pool/:id", a.getPoolTx) diff --git a/api/exits_test.go b/api/exits_test.go index a92b499..3ac3c0a 100644 --- a/api/exits_test.go +++ b/api/exits_test.go @@ -124,7 +124,7 @@ func TestGetExits(t *testing.T) { } } path = fmt.Sprintf( - "%s?hermezEthereumAddress=%s&limit=%d", + "%s?hezEthereumAddress=%s&limit=%d", endpoint, account.EthAddr, limit, ) err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter) @@ -244,7 +244,7 @@ func TestGetExits(t *testing.T) { assertExitAPIs(t, flipedExits, fetchedExits) // 400 path = fmt.Sprintf( - "%s?accountIndex=%s&hermezEthereumAddress=%s", + "%s?accountIndex=%s&hezEthereumAddress=%s", endpoint, idx, account.EthAddr, ) err = doBadReq("GET", path, nil, 400) diff --git a/api/parsers.go b/api/parsers.go index 20e9536..0e4a60c 100644 --- a/api/parsers.go +++ b/api/parsers.go @@ -82,7 +82,7 @@ func parseQueryBool(name string, dflt *bool, c querier) (*bool, error) { //nolin } func parseQueryHezEthAddr(c querier) (*ethCommon.Address, error) { - const name = "hermezEthereumAddress" + const name = "hezEthereumAddress" addrStr := c.Query(name) return hezStringToEthAddr(addrStr, name) } @@ -168,7 +168,7 @@ func parseExitFilters(c querier) (*common.TokenID, *ethCommon.Address, *babyjub. return nil, nil, nil, nil, tracerr.Wrap(err) } if addr != nil && bjj != nil { - return nil, nil, nil, nil, tracerr.Wrap(errors.New("bjj and hermezEthereumAddress params are incompatible")) + return nil, nil, nil, nil, tracerr.Wrap(errors.New("bjj and hezEthereumAddress params are incompatible")) } // Idx idx, err := parseIdx(c) @@ -176,7 +176,7 @@ func parseExitFilters(c querier) (*common.TokenID, *ethCommon.Address, *babyjub. return nil, nil, nil, nil, tracerr.Wrap(err) } if idx != nil && (addr != nil || bjj != nil || tokenID != nil) { - return nil, nil, nil, nil, tracerr.Wrap(errors.New("accountIndex is incompatible with BJJ, hermezEthereumAddress and tokenId")) + return nil, nil, nil, nil, tracerr.Wrap(errors.New("accountIndex is incompatible with BJJ, hezEthereumAddress and tokenId")) } return tokenID, addr, bjj, idx, nil } @@ -264,7 +264,7 @@ func parseAccountFilters(c querier) ([]common.TokenID, *ethCommon.Address, *baby return nil, nil, nil, tracerr.Wrap(err) } if addr != nil && bjj != nil { - return nil, nil, nil, tracerr.Wrap(errors.New("bjj and hermezEthereumAddress params are incompatible")) + return nil, nil, nil, tracerr.Wrap(errors.New("bjj and hezEthereumAddress params are incompatible")) } return tokenIDs, addr, bjj, nil @@ -427,7 +427,7 @@ func parseEthAddr(ethAddrStr string) (*ethCommon.Address, error) { } func parseParamHezEthAddr(c paramer) (*ethCommon.Address, error) { - const name = "hermezEthereumAddress" + const name = "hezEthereumAddress" addrStr := c.Param(name) return hezStringToEthAddr(addrStr, name) } diff --git a/api/parsers_test.go b/api/parsers_test.go index f9ba38b..f166617 100644 --- a/api/parsers_test.go +++ b/api/parsers_test.go @@ -163,7 +163,7 @@ func TestParsePagination(t *testing.T) { } func TestParseQueryHezEthAddr(t *testing.T) { - name := "hermezEthereumAddress" + name := "hezEthereumAddress" c := &queryParser{} c.m = make(map[string]string) ethAddr := ethCommon.BigToAddress(big.NewInt(int64(347683))) diff --git a/api/txshistory_test.go b/api/txshistory_test.go index 9d7855a..cb70100 100644 --- a/api/txshistory_test.go +++ b/api/txshistory_test.go @@ -269,7 +269,7 @@ func TestGetHistoryTxs(t *testing.T) { fetchedTxs = []testTx{} limit = 7 path = fmt.Sprintf( - "%s?hermezEthereumAddress=%s&limit=%d", + "%s?hezEthereumAddress=%s&limit=%d", endpoint, account.EthAddr, limit, ) err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter) @@ -422,7 +422,7 @@ func TestGetHistoryTxs(t *testing.T) { assertTxs(t, flipedTxs, fetchedTxs) // 400 path = fmt.Sprintf( - "%s?accountIndex=%s&hermezEthereumAddress=%s", + "%s?accountIndex=%s&hezEthereumAddress=%s", endpoint, idx, account.EthAddr, ) err = doBadReq("GET", path, nil, 400)