mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
WIP5
This commit is contained in:
@@ -166,6 +166,19 @@ func (hdb *HistoryDB) addBatches(d meddler.DB, batches []common.Batch) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBatch returns the batch with the given batchNum
|
||||
func (hdb *HistoryDB) GetBatch(batchNum common.BatchNum) (*common.Batch, error) {
|
||||
var batch common.Batch
|
||||
err := meddler.QueryRow(
|
||||
hdb.db, &batch, `SELECT batch.batch_num, batch.eth_block_num, batch.forger_addr,
|
||||
batch.fees_collected, batch.fee_idxs_coordinator, batch.state_root,
|
||||
batch.num_accounts, batch.last_idx, batch.exit_root, batch.forge_l1_txs_num,
|
||||
batch.slot_num, batch.total_fees_usd FROM batch WHERE batch_num = $1;`,
|
||||
batchNum,
|
||||
)
|
||||
return &batch, err
|
||||
}
|
||||
|
||||
// GetBatchAPI return the batch with the given batchNum
|
||||
func (hdb *HistoryDB) GetBatchAPI(batchNum common.BatchNum) (*BatchAPI, error) {
|
||||
batch := &BatchAPI{}
|
||||
@@ -320,7 +333,7 @@ func (hdb *HistoryDB) GetLastBatchNum() (common.BatchNum, error) {
|
||||
return batchNum, tracerr.Wrap(row.Scan(&batchNum))
|
||||
}
|
||||
|
||||
// GetLastBatchreturns the last forged batch
|
||||
// GetLastBatch returns the last forged batch
|
||||
func (hdb *HistoryDB) GetLastBatch() (*common.Batch, error) {
|
||||
var batch common.Batch
|
||||
err := meddler.QueryRow(
|
||||
|
||||
@@ -212,6 +212,12 @@ func TestBatches(t *testing.T) {
|
||||
fetchedLastL1BatchBlockNum, err := historyDB.GetLastL1BatchBlockNum()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, lastL1BatchBlockNum, fetchedLastL1BatchBlockNum)
|
||||
// Test GetBatch
|
||||
fetchedBatch, err := historyDB.GetBatch(1)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &batches[0], fetchedBatch)
|
||||
_, err = historyDB.GetBatch(common.BatchNum(len(batches) + 1))
|
||||
assert.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err))
|
||||
}
|
||||
|
||||
func TestBids(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user