|
@ -41,6 +41,7 @@ type testCommon struct { |
|
|
blocks []common.Block |
|
|
blocks []common.Block |
|
|
tokens []tokenAPI |
|
|
tokens []tokenAPI |
|
|
batches []common.Batch |
|
|
batches []common.Batch |
|
|
|
|
|
coordinators []coordinatorAPI |
|
|
usrAddr string |
|
|
usrAddr string |
|
|
usrBjj string |
|
|
usrBjj string |
|
|
accs []common.Account |
|
|
accs []common.Account |
|
@ -622,11 +623,26 @@ func TestMain(m *testing.M) { |
|
|
poolTxsToSend = append(poolTxsToSend, genSendTx) |
|
|
poolTxsToSend = append(poolTxsToSend, genSendTx) |
|
|
poolTxsToReceive = append(poolTxsToReceive, genReceiveTx) |
|
|
poolTxsToReceive = append(poolTxsToReceive, genReceiveTx) |
|
|
} |
|
|
} |
|
|
|
|
|
// Coordinators
|
|
|
|
|
|
const nCoords = 10 |
|
|
|
|
|
coords := test.GenCoordinators(nCoords, blocks) |
|
|
|
|
|
err = hdb.AddCoordinators(coords) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
fromItem := uint(0) |
|
|
|
|
|
limit := uint(99999) |
|
|
|
|
|
coordinators, _, err := hdb.GetCoordinators(&fromItem, &limit, historydb.OrderAsc) |
|
|
|
|
|
apiCoordinators := coordinatorsToAPI(coordinators) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
// Set testCommon
|
|
|
// Set testCommon
|
|
|
tc = testCommon{ |
|
|
tc = testCommon{ |
|
|
blocks: blocks, |
|
|
blocks: blocks, |
|
|
tokens: tokensUSD, |
|
|
tokens: tokensUSD, |
|
|
batches: batches, |
|
|
batches: batches, |
|
|
|
|
|
coordinators: apiCoordinators, |
|
|
usrAddr: ethAddrToHez(usrAddr), |
|
|
usrAddr: ethAddrToHez(usrAddr), |
|
|
usrBjj: bjjToString(usrBjj), |
|
|
usrBjj: bjjToString(usrBjj), |
|
|
accs: accs, |
|
|
accs: accs, |
|
@ -1250,6 +1266,59 @@ func assertPoolTx(t *testing.T, expected, actual sendPoolTx) { |
|
|
assert.Equal(t, expected, actual) |
|
|
assert.Equal(t, expected, actual) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestGetCoordinators(t *testing.T) { |
|
|
|
|
|
endpoint := apiURL + "coordinators" |
|
|
|
|
|
fetchedCoordinators := []coordinatorAPI{} |
|
|
|
|
|
|
|
|
|
|
|
appendIter := func(intr interface{}) { |
|
|
|
|
|
for i := 0; i < len(intr.(*coordinatorsAPI).Coordinators); i++ { |
|
|
|
|
|
tmp, err := copystructure.Copy(intr.(*coordinatorsAPI).Coordinators[i]) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
fetchedCoordinators = append(fetchedCoordinators, tmp.(coordinatorAPI)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
limit := 5 |
|
|
|
|
|
|
|
|
|
|
|
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit) |
|
|
|
|
|
err := doGoodReqPaginated(path, historydb.OrderAsc, &coordinatorsAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
assert.Equal(t, tc.coordinators, fetchedCoordinators) |
|
|
|
|
|
|
|
|
|
|
|
// Reverse Order
|
|
|
|
|
|
reversedCoordinators := []coordinatorAPI{} |
|
|
|
|
|
appendIter = func(intr interface{}) { |
|
|
|
|
|
for i := 0; i < len(intr.(*coordinatorsAPI).Coordinators); i++ { |
|
|
|
|
|
tmp, err := copystructure.Copy(intr.(*coordinatorsAPI).Coordinators[i]) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
reversedCoordinators = append(reversedCoordinators, tmp.(coordinatorAPI)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderDesc, &coordinatorsAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
for i := 0; i < len(fetchedCoordinators); i++ { |
|
|
|
|
|
assert.Equal(t, reversedCoordinators[i], fetchedCoordinators[len(fetchedCoordinators)-1-i]) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Test GetCoordinator
|
|
|
|
|
|
path = fmt.Sprintf("%s/%s", endpoint, fetchedCoordinators[2].Forger.String()) |
|
|
|
|
|
coordinator := coordinatorAPI{} |
|
|
|
|
|
assert.NoError(t, doGoodReq("GET", path, nil, &coordinator)) |
|
|
|
|
|
assert.Equal(t, fetchedCoordinators[2], coordinator) |
|
|
|
|
|
// 400
|
|
|
|
|
|
path = fmt.Sprintf("%s/0x001", endpoint) |
|
|
|
|
|
err = doBadReq("GET", path, nil, 400) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
// 404
|
|
|
|
|
|
path = fmt.Sprintf("%s/0xaa942cfcd25ad4d90a62358b0dd84f33b398262a", endpoint) |
|
|
|
|
|
err = doBadReq("GET", path, nil, 404) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func doGoodReqPaginated( |
|
|
func doGoodReqPaginated( |
|
|
path, order string, |
|
|
path, order string, |
|
|
iterStruct db.Paginationer, |
|
|
iterStruct db.Paginationer, |
|
|