feat(schema): testing utilities (#20705)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Aaron Craelius
2024-07-31 06:58:30 +00:00
committed by GitHub
co-authored by coderabbitai[bot]
parent 6eea0ae6d2
commit e7844e640c
40 changed files with 2147 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
package appdatasim
import (
"testing"
"github.com/stretchr/testify/require"
"gotest.tools/v3/golden"
"cosmossdk.io/schema"
schematesting "cosmossdk.io/schema/testing"
)
// this test checks that diffs in app data are deterministic and can be used for regression testing
func TestDiffAppData(t *testing.T) {
appSim, err := NewSimulator(Options{
AppSchema: schematesting.ExampleAppSchema,
})
require.NoError(t, err)
mirror, err := NewSimulator(Options{
// add just one module to the mirror
AppSchema: map[string]schema.ModuleSchema{
"all_kinds": schematesting.ExampleAppSchema["all_kinds"],
},
})
require.NoError(t, err)
// mirror one block
blockGen := appSim.BlockDataGenN(50, 100)
blockData := blockGen.Example(1)
require.NoError(t, appSim.ProcessBlockData(blockData))
require.NoError(t, mirror.ProcessBlockData(blockData))
// produce another block, but don't mirror it so that they're out of sync
blockData = blockGen.Example(2)
require.NoError(t, appSim.ProcessBlockData(blockData))
golden.Assert(t, DiffAppData(appSim, mirror), "diff_example.txt")
}