Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion carmen
Submodule carmen updated 441 files
67 changes: 0 additions & 67 deletions executor/extension/statedb/state_db_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,73 +281,6 @@ func TestStateDbManager_OverrideArchiveMode(t *testing.T) {
}
}

func TestStateDbManager_OverrideArchiveVariant(t *testing.T) {
state := executor.State[any]{
Block: 0,
}
tmpDir := t.TempDir()
cfg := &utils.Config{}
cfg.DbTmp = tmpDir
cfg.DbImpl = "carmen"
cfg.DbVariant = "go-file"
cfg.KeepDb = true
cfg.ChainID = utils.OperaMainnetChainID
cfg.ArchiveMode = true
cfg.ArchiveVariant = "ldb"
cfg.CarmenSchema = 5

ext := MakeStateDbManager[any](cfg, "")
ctx := &executor.Context{}

// First, create a live src db
if err := ext.PreRun(state, ctx); err != nil {
t.Fatalf("failed to to run pre-run: %v", err)
}

if err := ext.PostRun(state, ctx, nil); err != nil {
t.Fatalf("failed to to run post-run: %v", err)
}

expectedName := fmt.Sprintf("state_db_%v_%v_%v", cfg.DbImpl, cfg.DbVariant, state.Block)
dbPath := filepath.Join(cfg.DbTmp, expectedName)

filename := filepath.Join(dbPath, utils.PathToDbInfo)

if _, err := os.Stat(filename); err != nil {
t.Fatalf("failed to find %v of stateDbInfo; %v", utils.PathToDbInfo, err)
}

stateDbInfo, err := utils.ReadStateDbInfo(dbPath)
if err != nil {
t.Fatal("failed to read statedb_info.json")
}

// Second, read from the src db and run in archive mode with different archive variant
cfg = &utils.Config{}
cfg.DbTmp = tmpDir
cfg.DbImpl = "carmen"
cfg.ChainID = utils.OperaMainnetChainID
cfg.ArchiveMode = true
cfg.ArchiveVariant = "s5"
cfg.StateDbSrc = dbPath

ext = MakeStateDbManager[any](cfg, "")
ctx = &executor.Context{}

if err := ext.PreRun(state, ctx); err != nil {
t.Fatalf("failed to to run pre-run: %v", err)
}

// must use the same db variant as in src db
if cfg.ArchiveVariant != stateDbInfo.ArchiveVariant {
t.Fatalf("Wrong archive variant.\ngot: %v\nwant: %v", cfg.ArchiveVariant, stateDbInfo.ArchiveVariant)
}

if err := ext.PostRun(state, ctx, nil); err != nil {
t.Fatalf("failed to to run post-run: %v", err)
}
}

