Browse Source

Fix inconsistency between api doc and code: hermezEthereumAddress => hezEthereumAddress

feature/sql-semaphore1
Arnau B 3 years ago
parent
commit
226c49f28f
6 changed files with 18 additions and 13 deletions
  1. +7
    -2
      api/account_test.go
  2. +1
    -1
      api/api.go
  3. +2
    -2
      api/exits_test.go
  4. +5
    -5
      api/parsers.go
  5. +1
    -1
      api/parsers_test.go
  6. +2
    -2
      api/txshistory_test.go

+ 7
- 2
api/account_test.go

@ -81,14 +81,14 @@ func TestGetAccounts(t *testing.T) {
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts)) assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{} fetchedAccounts = []testAccount{}
// Filter by ethAddr // 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) err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err) assert.NoError(t, err)
assert.Greater(t, len(fetchedAccounts), 0) assert.Greater(t, len(fetchedAccounts), 0)
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts)) assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{} fetchedAccounts = []testAccount{}
// both filters (incompatible) // 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) err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err) assert.NoError(t, err)
fetchedAccounts = []testAccount{} fetchedAccounts = []testAccount{}
@ -144,6 +144,11 @@ func TestGetAccounts(t *testing.T) {
assert.Equal(t, reversedAccounts[i], fetchedAccounts[len(fetchedAccounts)-1-i]) 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 // Test GetAccount
path = fmt.Sprintf("%s/%s", endpoint, fetchedAccounts[2].Idx) path = fmt.Sprintf("%s/%s", endpoint, fetchedAccounts[2].Idx)
account := testAccount{} account := testAccount{}

+ 1
- 1
api/api.go

@ -72,7 +72,7 @@ func NewAPI(
if coordinatorEndpoints { if coordinatorEndpoints {
// Account // Account
server.POST("/account-creation-authorization", a.postAccountCreationAuth) server.POST("/account-creation-authorization", a.postAccountCreationAuth)
server.GET("/account-creation-authorization/:hermezEthereumAddress", a.getAccountCreationAuth)
server.GET("/account-creation-authorization/:hezEthereumAddress", a.getAccountCreationAuth)
// Transaction // Transaction
server.POST("/transactions-pool", a.postPoolTx) server.POST("/transactions-pool", a.postPoolTx)
server.GET("/transactions-pool/:id", a.getPoolTx) server.GET("/transactions-pool/:id", a.getPoolTx)

+ 2
- 2
api/exits_test.go

@ -124,7 +124,7 @@ func TestGetExits(t *testing.T) {
} }
} }
path = fmt.Sprintf( path = fmt.Sprintf(
"%s?hermezEthereumAddress=%s&limit=%d",
"%s?hezEthereumAddress=%s&limit=%d",
endpoint, account.EthAddr, limit, endpoint, account.EthAddr, limit,
) )
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter) err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -244,7 +244,7 @@ func TestGetExits(t *testing.T) {
assertExitAPIs(t, flipedExits, fetchedExits) assertExitAPIs(t, flipedExits, fetchedExits)
// 400 // 400
path = fmt.Sprintf( path = fmt.Sprintf(
"%s?accountIndex=%s&hermezEthereumAddress=%s",
"%s?accountIndex=%s&hezEthereumAddress=%s",
endpoint, idx, account.EthAddr, endpoint, idx, account.EthAddr,
) )
err = doBadReq("GET", path, nil, 400) err = doBadReq("GET", path, nil, 400)

+ 5
- 5
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) { func parseQueryHezEthAddr(c querier) (*ethCommon.Address, error) {
const name = "hermezEthereumAddress"
const name = "hezEthereumAddress"
addrStr := c.Query(name) addrStr := c.Query(name)
return hezStringToEthAddr(addrStr, 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) return nil, nil, nil, nil, tracerr.Wrap(err)
} }
if addr != nil && bjj != nil { 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
idx, err := parseIdx(c) 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) return nil, nil, nil, nil, tracerr.Wrap(err)
} }
if idx != nil && (addr != nil || bjj != nil || tokenID != nil) { 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 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) return nil, nil, nil, tracerr.Wrap(err)
} }
if addr != nil && bjj != nil { 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 return tokenIDs, addr, bjj, nil
@ -427,7 +427,7 @@ func parseEthAddr(ethAddrStr string) (*ethCommon.Address, error) {
} }
func parseParamHezEthAddr(c paramer) (*ethCommon.Address, error) { func parseParamHezEthAddr(c paramer) (*ethCommon.Address, error) {
const name = "hermezEthereumAddress"
const name = "hezEthereumAddress"
addrStr := c.Param(name) addrStr := c.Param(name)
return hezStringToEthAddr(addrStr, name) return hezStringToEthAddr(addrStr, name)
} }

+ 1
- 1
api/parsers_test.go

@ -163,7 +163,7 @@ func TestParsePagination(t *testing.T) {
} }
func TestParseQueryHezEthAddr(t *testing.T) { func TestParseQueryHezEthAddr(t *testing.T) {
name := "hermezEthereumAddress"
name := "hezEthereumAddress"
c := &queryParser{} c := &queryParser{}
c.m = make(map[string]string) c.m = make(map[string]string)
ethAddr := ethCommon.BigToAddress(big.NewInt(int64(347683))) ethAddr := ethCommon.BigToAddress(big.NewInt(int64(347683)))

+ 2
- 2
api/txshistory_test.go

@ -269,7 +269,7 @@ func TestGetHistoryTxs(t *testing.T) {
fetchedTxs = []testTx{} fetchedTxs = []testTx{}
limit = 7 limit = 7
path = fmt.Sprintf( path = fmt.Sprintf(
"%s?hermezEthereumAddress=%s&limit=%d",
"%s?hezEthereumAddress=%s&limit=%d",
endpoint, account.EthAddr, limit, endpoint, account.EthAddr, limit,
) )
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter) err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -422,7 +422,7 @@ func TestGetHistoryTxs(t *testing.T) {
assertTxs(t, flipedTxs, fetchedTxs) assertTxs(t, flipedTxs, fetchedTxs)
// 400 // 400
path = fmt.Sprintf( path = fmt.Sprintf(
"%s?accountIndex=%s&hermezEthereumAddress=%s",
"%s?accountIndex=%s&hezEthereumAddress=%s",
endpoint, idx, account.EthAddr, endpoint, idx, account.EthAddr,
) )
err = doBadReq("GET", path, nil, 400) err = doBadReq("GET", path, nil, 400)

Loading…
Cancel
Save