cosmos-sdk/server/mock/app_test.go
Alessio Treglia c20fcbfd8f New genesis workflow (#2602)
New genesis workflow:
* `gaiad init` is now used to generate an empty `genesis.json`.
* Genesis accounts need to be populated manually before running
  `gaiad collect-gentxs`.
* This should support starfish too, see #2615 for more info.
* Closes: #2596 #2615
* Validate validator address and address against respective account ex ante
* Fix local testnet failures
* New genesis tests
* Run make format
* Add --pubkey flag
* gaiad collect-gentxs takes no args
2018-11-04 20:26:46 -08:00

79 lines
1.8 KiB
Go

package mock
import (
"github.com/tendermint/tendermint/types"
"testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/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
appState, err := AppGenState(nil, types.GenesisDoc{}, nil)
require.NoError(t, err)
//TODO test validators in the init chain?
req := abci.RequestInitChain{
AppStateBytes: appState,
}
app.InitChain(req)
app.Commit()
// make sure we can query these values
query := abci.RequestQuery{
Path: "/store/main/key",
Data: []byte("foo"),
}
qres := app.Query(query)
require.Equal(t, uint32(0), qres.Code, qres.Log)
require.Equal(t, []byte("bar"), qres.Value)
}
// TextDeliverTx ensures we can write a tx
func TestDeliverTx(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)
key := "my-special-key"
value := "top-secret-data!!"
tx := NewTx(key, value)
txBytes := tx.GetSignBytes()
header := abci.Header{
AppHash: []byte("apphash"),
Height: 1,
}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
dres := app.DeliverTx(txBytes)
require.Equal(t, uint32(0), dres.Code, dres.Log)
app.EndBlock(abci.RequestEndBlock{})
cres := app.Commit()
require.NotEmpty(t, cres.Data)
// make sure we can query these values
query := abci.RequestQuery{
Path: "/store/main/key",
Data: []byte(key),
}
qres := app.Query(query)
require.Equal(t, uint32(0), qres.Code, qres.Log)
require.Equal(t, []byte(value), qres.Value)
}