2020-12-01 10:26:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-11-17 11:14:22 +00:00
|
|
|
"path/filepath"
|
2020-12-01 10:26:53 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDBRestore(t *testing.T) {
|
2021-08-25 19:17:37 +00:00
|
|
|
tmpDir := t.TempDir()
|
2020-12-01 10:26:53 +00:00
|
|
|
|
2021-11-17 11:14:22 +00:00
|
|
|
chainPath := filepath.Join(tmpDir, "neogotestchain")
|
|
|
|
cfg, err := config.LoadFile(filepath.Join("..", "config", "protocol.unit_testnet.yml"))
|
2020-12-01 10:26:53 +00:00
|
|
|
require.NoError(t, err, "could not load config")
|
|
|
|
cfg.ApplicationConfiguration.DBConfiguration.Type = "leveldb"
|
|
|
|
cfg.ApplicationConfiguration.DBConfiguration.LevelDBOptions.DataDirectoryPath = chainPath
|
|
|
|
|
|
|
|
out, err := yaml.Marshal(cfg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-11-17 11:14:22 +00:00
|
|
|
cfgPath := filepath.Join(tmpDir, "protocol.unit_testnet.yml")
|
2020-12-01 10:26:53 +00:00
|
|
|
require.NoError(t, ioutil.WriteFile(cfgPath, out, os.ModePerm))
|
|
|
|
|
|
|
|
// generated via `go run ./scripts/gendump/main.go --out ./cli/testdata/chain50x2.acc --blocks 50 --txs 2`
|
|
|
|
const inDump = "./testdata/chain50x2.acc"
|
|
|
|
e := newExecutor(t, false)
|
2021-11-17 11:14:22 +00:00
|
|
|
stateDump := filepath.Join(tmpDir, "neogo.teststate")
|
2020-12-01 10:26:53 +00:00
|
|
|
baseArgs := []string{"neo-go", "db", "restore", "--unittest",
|
|
|
|
"--config-path", tmpDir, "--in", inDump, "--dump", stateDump}
|
|
|
|
|
|
|
|
// First 15 blocks.
|
|
|
|
e.Run(t, append(baseArgs, "--count", "15")...)
|
|
|
|
|
|
|
|
// Big count.
|
2021-07-16 07:45:34 +00:00
|
|
|
e.RunWithError(t, append(baseArgs, "--count", "1000")...)
|
2020-12-01 10:26:53 +00:00
|
|
|
|
|
|
|
// Continue 15..25
|
2021-07-16 07:45:34 +00:00
|
|
|
e.Run(t, append(baseArgs, "--count", "10")...)
|
2020-12-01 10:26:53 +00:00
|
|
|
|
|
|
|
// Continue till end.
|
2021-07-16 07:45:34 +00:00
|
|
|
e.Run(t, baseArgs...)
|
2020-12-01 10:26:53 +00:00
|
|
|
|
|
|
|
// Dump and compare.
|
2021-11-17 11:14:22 +00:00
|
|
|
dumpPath := filepath.Join(tmpDir, "testdump.acc")
|
2020-12-01 10:26:53 +00:00
|
|
|
e.Run(t, "neo-go", "db", "dump", "--unittest",
|
|
|
|
"--config-path", tmpDir, "--out", dumpPath)
|
|
|
|
|
|
|
|
d1, err := ioutil.ReadFile(inDump)
|
|
|
|
require.NoError(t, err)
|
|
|
|
d2, err := ioutil.ReadFile(dumpPath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, d1, d2, "dumps differ")
|
|
|
|
}
|