From 3ea9634291bcd36fcb1746dd77df2f6560f3bdc3 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 21 Feb 2018 16:14:49 +0100 Subject: [PATCH] Test init/query mock app --- mock/app_test.go | 36 ++++++++++++++++++++++++++++++++++++ mock/helpers.go | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 mock/app_test.go diff --git a/mock/app_test.go b/mock/app_test.go new file mode 100644 index 000000000..782362827 --- /dev/null +++ b/mock/app_test.go @@ -0,0 +1,36 @@ +package mock + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + abci "github.com/tendermint/abci/types" +) + +// TestInitApp makes sure we can initialize this thing without an error +func TestInitApp(t *testing.T) { + // set up an app + app, closer, err := SetupApp() + // closer may need to be run, even when error in later stage + if closer != nil { + defer closer() + } + require.NoError(t, err) + + // initialize it future-way + opts, err := GenInitOptions(nil) + require.NoError(t, err) + req := abci.RequestInitChain{AppStateBytes: opts} + app.InitChain(req) + + // make sure we can query these values + query := abci.RequestQuery{ + Path: "/main/key", + Data: []byte("foo"), + } + qres := app.Query(query) + require.Equal(t, uint32(0), qres.Code, qres.Log) + assert.Equal(t, []byte("bar"), qres.Value) +} diff --git a/mock/helpers.go b/mock/helpers.go index 4b6f70ba7..4e30eaa30 100644 --- a/mock/helpers.go +++ b/mock/helpers.go @@ -13,7 +13,7 @@ import ( func SetupApp() (abci.Application, func(), error) { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)). With("module", "mock") - rootDir, err := ioutil.TempDir("mock-sdk", "") + rootDir, err := ioutil.TempDir("", "mock-sdk") if err != nil { return nil, nil, err }