forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from sikkatech/genesis_tests
Add genesis tests
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package wasm | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func TestInitGenesis(t *testing.T) { | ||
data, cleanup := setupTest(t) | ||
defer cleanup() | ||
|
||
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) | ||
topUp := sdk.NewCoins(sdk.NewInt64Coin("denom", 5000)) | ||
creator := createFakeFundedAccount(data.ctx, data.acctKeeper, deposit.Add(deposit)) | ||
fred := createFakeFundedAccount(data.ctx, data.acctKeeper, topUp) | ||
|
||
h := data.module.NewHandler() | ||
q := data.module.NewQuerierHandler() | ||
|
||
msg := MsgStoreCode{ | ||
Sender: creator, | ||
WASMByteCode: testContract, | ||
} | ||
res := h(data.ctx, msg) | ||
require.True(t, res.IsOK()) | ||
require.Equal(t, res.Data, []byte("1")) | ||
|
||
_, _, bob := keyPubAddr() | ||
initMsg := initMsg{ | ||
Verifier: fred.String(), | ||
Beneficiary: bob.String(), | ||
} | ||
initMsgBz, err := json.Marshal(initMsg) | ||
require.NoError(t, err) | ||
|
||
initCmd := MsgInstantiateContract{ | ||
Sender: creator, | ||
Code: 1, | ||
InitMsg: initMsgBz, | ||
InitFunds: deposit, | ||
} | ||
res = h(data.ctx, initCmd) | ||
require.True(t, res.IsOK()) | ||
contractAddr := sdk.AccAddress(res.Data) | ||
|
||
execCmd := MsgExecuteContract{ | ||
Sender: fred, | ||
Contract: contractAddr, | ||
Msg: []byte("{}"), | ||
SentFunds: topUp, | ||
} | ||
res = h(data.ctx, execCmd) | ||
require.True(t, res.IsOK()) | ||
|
||
// ensure all contract state is as after init | ||
assertCodeList(t, q, data.ctx, 1) | ||
assertCodeBytes(t, q, data.ctx, 1, testContract) | ||
|
||
assertContractList(t, q, data.ctx, []string{contractAddr.String()}) | ||
assertContractInfo(t, q, data.ctx, contractAddr, 1, creator) | ||
assertContractState(t, q, data.ctx, contractAddr, state{ | ||
Verifier: fred.String(), | ||
Beneficiary: bob.String(), | ||
Funder: creator.String(), | ||
}) | ||
|
||
// export into genstate | ||
genState := ExportGenesis(data.ctx, data.keeper) | ||
|
||
// create new app to import genstate into | ||
newData, newCleanup := setupTest(t) | ||
defer newCleanup() | ||
q2 := newData.module.NewQuerierHandler() | ||
|
||
// initialize new app with genstate | ||
InitGenesis(newData.ctx, newData.keeper, genState) | ||
|
||
// run same checks again on newdata, to make sure it was reinitialized correctly | ||
assertCodeList(t, q2, newData.ctx, 1) | ||
assertCodeBytes(t, q2, newData.ctx, 1, testContract) | ||
|
||
assertContractList(t, q2, newData.ctx, []string{contractAddr.String()}) | ||
assertContractInfo(t, q2, newData.ctx, contractAddr, 1, creator) | ||
assertContractState(t, q2, newData.ctx, contractAddr, state{ | ||
Verifier: fred.String(), | ||
Beneficiary: bob.String(), | ||
Funder: creator.String(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters