Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cabrador committed Sep 20, 2024
1 parent e345a83 commit 70deec1
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 39 deletions.
16 changes: 8 additions & 8 deletions cmd/aida-rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestRpc_AllDbEventsAreIssuedInOrder_Sequential(t *testing.T) {
archiveThree := state.NewMockNonCommittableStateDB(ctrl)
archiveFour := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
// Simulate the execution of four requests in three blocks.
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestRpc_AllDbEventsAreIssuedInOrder_Parallel(t *testing.T) {
archiveTwo := state.NewMockNonCommittableStateDB(ctrl)
archiveThree := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.Workers = 2
// Simulate the execution of four requests in three blocks.
provider.EXPECT().
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestRpc_AllTransactionsAreProcessedInOrder_Sequential(t *testing.T) {
ext := executor.NewMockExtension[*rpc.RequestAndResults](ctrl)
processor := executor.NewMockProcessor[*rpc.RequestAndResults](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
// Simulate the execution of four requests in three blocks.
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestRpc_AllTransactionsAreProcessed_Parallel(t *testing.T) {
ext := executor.NewMockExtension[*rpc.RequestAndResults](ctrl)
processor := executor.NewMockProcessor[*rpc.RequestAndResults](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.Workers = 2
// Simulate the execution of four requests in three blocks.
provider.EXPECT().
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestRpc_ValidationDoesNotFailOnValidTransaction_Sequential(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
var err error
reqBlockTwo.Response.Result, err = json.Marshal("0x1")
if err != nil {
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestRpc_ValidationDoesNotFailOnValidTransaction_Parallel(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
var err error
reqBlockTwo.Response.Result, err = json.Marshal("0x1")
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestRpc_ValidationFailsOnValidTransaction_Sequential(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
var err error
reqBlockTwo.Response.Result, err = json.Marshal("0x1")
if err != nil {
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestRpc_ValidationFailsOnValidTransaction_Parallel(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
var err error
reqBlockTwo.Response.Result, err = json.Marshal("0x1")
Expand Down
2 changes: 1 addition & 1 deletion cmd/aida-sdb/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSdbRecord_AllDbEventsAreIssuedInOrder(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
path := t.TempDir() + "test_trace"

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 10, 11, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 10, 11, false, "")
cfg.TraceFile = path
cfg.SyncPeriodLength = 1
provider.EXPECT().
Expand Down
16 changes: 8 additions & 8 deletions cmd/aida-vm-adb/run_vm_adb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestVmAdb_AllDbEventsAreIssuedInOrder_Sequential(t *testing.T) {
archiveBlockTwo := state.NewMockNonCommittableStateDB(ctrl)
archiveBlockThree := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestVmAdb_AllDbEventsAreIssuedInOrder_Parallel(t *testing.T) {
archiveBlockTwo := state.NewMockNonCommittableStateDB(ctrl)
archiveBlockThree := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
cfg.Workers = 2
// Simulate the execution of three transactions in two blocks.
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestVmAdb_AllTransactionsAreProcessedInOrder_Sequential(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestVmAdb_AllTransactionsAreProcessed_Parallel(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.Workers = 2
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestVmAdb_ValidationDoesNotFailOnValidTransaction_Sequential(t *testing.T)
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestVmAdb_ValidationDoesNotFailOnValidTransaction_Parallel(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestVmAdb_ValidationFailsOnInvalidTransaction_Sequential(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down Expand Up @@ -524,7 +524,7 @@ func TestVmAdb_ValidationFailsOnInvalidTransaction_Parallel(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down
9 changes: 5 additions & 4 deletions cmd/aida-vm-sdb/run_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func TestVmSdb_Eth_AllDbEventsAreIssuedInOrder(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, false, "Cancun")
cfg.ContinueOnFailure = true

data := ethtest.CreateTestTransaction(t)

provider.EXPECT().
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestVmSdb_Eth_AllTransactionsAreProcessedInOrder(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, false, "Cancun")
data := ethtest.CreateTestTransaction(t)

// Simulate the execution of three transactions in two blocks.
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestVmSdb_Eth_ValidationDoesNotFailOnValidTransaction(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, true, "Cancun")
data := ethtest.CreateTestTransaction(t)

provider.EXPECT().
Expand Down Expand Up @@ -233,7 +234,7 @@ func TestVmSdb_Eth_ValidationDoesFailOnInvalidTransaction(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.EthTestsChainID, 2, 4, true, "Cancun")
data := ethtest.CreateTestTransaction(t)

provider.EXPECT().
Expand Down
8 changes: 4 additions & 4 deletions cmd/aida-vm-sdb/run_substate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestVmSdb_Substate_AllDbEventsAreIssuedInOrder(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestVmSdb_Substate_AllTransactionsAreProcessedInOrder(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestVmSdb_Substate_ValidationDoesNotFailOnValidTransaction(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestVmSdb_Substate_ValidationFailsOnInvalidTransaction(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/aida-vm-sdb/run_tx_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestVmSdb_TxGenerator_AllTransactionsAreProcessedInOrder(t *testing.T) {
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
// Simulate the execution of four transactions in three blocks.
provider.EXPECT().
Run(2, 4, gomock.Any()).
Expand Down
14 changes: 7 additions & 7 deletions cmd/aida-vm/run_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestVm_AllDbEventsAreIssuedInOrder_Sequential(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestVm_AllTransactionsAreProcessedInOrder_Sequential(t *testing.T) {
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
// Simulate the execution of three transactions in two blocks.
provider.EXPECT().
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestVm_AllTransactionsAreProcessedInOrder_Parallel(t *testing.T) {
processor := executor.NewMockProcessor[txcontext.TxContext](ctrl)
ext := executor.NewMockExtension[txcontext.TxContext](ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, false, "")
cfg.ContinueOnFailure = true
cfg.Workers = 2
// Simulate the execution of three transactions in two blocks.
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestVmAdb_ValidationDoesNotFailOnValidTransaction_Sequential(t *testing.T)
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestVmAdb_ValidationDoesNotFailOnValidTransaction_Parallel(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestVm_ValidationFailsOnInvalidTransaction_Sequential(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
provider.EXPECT().
Run(2, 5, gomock.Any()).
DoAndReturn(func(_ int, _ int, consumer executor.Consumer[txcontext.TxContext]) error {
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestVm_ValidationFailsOnInvalidTransaction_Parallel(t *testing.T) {
provider := executor.NewMockProvider[txcontext.TxContext](ctrl)
db := state.NewMockStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true)
cfg := utils.NewTestConfig(t, utils.MainnetChainID, 2, 4, true, "")
cfg.Workers = 2
provider.EXPECT().
Run(2, 5, gomock.Any()).
Expand Down
2 changes: 1 addition & 1 deletion executor/extension/statedb/archive_inquirer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestArchiveInquirer_RunsRandomTransactionsInBackground(t *testing.T) {
db := state.NewMockStateDB(ctrl)
archive := state.NewMockNonCommittableStateDB(ctrl)

cfg := utils.NewTestConfig(t, utils.TestnetChainID, 0, 0, false)
cfg := utils.NewTestConfig(t, utils.TestnetChainID, 0, 0, false, "")
cfg.ArchiveMode = true
cfg.ArchiveQueryRate = 100
cfg.ArchiveMaxQueryAge = 100
Expand Down
4 changes: 2 additions & 2 deletions executor/extension/tracker/block_progress_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestSubstateProgressTrackerExtension_LoggingHappens(t *testing.T) {
Result: &substate.Result{
Status: 0,
},
}, nil)
})

gomock.InOrder(
db.EXPECT().GetMemoryUsage().Return(&state.MemoryUsage{UsedBytes: 1234}),
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestSubstateProgressTrackerExtension_FirstLoggingIsIgnored(t *testing.T) {
Result: &substate.Result{
Status: 0,
},
}, nil)
})

ext.PreRun(executor.State[txcontext.TxContext]{
Block: 4,
Expand Down
2 changes: 1 addition & 1 deletion executor/transaction_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestPrepareBlockCtx(t *testing.T) {
gaslimit := uint64(10000000)
blocknum := uint64(4600000)
basefee := big.NewInt(12345)
env := substatecontext.NewBlockEnvironment(&substate.Env{Difficulty: big.NewInt(1), GasLimit: gaslimit, Number: blocknum, Timestamp: 1675961395, BaseFee: basefee}, nil)
env := substatecontext.NewBlockEnvironment(&substate.Env{Difficulty: big.NewInt(1), GasLimit: gaslimit, Number: blocknum, Timestamp: 1675961395, BaseFee: basefee})

var hashError error
// BlockHashes are nil, expect an error
Expand Down
4 changes: 2 additions & 2 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ func NewConfigContext(cfg *Config, ctx *cli.Context) *configContext {
}

// NewTestConfig creates a new config for test purpose
func NewTestConfig(t *testing.T, chainId ChainID, first, last uint64, validate bool) *Config {
chainCfg, err := getChainConfig(chainId, "")
func NewTestConfig(t *testing.T, chainId ChainID, first, last uint64, validate bool, fork string) *Config {
chainCfg, err := getChainConfig(chainId, fork)
if err != nil {
t.Fatalf("cannot get chain cfg: %v", err)
}
Expand Down

0 comments on commit 70deec1

Please sign in to comment.