mirror of https://github.com/certusone/wasmd.git
Implemented files called general_consts.go to all modules that heavly relied on the duplicated "CLientID : 1"
Future duplicated variables across the entire module can also be added to it, centralizing therefore all os those kind of values.
This commit is contained in:
parent
70a1dbac64
commit
23ce8e84c9
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const CID = 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", CID), nil)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode, body)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
CID = 1
|
||||
DefaultParamspace = types.DefaultParamspace
|
||||
ModuleName = types.ModuleName
|
||||
StoreKey = types.StoreKey
|
||||
|
|
|
@ -90,7 +90,7 @@ func TestInitGenesis(t *testing.T) {
|
|||
|
||||
initCmd := MsgInstantiateContract{
|
||||
Sender: creator,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
InitMsg: initMsgBz,
|
||||
InitFunds: deposit,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package keeper
|
||||
|
||||
const (
|
||||
// CID relates to the initial CodeID, referenced by multipe files in the keeper package
|
||||
CID = 1
|
||||
)
|
|
@ -123,7 +123,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"happy path: code info correct": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -138,7 +138,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"happy path: code ids can contain gaps": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}, {
|
||||
|
@ -161,7 +161,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}, {
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -176,7 +176,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
},
|
||||
"prevent code hash mismatch": {src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: wasmTypes.CodeInfoFixture(func(i *wasmTypes.CodeInfo) { i.CodeHash = make([]byte, sha256.Size) }),
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -185,12 +185,12 @@ func TestFailFastImport(t *testing.T) {
|
|||
"prevent duplicate codeIDs": {src: types.GenesisState{
|
||||
Codes: []types.Code{
|
||||
{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
},
|
||||
{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
},
|
||||
|
@ -200,7 +200,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: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -221,7 +221,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"happy path: code info with two contracts": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -256,7 +256,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"prevent duplicate contract address": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -275,7 +275,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"prevent duplicate contract model keys": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -323,7 +323,7 @@ func TestFailFastImport(t *testing.T) {
|
|||
"prevent contract id seq init value == count contracts": {
|
||||
src: types.GenesisState{
|
||||
Codes: []types.Code{{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
CodeInfo: myCodeInfo,
|
||||
CodesBytes: wasmCode,
|
||||
}},
|
||||
|
@ -451,7 +451,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
|
|||
adminAddr, _ := sdk.AccAddressFromBech32("cosmos1h5t8zxmjr30e9dqghtlpl40f2zz5cgey6esxtn")
|
||||
|
||||
expContractInfo := types.ContractInfo{
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Creator: contractCreatorAddr,
|
||||
Admin: adminAddr,
|
||||
Label: "ȀĴnZV芢毤",
|
||||
|
@ -461,7 +461,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
|
|||
|
||||
expHistory := []types.ContractCodeHistoryEntry{{
|
||||
Operation: types.GenesisContractCodeHistoryType,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Updated: types.NewAbsoluteTxPosition(ctx),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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 = CID
|
||||
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: CID,
|
||||
Updated: types.NewAbsoluteTxPosition(ctx),
|
||||
}, {
|
||||
Operation: types.MigrateContractCodeHistoryType,
|
||||
|
|
|
@ -237,20 +237,20 @@ func TestQueryContractHistory(t *testing.T) {
|
|||
"response with internal fields cleared": {
|
||||
srcHistory: []types.ContractCodeHistoryEntry{{
|
||||
Operation: types.GenesisContractCodeHistoryType,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Updated: types.NewAbsoluteTxPosition(ctx),
|
||||
Msg: []byte(`"init message"`),
|
||||
}},
|
||||
expContent: []types.ContractCodeHistoryEntry{{
|
||||
Operation: types.GenesisContractCodeHistoryType,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Msg: []byte(`"init message"`),
|
||||
}},
|
||||
},
|
||||
"response with multiple entries": {
|
||||
srcHistory: []types.ContractCodeHistoryEntry{{
|
||||
Operation: types.InitContractCodeHistoryType,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
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: CID,
|
||||
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: CID,
|
||||
Updated: types.NewAbsoluteTxPosition(ctx),
|
||||
Msg: []byte(`"init message"`),
|
||||
}},
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
const (
|
||||
// CID relates to the initial CodeID, referenced by multipe files in the keeper package
|
||||
CID = 1
|
||||
)
|
|
@ -146,7 +146,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"correct minimal": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Label: "foo",
|
||||
InitMsg: []byte("{}"),
|
||||
},
|
||||
|
@ -177,7 +177,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"bad sender minimal": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: badAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Label: "foo",
|
||||
InitMsg: []byte("{}"),
|
||||
},
|
||||
|
@ -186,7 +186,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"correct maximal": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Label: "foo",
|
||||
InitMsg: []byte(`{"some": "data"}`),
|
||||
InitFunds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}},
|
||||
|
@ -196,7 +196,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"negative funds": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
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 +207,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"non json init msg": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Label: "foo",
|
||||
InitMsg: []byte("invalid-json"),
|
||||
},
|
||||
|
@ -216,7 +216,7 @@ func TestInstantiateContractValidation(t *testing.T) {
|
|||
"empty init msg": {
|
||||
msg: MsgInstantiateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
Label: "foo",
|
||||
},
|
||||
valid: false,
|
||||
|
@ -479,7 +479,7 @@ func TestMsgMigrateContract(t *testing.T) {
|
|||
src: MsgMigrateContract{
|
||||
Sender: goodAddress,
|
||||
Contract: anotherGoodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
MigrateMsg: []byte("{}"),
|
||||
},
|
||||
},
|
||||
|
@ -487,14 +487,14 @@ func TestMsgMigrateContract(t *testing.T) {
|
|||
src: MsgMigrateContract{
|
||||
Sender: badAddress,
|
||||
Contract: anotherGoodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
"empty sender": {
|
||||
src: MsgMigrateContract{
|
||||
Contract: anotherGoodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
|
@ -509,14 +509,14 @@ func TestMsgMigrateContract(t *testing.T) {
|
|||
src: MsgMigrateContract{
|
||||
Sender: goodAddress,
|
||||
Contract: badAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
"empty contract addr": {
|
||||
src: MsgMigrateContract{
|
||||
Sender: goodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
|
@ -524,7 +524,7 @@ func TestMsgMigrateContract(t *testing.T) {
|
|||
src: MsgMigrateContract{
|
||||
Sender: goodAddress,
|
||||
Contract: anotherGoodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
MigrateMsg: []byte("invalid json"),
|
||||
},
|
||||
expErr: true,
|
||||
|
@ -533,7 +533,7 @@ func TestMsgMigrateContract(t *testing.T) {
|
|||
src: MsgMigrateContract{
|
||||
Sender: goodAddress,
|
||||
Contract: anotherGoodAddress,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
|
|
|
@ -171,7 +171,7 @@ func TestHandleInstantiate(t *testing.T) {
|
|||
// create with no balance is also legal
|
||||
initCmd := MsgInstantiateContract{
|
||||
Sender: creator,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
InitMsg: initMsgBz,
|
||||
InitFunds: nil,
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ func TestHandleExecute(t *testing.T) {
|
|||
|
||||
initCmd := MsgInstantiateContract{
|
||||
Sender: creator,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
InitMsg: initMsgBz,
|
||||
InitFunds: deposit,
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ func TestHandleExecuteEscrow(t *testing.T) {
|
|||
|
||||
initCmd := MsgInstantiateContract{
|
||||
Sender: creator,
|
||||
CodeID: 1,
|
||||
CodeID: CID,
|
||||
InitMsg: initMsgBz,
|
||||
InitFunds: deposit,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue