Skip to content

Commit

Permalink
refactor: move blockdb_tests.go to blockdb package
Browse files Browse the repository at this point in the history
  • Loading branch information
icorderi committed Dec 7, 2022
1 parent 00cf6be commit a8c98cc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 73 deletions.
56 changes: 28 additions & 28 deletions ledger/accountdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func TestAccountDBInit(t *testing.T) {

proto := config.Consensus[protocol.ConsensusCurrentVersion]

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -209,8 +209,8 @@ func TestAccountDBRound(t *testing.T) {

proto := config.Consensus[protocol.ConsensusCurrentVersion]

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -365,8 +365,8 @@ func TestAccountDBInMemoryAcct(t *testing.T) {

for i, test := range tests {

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -437,8 +437,8 @@ func TestAccountDBInMemoryAcct(t *testing.T) {
func TestAccountStorageWithStateProofID(t *testing.T) {
partitiontest.PartitionTest(t)

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -651,8 +651,8 @@ func cleanupTestDb(dbs db.Pair, dbName string, inMemory bool) {
}

func benchmarkReadingAllBalances(b *testing.B, inMemory bool) {
dbs, fn := dbOpenTest(b, inMemory)
setDbLogging(b, dbs)
dbs, fn := storetesting.DbOpenTest(b, inMemory)
storetesting.SetDbLogging(b, dbs)
defer cleanupTestDb(dbs, fn, inMemory)

benchmarkInitBalances(b, b.N, dbs, protocol.ConsensusCurrentVersion)
Expand Down Expand Up @@ -682,8 +682,8 @@ func BenchmarkReadingAllBalancesDisk(b *testing.B) {
}

func benchmarkReadingRandomBalances(b *testing.B, inMemory bool) {
dbs, fn := dbOpenTest(b, inMemory)
setDbLogging(b, dbs)
dbs, fn := storetesting.DbOpenTest(b, inMemory)
storetesting.SetDbLogging(b, dbs)
defer cleanupTestDb(dbs, fn, inMemory)

accounts := benchmarkInitBalances(b, b.N, dbs, protocol.ConsensusCurrentVersion)
Expand Down Expand Up @@ -721,8 +721,8 @@ func BenchmarkWritingRandomBalancesDisk(b *testing.B) {
batchCount := 1000
startupAcct := 5
initDatabase := func() (*sql.Tx, func(), error) {
dbs, fn := dbOpenTest(b, false)
setDbLogging(b, dbs)
dbs, fn := storetesting.DbOpenTest(b, false)
storetesting.SetDbLogging(b, dbs)
cleanup := func() {
cleanupTestDb(dbs, fn, false)
}
Expand Down Expand Up @@ -963,8 +963,8 @@ func TestLookupKeysByPrefix(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

dbs, fn := dbOpenTest(t, false)
setDbLogging(t, dbs)
dbs, fn := storetesting.DbOpenTest(t, false)
storetesting.SetDbLogging(t, dbs)
defer cleanupTestDb(dbs, fn, false)

// return account data, initialize DB tables from AccountsInitTest
Expand Down Expand Up @@ -1144,8 +1144,8 @@ func TestLookupKeysByPrefix(t *testing.T) {
func BenchmarkLookupKeyByPrefix(b *testing.B) {
// learn something from BenchmarkWritingRandomBalancesDisk

dbs, fn := dbOpenTest(b, false)
setDbLogging(b, dbs)
dbs, fn := storetesting.DbOpenTest(b, false)
storetesting.SetDbLogging(b, dbs)
defer cleanupTestDb(dbs, fn, false)

// return account data, initialize DB tables from AccountsInitTest
Expand Down Expand Up @@ -1422,8 +1422,8 @@ func TestCompactResourceDeltas(t *testing.T) {
func TestLookupAccountAddressFromAddressID(t *testing.T) {
partitiontest.PartitionTest(t)

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

addrs := make([]basics.Address, 100)
Expand Down Expand Up @@ -2080,8 +2080,8 @@ func initBoxDatabase(b *testing.B, totalBoxes, boxSize int) (db.Pair, func(), er
}

proto := config.Consensus[protocol.ConsensusCurrentVersion]
dbs, fn := dbOpenTest(b, false)
setDbLogging(b, dbs)
dbs, fn := storetesting.DbOpenTest(b, false)
storetesting.SetDbLogging(b, dbs)
cleanup := func() {
cleanupTestDb(dbs, fn, false)
}
Expand Down Expand Up @@ -2219,8 +2219,8 @@ func TestAccountOnlineQueries(t *testing.T) {

proto := config.Consensus[protocol.ConsensusCurrentVersion]

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -2723,8 +2723,8 @@ func TestAccountOnlineAccountsNewRoundFlip(t *testing.T) {
func TestAccountOnlineRoundParams(t *testing.T) {
partitiontest.PartitionTest(t)

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down Expand Up @@ -2776,8 +2776,8 @@ func TestAccountOnlineRoundParams(t *testing.T) {
func TestOnlineAccountsDeletion(t *testing.T) {
partitiontest.PartitionTest(t)

dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down
7 changes: 4 additions & 3 deletions ledger/acctupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store"
storetesting "github.com/algorand/go-algorand/ledger/store/testing"
ledgertesting "github.com/algorand/go-algorand/ledger/testing"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
Expand Down Expand Up @@ -93,7 +94,7 @@ func setupAccts(niter int) []map[basics.Address]basics.AccountData {
}

func makeMockLedgerForTrackerWithLogger(t testing.TB, inMemory bool, initialBlocksCount int, consensusVersion protocol.ConsensusVersion, accts []map[basics.Address]basics.AccountData, l logging.Logger) *mockLedgerForTracker {
dbs, fileName := dbOpenTest(t, inMemory)
dbs, fileName := storetesting.DbOpenTest(t, inMemory)
dbs.Rdb.SetLogger(l)
dbs.Wdb.SetLogger(l)

Expand Down Expand Up @@ -1149,8 +1150,8 @@ func TestListCreatables(t *testing.T) {
numElementsPerSegement := 25

// set up the database
dbs, _ := dbOpenTest(t, true)
setDbLogging(t, dbs)
dbs, _ := storetesting.DbOpenTest(t, true)
storetesting.SetDbLogging(t, dbs)
defer dbs.Close()

tx, err := dbs.Wdb.Handle.Begin()
Expand Down
28 changes: 28 additions & 0 deletions ledger/blockqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/algorand/go-algorand/agreement"
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/ledger/ledgercore"
ledgertesting "github.com/algorand/go-algorand/ledger/testing"
Expand All @@ -34,6 +35,33 @@ import (
"github.com/algorand/go-algorand/test/partitiontest"
)

func randomBlock(r basics.Round) blockEntry {
b := bookkeeping.Block{}
c := agreement.Certificate{}

b.BlockHeader.Round = r
b.BlockHeader.TimeStamp = int64(crypto.RandUint64())
b.RewardsPool = testPoolAddr
b.FeeSink = testSinkAddr
c.Round = r

return blockEntry{
block: b,
cert: c,
}
}

func randomInitChain(proto protocol.ConsensusVersion, nblock int) []blockEntry {
res := make([]blockEntry, 0)
for i := 0; i < nblock; i++ {
blkent := randomBlock(basics.Round(i))
blkent.cert = agreement.Certificate{}
blkent.block.CurrentProtocol = proto
res = append(res, blkent)
}
return res
}

func TestPutBlockTooOld(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down

0 comments on commit a8c98cc

Please sign in to comment.