2020-11-28 15:08:17 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-03-30 09:53:54 +00:00
|
|
|
"context"
|
2020-11-28 15:08:17 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core"
|
2021-06-19 08:21:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/ethdb/kv"
|
2020-11-28 15:08:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetChainConfig(t *testing.T) {
|
2021-06-19 08:21:53 +00:00
|
|
|
db := kv.NewTestKV(t)
|
2021-06-05 15:17:04 +00:00
|
|
|
config, _, err := core.CommitGenesisBlock(db, core.DefaultGenesisBlock(), false)
|
2020-11-28 15:08:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("setting up genensis block: %v", err)
|
|
|
|
}
|
2021-01-02 19:28:22 +00:00
|
|
|
|
2021-04-03 06:26:00 +00:00
|
|
|
tx, txErr := db.BeginRo(context.Background())
|
2021-03-30 09:53:54 +00:00
|
|
|
if txErr != nil {
|
|
|
|
t.Fatalf("error starting tx: %v", txErr)
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2021-05-01 07:42:23 +00:00
|
|
|
api := &BaseAPI{}
|
2021-03-30 09:53:54 +00:00
|
|
|
config1, err1 := api.chainConfig(tx)
|
2020-11-28 15:08:17 +00:00
|
|
|
if err1 != nil {
|
|
|
|
t.Fatalf("reading chain config: %v", err1)
|
|
|
|
}
|
|
|
|
if config.String() != config1.String() {
|
|
|
|
t.Fatalf("read different config: %s, expected %s", config1.String(), config.String())
|
|
|
|
}
|
2021-03-30 09:53:54 +00:00
|
|
|
config2, err2 := api.chainConfig(tx)
|
2021-01-02 19:28:22 +00:00
|
|
|
if err2 != nil {
|
|
|
|
t.Fatalf("reading chain config: %v", err2)
|
|
|
|
}
|
|
|
|
if config.String() != config2.String() {
|
|
|
|
t.Fatalf("read different config: %s, expected %s", config2.String(), config.String())
|
|
|
|
}
|
2020-11-28 15:08:17 +00:00
|
|
|
}
|