package ethdb_test import ( "context" "errors" "fmt" "testing" "time" "github.com/ledgerwatch/erigon/common/dbutils" "github.com/ledgerwatch/erigon/ethdb" "github.com/ledgerwatch/erigon/ethdb/remote/remotedbserver" "github.com/ledgerwatch/erigon/gointerfaces" "github.com/ledgerwatch/erigon/gointerfaces/remote" "github.com/ledgerwatch/erigon/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, _ := setupDatabases(t, func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg { return defaultBuckets }) ctx := context.Background() for _, db := range writeDBs { db := db tx, err := db.BeginRw(ctx) require.NoError(t, err) defer tx.Rollback() i, err := tx.ReadSequence(dbutils.Buckets[0]) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.IncrementSequence(dbutils.Buckets[0], 1) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.IncrementSequence(dbutils.Buckets[0], 6) require.NoError(t, err) require.Equal(t, uint64(1), i) i, err = tx.IncrementSequence(dbutils.Buckets[0], 1) require.NoError(t, err) require.Equal(t, uint64(7), i) i, err = tx.ReadSequence(dbutils.Buckets[1]) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.IncrementSequence(dbutils.Buckets[1], 1) require.NoError(t, err) require.Equal(t, uint64(0), i) i, err = tx.IncrementSequence(dbutils.Buckets[1], 6) require.NoError(t, err) require.Equal(t, uint64(1), i) i, err = tx.IncrementSequence(dbutils.Buckets[1], 1) require.NoError(t, err) require.Equal(t, uint64(7), i) tx.Rollback() } } 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 := setupDatabases(t, func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg { return map[string]dbutils.BucketConfigItem{ bucket1: { Flags: dbutils.DupSort, AutoDupSortKeysConversion: true, DupToLen: 4, DupFromLen: 6, }, bucket2: { Flags: 0, }, } }) ctx := context.Background() for _, db := range writeDBs { db := db tx, err := db.BeginRw(ctx) require.NoError(t, err) defer tx.Rollback() c, err := tx.RwCursor(bucket1) require.NoError(t, err) c1, err := tx.RwCursor(bucket2) require.NoError(t, err) 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