func TestStateDbManager_NonExistentStateDbSrc(t *testing.T) {
cfg := &utils.Config{}

Expand Down
8 changes: 2 additions & 6 deletions state/carmen.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,14 @@ func MakeCarmenStateDB(
switch strings.ToLower(archive) {
case "none":
archiveType = ""
case "": // = default option
fallthrough
case "ldb":
fallthrough
case "leveldb":
archiveType = "ldb"
case "sql":
fallthrough
case "sqlite":
archiveType = "sql"
case "s4":
archiveType = "s4"
case "": // = default option
fallthrough
case "s5":
archiveType = "s5"
default:
Expand Down
54 changes: 5 additions & 49 deletions state/carmen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,12 @@ func TestCarmenState_AccountLifecycle(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)
csDB.AddBalance(addr, uint256.NewInt(10), 0)

if !csDB.Exist(addr) {
t.Fatal("failed to create carmen state DB account")
}

if !csDB.Empty(addr) {
t.Fatal("failed to create carmen state DB account; should be empty")
}

csDB.SelfDestruct(addr)
if !csDB.HasSelfDestructed(addr) {
t.Fatal("failed to suicide carmen state DB account;")
Expand Down Expand Up @@ -134,8 +130,6 @@ func TestCarmenState_AccountBalanceOperations(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)

// get randomized balance
additionBase := GetRandom(t, 1, 5_000_000)
addition := uint256.NewInt(additionBase)
Expand Down Expand Up @@ -181,8 +175,6 @@ func TestCarmenState_NonceOperations(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)

// get randomized nonce
newNonce := GetRandom(t, 1, 5_000_000)

Expand Down Expand Up @@ -218,8 +210,6 @@ func TestCarmenState_CodeOperations(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)

// generate new randomized code
code := MakeRandomByteSlice(t, 2048)

Expand Down Expand Up @@ -263,7 +253,7 @@ func TestCarmenState_StateOperations(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)
csDB.AddBalance(addr, uint256.NewInt(10), 0)

// generate state key and value
key := common.BytesToHash(MakeRandomByteSlice(t, 32))
Expand Down Expand Up @@ -496,7 +486,7 @@ func TestCarmenState_GetArchiveState(t *testing.T) {
}
addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

csDB.CreateAccount(addr)
csDB.AddBalance(addr, uint256.NewInt(10), 0)

// generate state key and value
key := common.BytesToHash(MakeRandomByteSlice(t, 32))
Expand Down Expand Up @@ -563,8 +553,6 @@ func TestCarmenState_SetBalanceUsingBulkInsertion(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

cbl.CreateAccount(addr)

newBalance := uint256.NewInt(GetRandom(t, 1, 5_000_000))
cbl.SetBalance(addr, newBalance)

Expand Down Expand Up @@ -613,8 +601,6 @@ func TestCarmenState_SetNonceUsingBulkInsertion(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

cbl.CreateAccount(addr)

newNonce := GetRandom(t, 1, 5_000_000)

cbl.SetNonce(addr, newNonce)
Expand Down Expand Up @@ -664,7 +650,7 @@ func TestCarmenState_SetStateUsingBulkInsertion(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

cbl.CreateAccount(addr)
cbl.SetBalance(addr, uint256.NewInt(10))

// generate state key and value
key := common.BytesToHash(MakeRandomByteSlice(t, 32))
Expand Down Expand Up @@ -717,8 +703,6 @@ func TestCarmenState_SetCodeUsingBulkInsertion(t *testing.T) {

addr := common.BytesToAddress(MakeRandomByteSlice(t, 40))

cbl.CreateAccount(addr)

// generate new randomized code
code := MakeRandomByteSlice(t, 2048)

Expand Down Expand Up @@ -766,7 +750,7 @@ func TestCarmenState_BulkloadOperations(t *testing.T) {

for i := 0; i < len(accounts); i++ {
accounts[i] = common.BytesToAddress(MakeRandomByteSlice(t, 40))
csDB.CreateAccount(accounts[i])
csDB.AddBalance(accounts[i], uint256.NewInt(10), 0)
}

if err = csDB.EndTransaction(); err != nil {
Expand Down Expand Up @@ -853,21 +837,6 @@ func TestCarmenState_GetShadowDB(t *testing.T) {
}
}

// carmenStateDB struct method tests
func TestCarmenStateDB_CreateAccount(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDb := carmen.NewMockDatabase(ctrl)
mockTxCtx := carmen.NewMockTransactionContext(ctrl)
c := &carmenStateDB{
db: mockDb,
txCtx: mockTxCtx,
}
addr := common.HexToAddress("0x1234")
mockTxCtx.EXPECT().CreateAccount(carmen.Address(addr))
c.CreateAccount(addr)
}

func TestCarmenStateDB_CreateContract(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -1782,19 +1751,6 @@ func TestCarmenHistoricState_Release(t *testing.T) {
assert.NoError(t, err)
}

// carmenBulkLoad struct method tests
func TestCarmenBulkLoad_CreateAccount(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockBulk := carmen.NewMockBulkLoad(ctrl)
c := &carmenBulkLoad{
load: mockBulk,
}
addr := common.HexToAddress("0x1234")
mockBulk.EXPECT().CreateAccount(carmen.Address(addr))
c.CreateAccount(addr)
}

func TestCarmenBulkLoad_SetBalance(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
2 changes: 1 addition & 1 deletion state/proxy/shadow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestShadowState_SetStateUsingBulkInsertion(t *testing.T) {

addr := common.BytesToAddress(state.MakeRandomByteSlice(t, 40))

cbl.CreateAccount(addr)
cbl.SetBalance(addr, uint256.NewInt(10))

// generate state key and value
key := common.BytesToHash(state.MakeRandomByteSlice(t, 32))
Expand Down
3 changes: 1 addition & 2 deletions utils/test_cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func GetStateDbTestCases() []StateDbTestCase {
{"geth", "", true, "", false},
{"geth", "geth", true, "", false},
{"carmen", "geth", false, "none", false},
{"carmen", "geth", true, "ldb", false},
{"carmen", "geth", true, "sqlite", false},
{"carmen", "geth", false, "s5", false},
}

return testCases
Expand Down
2 changes: 1 addition & 1 deletion utils/test_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func TestCases_GetStateDbTestCases(t *testing.T) {
testCases := GetStateDbTestCases()
assert.Equal(t, 5, len(testCases))
assert.Equal(t, 4, len(testCases))
}

func TestCases_MakeRandomByteSlice(t *testing.T) {
Expand Down
Loading