Merge pull request #275 from hermeznetwork/feature/api-db-tests-til

Feature/api db tests til
This commit is contained in:
arnau
2020-11-11 15:54:41 +01:00
committed by GitHub
6 changed files with 298 additions and 186 deletions

View File

@@ -71,6 +71,16 @@ var api *API
// emulating the task of the synchronizer in order to have data to be returned
// by the API endpoints that will be tested
func TestMain(m *testing.M) {
/*
til update considerations:
1. Two instructions sets should be enough (one for L2 another for historydb)
2. FillBlocksExtra function must be used, there is a coment on top of the function that explains which data is setted
3. Some data will not be generated by til nor FillBlocksExtra, test.GenXXX will still be required to cover this cases
4. Most of the historydb inserts should be replaced with nBlocks calls to AddBlockSCData
5. When defining til instructions, there is no need to have 100s of entries for each table, but it's interesting to
cover all different cases (for instance all tx types)
*/
// Initializations
// Swagger
router := swagger.NewRouter().WithSwaggerFromFile("./swagger.yml")
@@ -132,6 +142,7 @@ func TestMain(m *testing.M) {
// Fill HistoryDB and StateDB with fake data
// Gen blocks and add them to DB
const nBlocks = 5
// TODO: UPDATE with til
blocks := test.GenBlocks(1, nBlocks+1)
err = api.h.AddBlocks(blocks)
if err != nil {
@@ -141,6 +152,7 @@ func TestMain(m *testing.M) {
// Gen tokens and add them to DB
const nTokens = 10
// TODO: UPDATE with til
tokens, ethToken := test.GenTokens(nTokens, blocks)
err = api.h.AddTokens(tokens)
if err != nil {
@@ -173,6 +185,7 @@ func TestMain(m *testing.M) {
}
// Gen batches and add them to DB
const nBatches = 10
// TODO: UPDATE with til
batches := test.GenBatches(nBatches, blocks)
err = api.h.AddBatches(batches)
if err != nil {
@@ -184,6 +197,7 @@ func TestMain(m *testing.M) {
usrAddr := ethCommon.BigToAddress(big.NewInt(4896847))
privK := babyjub.NewRandPrivKey()
usrBjj := privK.Public()
// TODO: UPDATE with til
accs := test.GenAccounts(totalAccounts, userAccounts, tokens, &usrAddr, usrBjj, batches)
err = api.h.AddAccounts(accs)
if err != nil {
@@ -207,6 +221,7 @@ func TestMain(m *testing.M) {
}
// Gen exits and add them to DB
const totalExits = 40
// TODO: UPDATE with til
exits := test.GenExitTree(totalExits, batches, accs)
err = api.h.AddExitTree(exits)
if err != nil {
@@ -217,10 +232,12 @@ func TestMain(m *testing.M) {
// Gen L1Txs
const totalL1Txs = 40
const userL1Txs = 4
// TODO: UPDATE with til
usrL1Txs, othrL1Txs := test.GenL1Txs(256, totalL1Txs, userL1Txs, &usrAddr, accs, tokens, blocks, batches)
// Gen L2Txs
const totalL2Txs = 20
const userL2Txs = 4
// TODO: UPDATE with til
usrL2Txs, othrL2Txs := test.GenL2Txs(256+totalL1Txs, totalL2Txs, userL2Txs, &usrAddr, accs, tokens, blocks, batches)
// Sort txs
sortedTxs := []txSortFielder{}