|
| 1 | +//go:build system_test |
| 2 | + |
| 3 | +package systemtests |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "os" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +func TestSnapshots(t *testing.T) { |
| 13 | + |
| 14 | + sut.ResetChain(t) |
| 15 | + cli := NewCLIWrapper(t, sut, verbose) |
| 16 | + sut.StartChain(t) |
| 17 | + |
| 18 | + // Wait for chain produce some blocks |
| 19 | + sut.AwaitNBlocks(t, 6) |
| 20 | + // Stop all nodes |
| 21 | + sut.StopChain() |
| 22 | + |
| 23 | + var ( |
| 24 | + command string |
| 25 | + restoreableDirs []string |
| 26 | + ) |
| 27 | + node0Dir := sut.NodeDir(0) |
| 28 | + if isV2() { |
| 29 | + command = "store" |
| 30 | + restoreableDirs = []string{fmt.Sprintf("%s/data/application.db", node0Dir), fmt.Sprintf("%s/data/ss", node0Dir)} |
| 31 | + } else { |
| 32 | + command = "snapshots" |
| 33 | + restoreableDirs = []string{fmt.Sprintf("%s/data/application.db", node0Dir)} |
| 34 | + } |
| 35 | + |
| 36 | + // export snapshot at height 5 |
| 37 | + res := cli.RunCommandWithArgs(command, "export", "--height=5", fmt.Sprintf("--home=%s", node0Dir)) |
| 38 | + require.Contains(t, res, "Snapshot created at height 5") |
| 39 | + require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", node0Dir)) |
| 40 | + |
| 41 | + // Check snapshots list |
| 42 | + res = cli.RunCommandWithArgs(command, "list", fmt.Sprintf("--home=%s", node0Dir)) |
| 43 | + require.Contains(t, res, "height: 5") |
| 44 | + |
| 45 | + // Dump snapshot |
| 46 | + res = cli.RunCommandWithArgs(command, "dump", "5", "3", fmt.Sprintf("--home=%s", node0Dir), fmt.Sprintf("--output=%s/5-3.tar.gz", node0Dir)) |
| 47 | + // Check if output file exist |
| 48 | + require.FileExists(t, fmt.Sprintf("%s/5-3.tar.gz", node0Dir)) |
| 49 | + |
| 50 | + // Delete snapshots |
| 51 | + res = cli.RunCommandWithArgs(command, "delete", "5", "3", fmt.Sprintf("--home=%s", node0Dir)) |
| 52 | + require.NoDirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", node0Dir)) |
| 53 | + |
| 54 | + // Load snapshot from file |
| 55 | + res = cli.RunCommandWithArgs(command, "load", fmt.Sprintf("%s/5-3.tar.gz", node0Dir), fmt.Sprintf("--home=%s", node0Dir)) |
| 56 | + require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", node0Dir)) |
| 57 | + |
| 58 | + // Restore from snapshots |
| 59 | + for _, dir := range restoreableDirs { |
| 60 | + require.NoError(t, os.RemoveAll(dir)) |
| 61 | + } |
| 62 | + // Remove database |
| 63 | + err := os.RemoveAll(fmt.Sprintf("%s/data/application.db", node0Dir)) |
| 64 | + require.NoError(t, err) |
| 65 | + if isV2() { |
| 66 | + require.NoError(t, os.RemoveAll(fmt.Sprintf("%s/data/ss", node0Dir))) |
| 67 | + } |
| 68 | + |
| 69 | + res = cli.RunCommandWithArgs(command, "restore", "5", "3", fmt.Sprintf("--home=%s", node0Dir)) |
| 70 | + for _, dir := range restoreableDirs { |
| 71 | + require.DirExists(t, dir) |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +func TestPrune(t *testing.T) { |
| 76 | + sut.ResetChain(t) |
| 77 | + cli := NewCLIWrapper(t, sut, verbose) |
| 78 | + |
| 79 | + sut.StartChain(t) |
| 80 | + |
| 81 | + // Wait for chain produce some blocks |
| 82 | + sut.AwaitNBlocks(t, 6) |
| 83 | + |
| 84 | + // Stop all nodes |
| 85 | + sut.StopChain() |
| 86 | + |
| 87 | + node0Dir := sut.NodeDir(0) |
| 88 | + |
| 89 | + // prune |
| 90 | + var command []string |
| 91 | + if isV2() { |
| 92 | + command = []string{"store", "prune", "--keep-recent=1"} |
| 93 | + } else { |
| 94 | + command = []string{"prune", "everything"} |
| 95 | + } |
| 96 | + res := cli.RunCommandWithArgs(append(command, fmt.Sprintf("--home=%s", node0Dir))...) |
| 97 | + require.Contains(t, res, "successfully pruned the application root multi stores") |
| 98 | +} |
0 commit comments