Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk committed Aug 21, 2024
1 parent 0758a91 commit 59486ec
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions tests/systemtests/snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ package systemtests
import (
"fmt"
"os"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"
)

var nodeDir = fmt.Sprintf("./testnet/node0/%s", sut.execBinary)
func getBinaryNameAndPrefix(isSnapshot bool) (string, string) {
if sut.execBinary == filepath.Join(WorkDir, "binaries", "simd") {
if isSnapshot {
return "simd", "snapshots"
}
return "simd", ""
}
return "simdv2", "store"
}

func TestSnapshots(t *testing.T) {
sut.ResetChain(t)
Expand All @@ -24,46 +33,55 @@ func TestSnapshots(t *testing.T) {

sut.StartChain(t)

binary, snapshotPrefix := getBinaryNameAndPrefix(true)
nodeDir := fmt.Sprintf("./testnet/node0/%s", binary)

// Wait for chain produce some blocks
time.Sleep(time.Second * 10)
// Stop 1 node
err := sut.StopSingleNode()
require.NoError(t, err)
time.Sleep(time.Second)
time.Sleep(time.Second)

// export snapshot at height 5
res := cli.RunCommandWithArgs("store", "export", "--height=5", fmt.Sprintf("--home=%s", nodeDir))
res := cli.RunCommandWithArgs(snapshotPrefix, "export", "--height=5", fmt.Sprintf("--home=%s", nodeDir))
require.Contains(t, res, "Snapshot created at height 5")
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir))

// Check snapshots list
res = cli.RunCommandWithArgs("store", "list", fmt.Sprintf("--home=%s", nodeDir))
res = cli.RunCommandWithArgs(snapshotPrefix, "list", fmt.Sprintf("--home=%s", nodeDir))
require.Contains(t, res, "height: 5")

// Dump snapshot
res = cli.RunCommandWithArgs("store", "dump", "5", "3", fmt.Sprintf("--home=%s", nodeDir), "--output=./testnet/node0/simdv2/5-3.tar.gz")
res = cli.RunCommandWithArgs(snapshotPrefix, "dump", "5", "3", fmt.Sprintf("--home=%s", nodeDir), fmt.Sprintf("--output=%s/5-3.tar.gz", nodeDir))
// Check if output file exist
require.FileExists(t, fmt.Sprintf("%s/5-3.tar.gz", nodeDir))

// Delete snapshots
res = cli.RunCommandWithArgs("store", "delete", "5", "3", fmt.Sprintf("--home=%s", nodeDir))
res = cli.RunCommandWithArgs(snapshotPrefix, "delete", "5", "3", fmt.Sprintf("--home=%s", nodeDir))
require.NoDirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir))

// Load snapshot from file
res = cli.RunCommandWithArgs("store", "load", fmt.Sprintf("%s/5-3.tar.gz", nodeDir), fmt.Sprintf("--home=%s", nodeDir))
res = cli.RunCommandWithArgs(snapshotPrefix, "load", fmt.Sprintf("%s/5-3.tar.gz", nodeDir), fmt.Sprintf("--home=%s", nodeDir))
require.DirExists(t, fmt.Sprintf("%s/data/snapshots/5/3", nodeDir))

// Restore from snapshots

// Remove sc & ss database
// Remove database
err = os.RemoveAll(fmt.Sprintf("%s/data/application.db", nodeDir))
require.NoError(t, err)
err = os.RemoveAll(fmt.Sprintf("%s/data/ss", nodeDir))
require.NoError(t, err)

res = cli.RunCommandWithArgs("store", "restore", "5", "3", fmt.Sprintf("--home=%s", nodeDir))
// Only v2 have ss database
if binary == "simdv2" {
err = os.RemoveAll(fmt.Sprintf("%s/data/ss", nodeDir))
require.NoError(t, err)
}

res = cli.RunCommandWithArgs(snapshotPrefix, "restore", "5", "3", fmt.Sprintf("--home=%s", nodeDir))
require.DirExists(t, fmt.Sprintf("%s/data/application.db", nodeDir))
require.DirExists(t, fmt.Sprintf("%s/data/ss", nodeDir))
if binary == "simdv2" {
require.DirExists(t, fmt.Sprintf("%s/data/ss", nodeDir))
}

// Start the node
sut.StartSingleNode(t, nodeDir)
Expand All @@ -80,17 +98,24 @@ func TestPrune(t *testing.T) {

sut.StartChain(t)

binary, prefix := getBinaryNameAndPrefix(false)
nodeDir := fmt.Sprintf("./testnet/node0/%s", binary)

// Wait for chain produce some blocks
time.Sleep(time.Second * 10)
// Stop 1 node
err := sut.StopSingleNode()
require.NoError(t, err)
time.Sleep(time.Second)
time.Sleep(time.Second)

// prune
res := cli.RunCommandWithArgs("store", "prune", "--keep-recent=1", fmt.Sprintf("--home=%s", nodeDir))
var res string
if binary == "simdv2" {
res = cli.RunCommandWithArgs(prefix, "prune", "--keep-recent=1", fmt.Sprintf("--home=%s", nodeDir))
} else {
res = cli.RunCommandWithArgs("prune", "everything", fmt.Sprintf("--home=%s", nodeDir))
}
require.Contains(t, res, "successfully pruned the application root multi stores")

// Start the node
sut.StartSingleNode(t, nodeDir)
}
}

0 comments on commit 59486ec

Please sign in to comment.