Skip to content

Commit 51a288f

Browse files
author
HaoyangLiu
authored
Merge pull request #779 from HaoyangLiu/haoyang/develop
R4R: Merge PRs from cosmos-sdk 0.27
2 parents 9067358 + b11d235 commit 51a288f

File tree

35 files changed

+112
-203
lines changed

35 files changed

+112
-203
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ RUN cd $REPO_PATH && \
2626
make get_vendor_deps && \
2727
make test_unit && \
2828
make build_linux && \
29-
make install
29+
make install && \
30+
make test_cli
3031

3132
FROM alpine:3.7
3233

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation' | grep -v '/prometheus' | grep -v '/clitest' | grep -v '/lcd' | grep -v '/protobuf')
22
PACKAGES_MODULES=$(shell go list ./... | grep 'modules')
3-
PACKAGES_TYPES=$(shell go list ./... | grep 'types')
3+
PACKAGES_TYPES=$(shell go list ./... | grep 'irisnet/irishub/types')
4+
PACKAGES_STORE=$(shell go list ./... | grep 'irisnet/irishub/store')
45
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
56

67
all: get_tools get_vendor_deps install
@@ -74,7 +75,7 @@ install: update_irislcd_swagger_docs echo_bech32_prefix
7475
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/iriscli
7576
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/irislcd
7677
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/iristool
77-
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/newiris
78+
# go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/newiris
7879

7980
build_linux: update_irislcd_swagger_docs echo_bech32_prefix
8081
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o build/iris ./cmd/iris && \
@@ -100,6 +101,7 @@ test_unit:
100101
#@go test $(PACKAGES_NOSIMULATION)
101102
@go test $(PACKAGES_MODULES)
102103
@go test $(PACKAGES_TYPES)
104+
@go test $(PACKAGES_STORE)
103105

104106
test_cli:
105107
@go test -timeout 20m -count 1 -p 1 client/clitest/utils.go client/clitest/bank_test.go client/clitest/distribution_test.go client/clitest/gov_test.go client/clitest/iparam_test.go client/clitest/irismon_test.go client/clitest/record_test.go client/clitest/service_test.go client/clitest/stake_test.go

app/app.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode)
466466
logs := make([]string, 0, len(msgs))
467467
var data []byte // NOTE: we just append them all (?!)
468468
var tags sdk.Tags // also just append them all
469-
var code sdk.ABCICodeType
469+
var code sdk.CodeType
470+
var codespace sdk.CodespaceType
470471
for msgIdx, msg := range msgs {
471472
// Match route.
472473
var msgType string
@@ -503,6 +504,7 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode)
503504
if !msgResult.IsOK() {
504505
logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log))
505506
code = msgResult.Code
507+
codespace = msgResult.Codespace
506508
break
507509
}
508510

@@ -512,10 +514,11 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode)
512514

513515
// Set the final gas values.
514516
result = sdk.Result{
515-
Code: code,
516-
Data: data,
517-
Log: strings.Join(logs, "\n"),
518-
GasUsed: ctx.GasMeter().GasConsumed(),
517+
Code: code,
518+
Codespace: codespace,
519+
Data: data,
520+
Log: strings.Join(logs, "\n"),
521+
GasUsed: ctx.GasMeter().GasConsumed(),
519522
// TODO: FeeAmount/FeeDenom
520523
Tags: tags,
521524
}

baseapp/baseapp.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type BaseApp struct {
5050
cms sdk.CommitMultiStore // Main (uncached) state
5151
router Router // handle any kind of message
5252
queryRouter QueryRouter // router for redirecting query calls
53-
codespacer *sdk.Codespacer // handle module codespacing
5453
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx
5554

5655
anteHandler sdk.AnteHandler // ante handler for fee and auth
@@ -100,13 +99,9 @@ func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecod
10099
cms: store.NewCommitMultiStore(db),
101100
router: NewRouter(),
102101
queryRouter: NewQueryRouter(),
103-
codespacer: sdk.NewCodespacer(),
104102
txDecoder: txDecoder,
105103
}
106104

