package ethdb_test import ( "context" "errors" "fmt" "testing" "time" "github.com/ledgerwatch/turbo-geth/common/dbutils" "github.com/ledgerwatch/turbo-geth/ethdb" "github.com/ledgerwatch/turbo-geth/ethdb/remote" "github.com/ledgerwatch/turbo-geth/ethdb/remote/remotedbserver" "github.com/ledgerwatch/turbo-geth/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/test/bufconn" ) func TestSequence(t *testing.T) { writeDBs, _, closeAll := setupDatabases(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg { return defaultBuckets }) defer closeAll() ctx := context.Background() for _, db := range writeDBs { db := db tx, err := db.Begin(ctx, ethdb.RW) require.NoError(t, err) defer tx.Rollback() i, err := tx.Sequence(dbutils.Buckets[0], 0) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.Sequence(dbutils.Buckets[0], 1) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.Sequence(dbutils.Buckets[0], 6) require.NoError(t, err) require.Equal(t, uint64(1), i) i, err = tx.Sequence(dbutils.Buckets[0], 1) require.NoError(t, err) require.Equal(t, uint64(7), i) i, err = tx.Sequence(dbutils.Buckets[1], 0) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.Sequence(dbutils.Buckets[1], 1) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.Sequence(dbutils.Buckets[1], 6) require.NoError(t, err) require.Equal(t, uint64(1), i) i, err = tx.Sequence(dbutils.Buckets[1], 1) require.NoError(t, err) require.Equal(t, uint64(7), i) } } func TestManagedTx(t *testing.T) { defaultConfig := dbutils.BucketsConfigs defer func() { dbutils.BucketsConfigs = defaultConfig }() bucketID := 0 bucket1 := dbutils.Buckets[bucketID] bucket2 := dbutils.Buckets[bucketID+1] writeDBs, readDBs, closeAll := setupDatabases(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg { return map[string]dbutils.BucketConfigItem{ bucket1: { Flags: dbutils.DupSort, AutoDupSortKeysConversion: true, DupToLen: 4, DupFromLen: 6, }, bucket2: { Flags: 0, }, } }) defer closeAll() ctx := context.Background() for _, db := range writeDBs { db := db tx, err := db.Begin(ctx, ethdb.RW) require.NoError(t, err) defer tx.Rollback() c := tx.Cursor(bucket1) c1 := tx.Cursor(bucket2) require.NoError(t, c.Append([]byte{0}, []byte{1})) require.NoError(t, c1.Append([]byte{0}, []byte{1})) require.NoError(t, c.Append([]byte{0, 0, 0, 0, 0, 1}, []byte{1})) // prefixes of len=FromLen for DupSort test (other keys must be