Skip to content

Commit

Permalink
add test from #21913
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 27, 2024
1 parent 295fd9e commit 73c2644
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/systemtests/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,46 @@ package systemtests
import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"

systest "cosmossdk.io/systemtests"
)

func TestChainExportImport(t *testing.T) {
// Scenario:
// given: a state dump from a running chain
// when: new chain is initialized with exported state
// then: the chain should start and produce blocks
systest.Sut.ResetChain(t)
cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)
systest.Sut.StartChain(t)

grantee := cli.GetKeyAddr("node1")
rsp3 := cli.RunAndWait("tx", "authz", "grant", grantee, "send", "--spend-limit=1000stake", "--from=node0", "--fees=1stake")
systest.RequireTxSuccess(t, rsp3)
systest.Sut.StopChain()

outFile := filepath.Join(t.TempDir(), "exported_genesis.json")
cli.RunCommandWithArgs("genesis", "export", "--home="+systest.Sut.NodeDir(0), "--output-document="+outFile)
exportedContent, err := os.ReadFile(outFile)
require.NoError(t, err)
exportedState := gjson.Get(string(exportedContent), "app_state").Raw

systest.Sut.ModifyGenesisJSON(t, func(genesis []byte) []byte {
state, err := sjson.SetRawBytes(genesis, "app_state", []byte(exportedState))
require.NoError(t, err)
return state
})
systest.Sut.StartChain(t)
systest.Sut.AwaitNBlocks(t, 2)
}

func TestExportCmd_WithHeight(t *testing.T) {
systest.Sut.ResetChain(t)
cli := systest.NewCLIWrapper(t, systest.Sut, systest.Verbose)
Expand Down

0 comments on commit 73c2644

Please sign in to comment.