107-
// Register the undefined & root codespaces, which should not be used by
108-
// any modules.
109-
app.codespacer.RegisterOrPanic(sdk.CodespaceRoot)
110105
for _, option := range options {
111106
option(app)
112107
}
@@ -124,11 +119,6 @@ func (app *BaseApp) SetCommitMultiStoreTracer(w io.Writer) {
124119
app.cms.WithTracer(w)
125120
}
126121

127-
// Register the next available codespace through the baseapp's codespacer, starting from a default
128-
func (app *BaseApp) RegisterCodespace(codespace sdk.CodespaceType) sdk.CodespaceType {
129-
return app.codespacer.RegisterNext(codespace)
130-
}
131-
132122
// Mount IAVL stores to the provided keys in the BaseApp multistore
133123
func (app *BaseApp) MountStoresIAVL(keys ...*sdk.KVStoreKey) {
134124
for _, key := range keys {
@@ -345,8 +335,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
345335
}
346336
case "version":
347337
return abci.ResponseQuery{
348-
Code: uint32(sdk.ABCICodeOK),
349-
Value: []byte(version.GetVersion()),
338+
Code: uint32(sdk.CodeOK),
339+
Codespace: string(sdk.CodespaceRoot),
340+
Value: []byte(version.GetVersion()),
350341
}
351342
default:
352343
result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result()
@@ -355,8 +346,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
355346
// Encode with json
356347
value := codec.Cdc.MustMarshalBinaryLengthPrefixed(result)
357348
return abci.ResponseQuery{
358-
Code: uint32(sdk.ABCICodeOK),
359-
Value: value,
349+
Code: uint32(sdk.CodeOK),
350+
Codespace: string(sdk.CodespaceRoot),
351+
Value: value,
360352
}
361353
}
362354
msg := "Expected second parameter to be either simulate or version, neither was present"
@@ -415,12 +407,13 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
415407
resBytes, err := querier(ctx, path[2:], req)
416408
if err != nil {
417409
return abci.ResponseQuery{
418-
Code: uint32(err.ABCICode()),
419-
Log: err.ABCILog(),
410+
Code: uint32(err.Code()),
411+
Codespace: string(err.Codespace()),
412+
Log: err.ABCILog(),
420413
}
421414
}
422415
return abci.ResponseQuery{
423-
Code: uint32(sdk.ABCICodeOK),
416+
Code: uint32(sdk.CodeOK),
424417
Value: resBytes,
425418
}
426419
}
@@ -478,6 +471,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
478471

