Merge pull request #254 from gustavohmsilva/master

Closes #10 Implemented files called general_consts.go to all modules that heavly relied on  the duplicated "ClientID : 1"
This commit is contained in:
Ethan Frey 2020-10-06 08:36:50 +02:00 committed by GitHub
commit 3b479c3235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 45 deletions

View File

@ -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.

View File

@ -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)
@ -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)
}

View File

@ -11,6 +11,7 @@ import (
)
const (
firstCodeID = 1
DefaultParamspace = types.DefaultParamspace
ModuleName = types.ModuleName
StoreKey = types.StoreKey
@ -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

View File

@ -90,7 +90,7 @@ func TestInitGenesis(t *testing.T) {
initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: deposit,
}

View File

@ -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()
@ -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,
}},
@ -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,
}, {
@ -161,7 +163,7 @@ func TestFailFastImport(t *testing.T) {
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}, {
CodeID: 1,
CodeID: firstCodeID,
CodeInfo: myCodeInfo,
CodesBytes: wasmCode,
}},
@ -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,
}},
@ -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,
},
@ -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,
}},
@ -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,
}},
@ -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,
}},
@ -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,
}},
@ -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,
}},
@ -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芢毤",
@ -461,7 +463,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
expHistory := []types.ContractCodeHistoryEntry{{
Operation: types.GenesisContractCodeHistoryType,
CodeID: 1,
CodeID: firstCodeID,
Updated: types.NewAbsoluteTxPosition(ctx),
},
}

View File

@ -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))
})
@ -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"))

View File

@ -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"
@ -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,

View File

@ -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"`),
}, {
@ -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,
@ -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"`),
}},

View File

@ -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

View File

@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/require"
)
const firstCodeID = 1
func TestBuilderRegexp(t *testing.T) {
cases := map[string]struct {
example string
@ -146,7 +148,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"correct minimal": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte("{}"),
},
@ -177,7 +179,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"bad sender minimal": {
msg: MsgInstantiateContract{
Sender: badAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
InitMsg: []byte("{}"),
},
@ -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)}},
@ -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)
@ -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"),
},
@ -216,7 +218,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"empty init msg": {
msg: MsgInstantiateContract{
Sender: goodAddress,
CodeID: 1,
CodeID: firstCodeID,
Label: "foo",
},
valid: false,
@ -479,7 +481,7 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
MigrateMsg: []byte("{}"),
},
},
@ -487,14 +489,14 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: badAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
"empty sender": {
src: MsgMigrateContract{
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},
@ -509,14 +511,14 @@ 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,
},
@ -524,7 +526,7 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
MigrateMsg: []byte("invalid json"),
},
expErr: true,
@ -533,7 +535,7 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
CodeID: 1,
CodeID: firstCodeID,
},
expErr: true,
},

View File

@ -171,7 +171,7 @@ func TestHandleInstantiate(t *testing.T) {
// create with no balance is also legal
initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: nil,
}
@ -228,7 +228,7 @@ func TestHandleExecute(t *testing.T) {
initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: deposit,
}
@ -339,7 +339,7 @@ func TestHandleExecuteEscrow(t *testing.T) {
initCmd := MsgInstantiateContract{
Sender: creator,
CodeID: 1,
CodeID: firstCodeID,
InitMsg: initMsgBz,
InitFunds: deposit,
}