From c4207d09c90e576fa7f41237d2aff49aa5d85fa8 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 26 Jun 2024 13:56:47 +0100 Subject: [PATCH] fix --- go/host/storage/hostdb/rollup.go | 2 +- go/host/storage/hostdb/rollup_test.go | 74 ++++++++++++++++++++------- 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/go/host/storage/hostdb/rollup.go b/go/host/storage/hostdb/rollup.go index 8e1b02430d..7b80057ddc 100644 --- a/go/host/storage/hostdb/rollup.go +++ b/go/host/storage/hostdb/rollup.go @@ -123,7 +123,7 @@ func GetLatestRollup(db HostDB) (*common.RollupHeader, error) { } func GetRollupByHash(db HostDB, rollupHash gethcommon.Hash) (*common.PublicRollup, error) { - whereQuery := " WHERE hash=" + db.GetSQLStatement().Placeholder + whereQuery := " WHERE rh.hash=" + db.GetSQLStatement().Placeholder return fetchPublicRollup(db.GetSQLDB(), whereQuery, rollupHash.Bytes()) } diff --git a/go/host/storage/hostdb/rollup_test.go b/go/host/storage/hostdb/rollup_test.go index d1c6c42e13..b5320c6139 100644 --- a/go/host/storage/hostdb/rollup_test.go +++ b/go/host/storage/hostdb/rollup_test.go @@ -60,9 +60,15 @@ func TestGetRollupByBlockHash(t *testing.T) { metadata := createRollupMetadata(batchNumber - 10) rollup := createRollup(batchNumber) - block := common.L1Block{} + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup, &metadata, &block) + err = AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup, &metadata, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -86,9 +92,15 @@ func TestGetLatestRollup(t *testing.T) { rollup1LastSeq := int64(batchNumber) metadata1 := createRollupMetadata(rollup1FirstSeq) rollup1 := createRollup(rollup1LastSeq) - block := common.L1Block{} + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, &block) + err = AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -99,7 +111,7 @@ func TestGetLatestRollup(t *testing.T) { rollup2LastSeq := int64(batchNumber + 10) metadata2 := createRollupMetadata(rollup2FirstSeq) rollup2 := createRollup(rollup2LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, block) if err != nil { t.Errorf("could not store rollup 2. Cause: %s", err) } @@ -125,9 +137,15 @@ func TestGetRollupBySeqNo(t *testing.T) { rollup1LastSeq := int64(batchNumber) metadata1 := createRollupMetadata(rollup1FirstSeq) rollup1 := createRollup(rollup1LastSeq) - block := common.L1Block{} + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, &block) + err = AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -138,7 +156,7 @@ func TestGetRollupBySeqNo(t *testing.T) { rollup2LastSeq := int64(batchNumber + 10) // 787 metadata2 := createRollupMetadata(rollup2FirstSeq) rollup2 := createRollup(rollup2LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, block) if err != nil { t.Errorf("could not store rollup 2. Cause: %s", err) } @@ -174,9 +192,15 @@ func TestGetRollupListing(t *testing.T) { rollup1LastSeq := int64(batchNumber) metadata1 := createRollupMetadata(rollup1FirstSeq) rollup1 := createRollup(rollup1LastSeq) - block := common.L1Block{} + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, &block) + err = AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -185,7 +209,7 @@ func TestGetRollupListing(t *testing.T) { rollup2LastSeq := int64(batchNumber + 10) metadata2 := createRollupMetadata(rollup2FirstSeq) rollup2 := createRollup(rollup2LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, block) if err != nil { t.Errorf("could not store rollup 2. Cause: %s", err) } @@ -194,7 +218,7 @@ func TestGetRollupListing(t *testing.T) { rollup3LastSeq := int64(batchNumber + 20) metadata3 := createRollupMetadata(rollup3FirstSeq) rollup3 := createRollup(rollup3LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup3, &metadata3, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup3, &metadata3, block) dbtx.Write() if err != nil { t.Errorf("could not store rollup 3. Cause: %s", err) @@ -271,9 +295,15 @@ func TestGetRollupByHash(t *testing.T) { rollup1LastSeq := int64(batchNumber) metadata1 := createRollupMetadata(rollup1FirstSeq) rollup1 := createRollup(rollup1LastSeq) - block := common.L1Block{} + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, &block) + err = AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -282,7 +312,7 @@ func TestGetRollupByHash(t *testing.T) { rollup2LastSeq := int64(batchNumber + 10) metadata2 := createRollupMetadata(rollup2FirstSeq) rollup2 := createRollup(rollup2LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, block) if err != nil { t.Errorf("could not store rollup 2. Cause: %s", err) } @@ -306,8 +336,15 @@ func TestGetRollupBatches(t *testing.T) { db, _ := createSQLiteDB(t) txHashesOne := []common.L2TxHash{gethcommon.BytesToHash([]byte("magicStringOne")), gethcommon.BytesToHash([]byte("magicStringTwo"))} batchOne := createBatch(batchNumber, txHashesOne) + block := types.NewBlock(&types.Header{}, nil, nil, nil, nil) dbtx, _ := db.NewDBTransaction() - err := AddBatch(dbtx, db.GetSQLStatement(), &batchOne) + err := AddBlock(dbtx, db.GetSQLStatement(), block.Header()) + if err != nil { + t.Errorf("could not store block. Cause: %s", err) + } + dbtx.Write() + dbtx, _ = db.NewDBTransaction() + err = AddBatch(dbtx, db.GetSQLStatement(), &batchOne) if err != nil { t.Errorf("could not store batch. Cause: %s", err) } @@ -340,8 +377,7 @@ func TestGetRollupBatches(t *testing.T) { rollup1LastSeq := int64(batchNumber + 1) metadata1 := createRollupMetadata(rollup1FirstSeq) rollup1 := createRollup(rollup1LastSeq) - block := common.L1Block{} - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup1, &metadata1, block) if err != nil { t.Errorf("could not store rollup. Cause: %s", err) } @@ -350,7 +386,7 @@ func TestGetRollupBatches(t *testing.T) { rollup2LastSeq := int64(batchNumber + 3) metadata2 := createRollupMetadata(rollup2FirstSeq) rollup2 := createRollup(rollup2LastSeq) - err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, &block) + err = AddRollup(dbtx, db.GetSQLStatement(), &rollup2, &metadata2, block) if err != nil { t.Errorf("could not store rollup 2. Cause: %s", err) }