479472
return abci.ResponseCheckTx{
480473
Code: uint32(result.Code),
474+
Codespace: string(result.Codespace),
481475
Data: result.Data,
482476
Log: result.Log,
483477
GasWanted: result.GasWanted,
@@ -526,6 +520,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
526520
// Tell the blockchain engine (i.e. Tendermint).
527521
return abci.ResponseDeliverTx{
528522
Code: uint32(result.Code),
523+
Codespace: string(result.Codespace),
529524
Data: result.Data,
530525
Log: result.Log,
531526
GasWanted: result.GasWanted,
@@ -545,7 +540,6 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error {
545540
// Validate the Msg.
546541
err := msg.ValidateBasic()
547542
if err != nil {
548-
err = err.WithDefaultCodespace(sdk.CodespaceRoot)
549543
return err
550544
}
551545
}
@@ -574,7 +568,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (re
574568
logs := make([]string, 0, len(msgs))
575569
var data []byte // NOTE: we just append them all (?!)
576570
var tags sdk.Tags // also just append them all
577-
var code sdk.ABCICodeType
571+
var code sdk.CodeType
572+
var codespace sdk.CodespaceType
578573
for msgIdx, msg := range msgs {
579574
// Match route.
580575
msgRoute := msg.Route()
@@ -601,6 +596,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (re
601596
if !msgResult.IsOK() {
602597
logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log))
603598
code = msgResult.Code
599+
codespace = msgResult.Codespace
604600
break
605601
}
606602

@@ -610,10 +606,11 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (re
610606

611607
// Set the final gas values.
612608
result = sdk.Result{
613-
Code: code,
614-
Data: data,
615-
Log: strings.Join(logs, "\n"),
616-
GasUsed: ctx.GasMeter().GasConsumed(),
609+
Code: code,
610+
Codespace: codespace,
611+
Data: data,
612+
Log: strings.Join(logs, "\n"),
613+
GasUsed: ctx.GasMeter().GasConsumed(),
617614
// TODO: FeeAmount/FeeDenom
618615
Tags: tags,
619616
}

client/clitest/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ func copyFile(dstFile, srcFile string) error {
208208
// helper methods
209209

210210
func initializeFixtures(t *testing.T) (chainID, servAddr, port string) {
211-
tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe-reset-all", irisHome), "")
211+
tests.ExecuteT(t, fmt.Sprintf("rm -rf %s ", irisHome), "")
212+
//tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe-reset-all", irisHome), "")
212213
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s foo", iriscliHome), app.DefaultKeyPass)
213214
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s bar", iriscliHome), app.DefaultKeyPass)
214215
executeWrite(t, fmt.Sprintf("iriscli keys add --home=%s foo", iriscliHome), app.DefaultKeyPass)

client/utils/rest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type kvPair struct {
3737
TagValue string `json:"tag_value"`
3838
}
3939
type abciResult struct {
40-
Code sdk.ABCICodeType `json:"code"`
40+
Code sdk.CodeType `json:"code"`
4141
Data []byte `json:"data"`
4242
Log string `json:"log"`
4343
GasWanted int64 `json:"gas_wanted"`

cmd/iristool/debug/hack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,21 @@ func NewIrisApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
192192
app.cdc,
193193
app.keyStake, app.tkeyStake,
194194
app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace),
195-
app.RegisterCodespace(stake.DefaultCodespace),
195+
stake.DefaultCodespace,
196196
)
197197
app.slashingKeeper = slashing.NewKeeper(
198198
app.cdc,
199199
app.keySlashing,
200200
app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
201-
app.RegisterCodespace(slashing.DefaultCodespace),
201+
slashing.DefaultCodespace,
202202
)
203203
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
204204
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper)
205205
app.govKeeper = gov.NewKeeper(
206206
app.cdc,
207207
app.keyGov,
208208
app.bankKeeper, app.stakeKeeper,
209-
app.RegisterCodespace(gov.DefaultCodespace),
209+
gov.DefaultCodespace,
210210
)
211211
// register message routes
212212
app.Router().

modules/auth/ante_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ func privAndAddr() (crypto.PrivKey, sdk.AccAddress) {
4242
func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool) {
4343
_, result, abort := anteHandler(ctx, tx, simulate)
4444
require.False(t, abort)
45-
require.Equal(t, sdk.ABCICodeOK, result.Code)
45+
require.Equal(t, sdk.CodeOK, result.Code)
4646
require.True(t, result.IsOK())
4747
}
4848

4949
// run the tx through the anteHandler and ensure it fails with the given code
5050
func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool, code sdk.CodeType) {
5151
newCtx, result, abort := anteHandler(ctx, tx, simulate)
5252
require.True(t, abort)
53-
require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, code), result.Code,
54-
fmt.Sprintf("Expected %v, got %v", sdk.ToABCICode(sdk.CodespaceRoot, code), result))
53+
require.Equal(t, code, result.Code, fmt.Sprintf("Expected %v, got %v", code, result))
54+
require.Equal(t, sdk.CodespaceRoot, result.Codespace)
5555

5656
if code == sdk.CodeOutOfGas {
5757
stdTx, ok := tx.(StdTx)

modules/bank/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// Bank errors reserve 100 ~ 199.
99
const (
10-
DefaultCodespace sdk.CodespaceType = 2
10+
DefaultCodespace sdk.CodespaceType = "bank"
1111

1212
CodeInvalidInput sdk.CodeType = 101
1313
CodeInvalidOutput sdk.CodeType = 102

modules/distribution/types/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type CodeType = sdk.CodeType
99

1010
const (
11-
DefaultCodespace sdk.CodespaceType = 6
11+
DefaultCodespace sdk.CodespaceType = "distr"
1212
CodeInvalidInput CodeType = 103
1313
CodeNoDistributionInfo CodeType = 104
1414
)

modules/distribution/types/msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var _, _ sdk.Msg = &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorRewardsAl
1717
// msg struct for changing the withdraw address for a delegator (or validator self-delegation)
1818
type MsgSetWithdrawAddress struct {
1919
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
20-
WithdrawAddr sdk.AccAddress `json:"delegator_addr"`
20+
WithdrawAddr sdk.AccAddress `json:"withdraw_addr"`
2121
}
2222

2323
func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {

modules/gov/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
const (
11-
DefaultCodespace sdk.CodespaceType = 21
11+
DefaultCodespace sdk.CodespaceType = "gov"
1212

1313
CodeUnknownProposal sdk.CodeType = 1
1414
CodeInactiveProposal sdk.CodeType = 2

modules/gov/simulation/sim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestGovWithRandomMessages(t *testing.T) {
3939
mapp.Cdc,
4040
govKey,
4141
bankKeeper, stakeKeeper,
42-
mapp.RegisterCodespace(gov.DefaultCodespace),
42+
gov.DefaultCodespace,
4343
)
4444

4545
mapp.Router().AddRoute("gov", []*sdk.KVStoreKey{govKey, mapp.KeyAccount, stakeKey, paramKey}, gov.NewHandler(govKeeper))

modules/gov/test_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper,
3434
mapp.Cdc,
3535
mapp.KeyStake, mapp.TkeyStake,
3636
mapp.BankKeeper, mapp.ParamsKeeper.Subspace(stake.DefaultParamspace),
37-
mapp.RegisterCodespace(stake.DefaultCodespace))
37+
stake.DefaultCodespace)
3838
gk := NewKeeper(mapp.Cdc, keyGov, ck, sk, DefaultCodespace)
3939

4040
mapp.Router().AddRoute("gov", []*sdk.KVStoreKey{keyGov}, NewHandler(gk))

modules/guardian/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
const (
9-
DefaultCodespace sdk.CodespaceType = 25
9+
DefaultCodespace sdk.CodespaceType = "guardian"
1010

1111
CodeProfilerExists sdk.CodeType = 100
1212
CodeProfilerNotExists sdk.CodeType = 101

modules/mock/app_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ func TestMsgSendWithAccounts(t *testing.T) {
143143
tx.Signatures[0].Sequence = 1
144144

145145
res := mapp.Deliver(tx)
146-
require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
146+
require.Equal(t, sdk.CodeUnauthorized, res.Code, res.Log)
147+
require.Equal(t, sdk.CodespaceRoot, res.Codespace)
147148

148149
// resigning the tx with the bumped sequence should work
149150
SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []int64{0}, []int64{1}, true, true, priv1)

modules/mock/test_utils.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func CheckGenTx(
5858
res := app.Check(tx)
5959

6060
if expPass {
61-
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
61+
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
6262
} else {
63-
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
63+
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
6464
}
6565

6666
return res
@@ -79,19 +79,19 @@ func SignCheckDeliver(
7979
res := app.Simulate(tx)
8080

8181
if expSimPass {
82-
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
82+
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
8383
} else {
84-
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
84+
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
8585
}
8686

8787
// Simulate a sending a transaction and committing a block
8888
app.BeginBlock(abci.RequestBeginBlock{})
8989
res = app.Deliver(tx)
9090

9191
if expPass {
92-
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
92+
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
9393
} else {
94-
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
94+
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
9595
}
9696

9797
app.EndBlock(abci.RequestEndBlock{})

modules/params/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
const (
8-
DefaultCodespace sdk.CodespaceType = 20
8+
DefaultCodespace sdk.CodespaceType = "params"
99
CodeInvalidMinDeposit sdk.CodeType = 100
1010
CodeInvalidMinDepositDenom sdk.CodeType = 101
1111
CodeInvalidMinDepositAmount sdk.CodeType = 102

modules/record/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
const (
11-
DefaultCodespace sdk.CodespaceType = 22
11+
DefaultCodespace sdk.CodespaceType = "record"
1212

1313
CodeInvalidDataSize sdk.CodeType = 1
1414
CodeInvalidFileDescription sdk.CodeType = 2

0 commit comments

Comments
 (0)