Skip to content

Commit

Permalink
Merge pull request CosmWasm#254 from gustavohmsilva/master
Browse files Browse the repository at this point in the history
Closes CosmWasm#10 Implemented files called general_consts.go to all modules that heavly relied on  the duplicated "ClientID : 1"
  • Loading branch information
ethanfrey authored Oct 6, 2020
2 parents 2d9bd47 + fd2f51c commit 3b479c3
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type WasmApp struct {
// WasmWrapper allows us to use namespacing in the config file
// This is only used for parsing in the app, x/wasm expects WasmConfig
type WasmWrapper struct {
Wasm wasm.WasmConfig `mapstructure:"wasm"`
Wasm wasm.Config `mapstructure:"wasm"`
}

// NewWasmApp returns a reference to an initialized WasmApp.
Expand Down
5 changes: 3 additions & 2 deletions lcd_test/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/stretchr/testify/require"
)

const firstCodeID = 1

func TestWasmStoreCode(t *testing.T) {
kb, err := newKeybase()
require.NoError(t, err)
Expand Down Expand Up @@ -73,7 +75,6 @@ func TestWasmStoreCode(t *testing.T) {
require.Len(t, listPayload.Result, 1)

// and check detail view
codeID := "1"
resp, body = Request(t, port, "GET", fmt.Sprintf("/wasm/code/%s", codeID), nil)
resp, body = Request(t, port, "GET", fmt.Sprintf("/wasm/code/%d", firstCodeID), nil)
require.Equal(t, http.StatusOK, resp.StatusCode, body)
}
3 changes: 2 additions & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
firstCodeID = 1
DefaultParamspace = types.DefaultParamspace
ModuleName = types.ModuleName
StoreKey = types.StoreKey
Expand Down Expand Up @@ -112,7 +113,7 @@ type (
CodeInfo = types.CodeInfo
ContractInfo = types.ContractInfo
CreatedAt = types.AbsoluteTxPosition
WasmConfig = types.WasmConfig
Config = types.WasmConfig
MessageHandler = keeper.MessageHandler
BankEncoder = keeper.BankEncoder
CustomEncoder = keeper.CustomEncoder
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestInitGenesis(t *testing.T) {

initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: deposit,
}
Expand Down
28 changes: 15 additions & 13 deletions x/wasm/internal/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
dbm "github.com/tendermint/tm-db"
)

const firstCodeID = 1

func TestGenesisExportImport(t *testing.T) {
srcKeeper, srcCtx, srcStoreKeys, srcCleanup := setupKeeper(t)
defer srcCleanup()
Expand Down Expand Up @@ -123,7 +125,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code info correct": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -138,7 +140,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code ids can contain gaps": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}, {
Expand All @@ -161,7 +163,7 @@ func TestFailFastImport(t *testing.T) {
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}, {
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -176,7 +178,7 @@ func TestFailFastImport(t *testing.T) {
},
"prevent code hash mismatch": {src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: wasmTypes.CodeInfoFixture(func(i *wasmTypes.CodeInfo) { i.CodeHash = make([]byte, sha256.Size) }),
CodesBytes: wasmCode,
}},
Expand All @@ -185,12 +187,12 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate codeIDs": {src: types.GenesisState{
Codes: []types.Code{
{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
},
{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
},
Expand All @@ -200,7 +202,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code id in info and contract do match": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -221,7 +223,7 @@ func TestFailFastImport(t *testing.T) {
"happy path: code info with two contracts": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -256,7 +258,7 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate contract address": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand All @@ -275,7 +277,7 @@ func TestFailFastImport(t *testing.T) {
"prevent duplicate contract model keys": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -323,7 +325,7 @@ func TestFailFastImport(t *testing.T) {
"prevent contract id seq init value == count contracts": {
src: types.GenesisState{
Codes: []types.Code{{
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
Expand Down Expand Up @@ -451,7 +453,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
adminAddr, _ := sdk.AccAddressFromBech32("cosmos1h5t8zxmjr30e9dqghtlpl40f2zz5cgey6esxtn")

expContractInfo := types.ContractInfo{
CodeID: 1,
CodeID: firstCodeID,
Creator: contractCreatorAddr,
Admin: adminAddr,
Label: "ȀĴnZV芢毤",
Expand All @@ -461,7 +463,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {

expHistory := []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
},
}
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestIsSimulationMode(t *testing.T) {
exp: true,
},
}
for msg, _ := range specs {
for msg := range specs {
t.Run(msg, func(t *testing.T) {
//assert.Equal(t, spec.exp, isSimulationMode(spec.ctx))
})
Expand Down Expand Up @@ -994,8 +994,8 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
},
},
}
expJsonEvts := string(mustMarshal(t, expEvents))
assert.JSONEq(t, expJsonEvts, prettyEvents(t, ctx.EventManager().Events()))
expJSONEvts := string(mustMarshal(t, expEvents))
assert.JSONEq(t, expJSONEvts, prettyEvents(t, ctx.EventManager().Events()))

// all persistent data cleared
m := keeper.QueryRaw(ctx, contractAddr, []byte("config"))
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestInstantiateProposal(t *testing.T) {
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, sdk.AddrLen)
)
src := types.InstantiateContractProposalFixture(func(p *types.InstantiateContractProposal) {
p.CodeID = 1
p.CodeID = firstCodeID
p.RunAs = oneAddress
p.Admin = otherAddress
p.Label = "testing"
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestMigrateProposal(t *testing.T) {
assert.Equal(t, "testing", cInfo.Label)
expHistory := []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
}, {
Operation: types.MigrateContractCodeHistoryType,
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/internal/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ func TestQueryContractHistory(t *testing.T) {
"response with internal fields cleared": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Msg: []byte(`"init message"`),
}},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
}},
},
"response with multiple entries": {
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.InitContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Msg: []byte(`"init message"`),
}, {
Expand All @@ -266,7 +266,7 @@ func TestQueryContractHistory(t *testing.T) {
}},
expContent: []types.ContractCodeHistoryEntry{{
Operation: types.InitContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Msg: []byte(`"init message"`),
}, {
Operation: types.MigrateContractCodeHistoryType,
Expand All @@ -282,7 +282,7 @@ func TestQueryContractHistory(t *testing.T) {
srcQueryAddr: otherAddr,
srcHistory: []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
Msg: []byte(`"init message"`),
}},
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/test_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func FuzzStateModel(m *types.Model, c fuzz.Continue) {

func FuzzAccessType(m *types.AccessType, c fuzz.Continue) {
pos := c.Int() % len(types.AllAccessTypes)
for k, _ := range types.AllAccessTypes {
for k := range types.AllAccessTypes {
if pos == 0 {
*m = k
return
Expand Down
28 changes: 15 additions & 13 deletions x/wasm/internal/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/require"
)

const firstCodeID = 1

func TestBuilderRegexp(t *testing.T) {
cases := map[string]struct {
example string
Expand Down Expand Up @@ -146,7 +148,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"correct minimal": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte("{}"),
},
Expand Down Expand Up @@ -177,7 +179,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"bad sender minimal": {
msg: MsgInstantiateContract{
Sender: badAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte("{}"),
},
Expand All @@ -186,7 +188,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"correct maximal": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte(`{"some": "data"}`),
InitFunds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}},
Expand All @@ -196,7 +198,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"negative funds": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte(`{"some": "data"}`),
// we cannot use sdk.NewCoin() constructors as they panic on creating invalid data (before we can test)
Expand All @@ -207,7 +209,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"non json init msg": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte("invalid-json"),
},
Expand All @@ -216,7 +218,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"empty init msg": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
},
valid: false,
Expand Down Expand Up @@ -479,22 +481,22 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
MigrateMsg: []byte("{}"),
},
},
"bad sender": {
src: MsgMigrateContract{
Sender: badAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
"empty sender": {
src: MsgMigrateContract{
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
Expand All @@ -509,22 +511,22 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: badAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
"empty contract addr": {
src: MsgMigrateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
"non json migrateMsg": {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
MigrateMsg: []byte("invalid json"),
},
expErr: true,
Expand All @@ -533,7 +535,7 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
Expand Down
Loading

0 comments on commit 3b479c3

Please sign in to comment.