github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/mock/app_test.go (about) 1 package mock 2 3 import ( 4 "testing" 5 6 appconfig "github.com/fibonacci-chain/fbc/app/config" 7 "github.com/fibonacci-chain/fbc/libs/tendermint/types" 8 9 "github.com/stretchr/testify/require" 10 11 abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types" 12 ) 13 14 // TestInitApp makes sure we can initialize this thing without an error 15 func TestInitApp(t *testing.T) { 16 // set up an app 17 app, closer, err := SetupApp() 18 19 // closer may need to be run, even when error in later stage 20 if closer != nil { 21 defer closer() 22 } 23 require.NoError(t, err) 24 25 // initialize it future-way 26 appState, err := AppGenState(nil, types.GenesisDoc{}, nil) 27 require.NoError(t, err) 28 29 //TODO test validators in the init chain? 30 req := abci.RequestInitChain{ 31 AppStateBytes: appState, 32 } 33 app.InitChain(req) 34 app.Commit(abci.RequestCommit{}) 35 36 // make sure we can query these values 37 query := abci.RequestQuery{ 38 Path: "/store/main/key", 39 Data: []byte("foo"), 40 } 41 qres := app.Query(query) 42 require.Equal(t, uint32(0), qres.Code, qres.Log) 43 require.Equal(t, []byte("bar"), qres.Value) 44 } 45 46 // TextDeliverTx ensures we can write a tx 47 func TestDeliverTx(t *testing.T) { 48 appconfig.GetFecConfig().SetDynamicGpMode(0) 49 // set up an app 50 app, closer, err := SetupApp() 51 // closer may need to be run, even when error in later stage 52 if closer != nil { 53 defer closer() 54 } 55 require.NoError(t, err) 56 57 appState, err := AppGenState(nil, types.GenesisDoc{}, nil) 58 require.NoError(t, err) 59 req := abci.RequestInitChain{ 60 AppStateBytes: appState, 61 } 62 app.InitChain(req) 63 64 key := "my-special-key" 65 value := "top-secret-data!!" 66 tx := NewTx(key, value) 67 txBytes := tx.GetSignBytes() 68 69 header := abci.Header{ 70 AppHash: []byte("apphash"), 71 Height: 1, 72 } 73 app.BeginBlock(abci.RequestBeginBlock{Header: header}) 74 dres := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes}) 75 require.Equal(t, uint32(0), dres.Code, dres.Log) 76 app.EndBlock(abci.RequestEndBlock{}) 77 cres := app.Commit(abci.RequestCommit{}) 78 require.NotEmpty(t, cres.Data) 79 80 // make sure we can query these values 81 query := abci.RequestQuery{ 82 Path: "/store/main/key", 83 Data: []byte(key), 84 } 85 qres := app.Query(query) 86 require.Equal(t, uint32(0), qres.Code, qres.Log) 87 require.Equal(t, []byte(value), qres.Value) 88 }