Skip to content

Commit

Permalink
Merge pull request #779 from HaoyangLiu/haoyang/develop
Browse files Browse the repository at this point in the history
R4R: Merge PRs from cosmos-sdk 0.27
  • Loading branch information
HaoyangLiu authored Dec 6, 2018
2 parents 9067358 + b11d235 commit 51a288f
Show file tree
Hide file tree
Showing 35 changed files with 112 additions and 203 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ RUN cd $REPO_PATH && \
make get_vendor_deps && \
make test_unit && \
make build_linux && \
make install
make install && \
make test_cli

FROM alpine:3.7

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation' | grep -v '/prometheus' | grep -v '/clitest' | grep -v '/lcd' | grep -v '/protobuf')
PACKAGES_MODULES=$(shell go list ./... | grep 'modules')
PACKAGES_TYPES=$(shell go list ./... | grep 'types')
PACKAGES_TYPES=$(shell go list ./... | grep 'irisnet/irishub/types')
PACKAGES_STORE=$(shell go list ./... | grep 'irisnet/irishub/store')
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')

all: get_tools get_vendor_deps install
Expand Down Expand Up @@ -74,7 +75,7 @@ install: update_irislcd_swagger_docs echo_bech32_prefix
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/iriscli
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/irislcd
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/iristool
go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/newiris
# go install $(INSTALL_FLAGS) $(BUILD_FLAGS) ./cmd/newiris

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

test_cli:
@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
Expand Down
13 changes: 8 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode)
logs := make([]string, 0, len(msgs))
var data []byte // NOTE: we just append them all (?!)
var tags sdk.Tags // also just append them all
var code sdk.ABCICodeType
var code sdk.CodeType
var codespace sdk.CodespaceType
for msgIdx, msg := range msgs {
// Match route.
var msgType string
Expand Down Expand Up @@ -503,6 +504,7 @@ func (app *IrisApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode bam.RunTxMode)
if !msgResult.IsOK() {
logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log))
code = msgResult.Code
codespace = msgResult.Codespace
break
}

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

// Set the final gas values.
result = sdk.Result{
Code: code,
Data: data,
Log: strings.Join(logs, "\n"),
GasUsed: ctx.GasMeter().GasConsumed(),
Code: code,
Codespace: codespace,
Data: data,
Log: strings.Join(logs, "\n"),
GasUsed: ctx.GasMeter().GasConsumed(),
// TODO: FeeAmount/FeeDenom
Tags: tags,
}
Expand Down
43 changes: 20 additions & 23 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type BaseApp struct {
cms sdk.CommitMultiStore // Main (uncached) state
router Router // handle any kind of message
queryRouter QueryRouter // router for redirecting query calls
codespacer *sdk.Codespacer // handle module codespacing
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx

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

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

// Register the next available codespace through the baseapp's codespacer, starting from a default
func (app *BaseApp) RegisterCodespace(codespace sdk.CodespaceType) sdk.CodespaceType {
return app.codespacer.RegisterNext(codespace)
}

// Mount IAVL stores to the provided keys in the BaseApp multistore
func (app *BaseApp) MountStoresIAVL(keys ...*sdk.KVStoreKey) {
for _, key := range keys {
Expand Down Expand Up @@ -345,8 +335,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
}
case "version":
return abci.ResponseQuery{
Code: uint32(sdk.ABCICodeOK),
Value: []byte(version.GetVersion()),
Code: uint32(sdk.CodeOK),
Codespace: string(sdk.CodespaceRoot),
Value: []byte(version.GetVersion()),
}
default:
result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result()
Expand All @@ -355,8 +346,9 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
// Encode with json
value := codec.Cdc.MustMarshalBinaryLengthPrefixed(result)
return abci.ResponseQuery{
Code: uint32(sdk.ABCICodeOK),
Value: value,
Code: uint32(sdk.CodeOK),
Codespace: string(sdk.CodespaceRoot),
Value: value,
}
}
msg := "Expected second parameter to be either simulate or version, neither was present"
Expand Down Expand Up @@ -415,12 +407,13 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
resBytes, err := querier(ctx, path[2:], req)
if err != nil {
return abci.ResponseQuery{
Code: uint32(err.ABCICode()),
Log: err.ABCILog(),
Code: uint32(err.Code()),
Codespace: string(err.Codespace()),
Log: err.ABCILog(),
}
}
return abci.ResponseQuery{
Code: uint32(sdk.ABCICodeOK),
Code: uint32(sdk.CodeOK),
Value: resBytes,
}
}
Expand Down Expand Up @@ -478,6 +471,7 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {

return abci.ResponseCheckTx{
Code: uint32(result.Code),
Codespace: string(result.Codespace),
Data: result.Data,
Log: result.Log,
GasWanted: result.GasWanted,
Expand Down Expand Up @@ -526,6 +520,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
// Tell the blockchain engine (i.e. Tendermint).
return abci.ResponseDeliverTx{
Code: uint32(result.Code),
Codespace: string(result.Codespace),
Data: result.Data,
Log: result.Log,
GasWanted: result.GasWanted,
Expand All @@ -545,7 +540,6 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error {
// Validate the Msg.
err := msg.ValidateBasic()
if err != nil {
err = err.WithDefaultCodespace(sdk.CodespaceRoot)
return err
}
}
Expand Down Expand Up @@ -574,7 +568,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (re
logs := make([]string, 0, len(msgs))
var data []byte // NOTE: we just append them all (?!)
var tags sdk.Tags // also just append them all
var code sdk.ABCICodeType
var code sdk.CodeType
var codespace sdk.CodespaceType
for msgIdx, msg := range msgs {
// Match route.
msgRoute := msg.Route()
Expand All @@ -601,6 +596,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode RunTxMode) (re
if !msgResult.IsOK() {
logs = append(logs, fmt.Sprintf("Msg %d failed: %s", msgIdx, msgResult.Log))
code = msgResult.Code
codespace = msgResult.Codespace
break
}

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

// Set the final gas values.
result = sdk.Result{
Code: code,
Data: data,
Log: strings.Join(logs, "\n"),
GasUsed: ctx.GasMeter().GasConsumed(),
Code: code,
Codespace: codespace,
Data: data,
Log: strings.Join(logs, "\n"),
GasUsed: ctx.GasMeter().GasConsumed(),
// TODO: FeeAmount/FeeDenom
Tags: tags,
}
Expand Down
3 changes: 2 additions & 1 deletion client/clitest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func copyFile(dstFile, srcFile string) error {
// helper methods

func initializeFixtures(t *testing.T) (chainID, servAddr, port string) {
tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe-reset-all", irisHome), "")
tests.ExecuteT(t, fmt.Sprintf("rm -rf %s ", irisHome), "")
//tests.ExecuteT(t, fmt.Sprintf("iris --home=%s unsafe-reset-all", irisHome), "")
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s foo", iriscliHome), app.DefaultKeyPass)
executeWrite(t, fmt.Sprintf("iriscli keys delete --home=%s bar", iriscliHome), app.DefaultKeyPass)
executeWrite(t, fmt.Sprintf("iriscli keys add --home=%s foo", iriscliHome), app.DefaultKeyPass)
Expand Down
2 changes: 1 addition & 1 deletion client/utils/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type kvPair struct {
TagValue string `json:"tag_value"`
}
type abciResult struct {
Code sdk.ABCICodeType `json:"code"`
Code sdk.CodeType `json:"code"`
Data []byte `json:"data"`
Log string `json:"log"`
GasWanted int64 `json:"gas_wanted"`
Expand Down
6 changes: 3 additions & 3 deletions cmd/iristool/debug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,21 @@ func NewIrisApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
app.cdc,
app.keyStake, app.tkeyStake,
app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace),
app.RegisterCodespace(stake.DefaultCodespace),
stake.DefaultCodespace,
)
app.slashingKeeper = slashing.NewKeeper(
app.cdc,
app.keySlashing,
app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
app.RegisterCodespace(slashing.DefaultCodespace),
slashing.DefaultCodespace,
)
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper)
app.govKeeper = gov.NewKeeper(
app.cdc,
app.keyGov,
app.bankKeeper, app.stakeKeeper,
app.RegisterCodespace(gov.DefaultCodespace),
gov.DefaultCodespace,
)
// register message routes
app.Router().
Expand Down
6 changes: 3 additions & 3 deletions modules/auth/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ func privAndAddr() (crypto.PrivKey, sdk.AccAddress) {
func checkValidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, tx sdk.Tx, simulate bool) {
_, result, abort := anteHandler(ctx, tx, simulate)
require.False(t, abort)
require.Equal(t, sdk.ABCICodeOK, result.Code)
require.Equal(t, sdk.CodeOK, result.Code)
require.True(t, result.IsOK())
}

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

if code == sdk.CodeOutOfGas {
stdTx, ok := tx.(StdTx)
Expand Down
2 changes: 1 addition & 1 deletion modules/bank/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Bank errors reserve 100 ~ 199.
const (
DefaultCodespace sdk.CodespaceType = 2
DefaultCodespace sdk.CodespaceType = "bank"

CodeInvalidInput sdk.CodeType = 101
CodeInvalidOutput sdk.CodeType = 102
Expand Down
2 changes: 1 addition & 1 deletion modules/distribution/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type CodeType = sdk.CodeType

const (
DefaultCodespace sdk.CodespaceType = 6
DefaultCodespace sdk.CodespaceType = "distr"
CodeInvalidInput CodeType = 103
CodeNoDistributionInfo CodeType = 104
)
Expand Down
2 changes: 1 addition & 1 deletion modules/distribution/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _, _ sdk.Msg = &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorRewardsAl
// msg struct for changing the withdraw address for a delegator (or validator self-delegation)
type MsgSetWithdrawAddress struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
WithdrawAddr sdk.AccAddress `json:"delegator_addr"`
WithdrawAddr sdk.AccAddress `json:"withdraw_addr"`
}

func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) MsgSetWithdrawAddress {
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
DefaultCodespace sdk.CodespaceType = 21
DefaultCodespace sdk.CodespaceType = "gov"

CodeUnknownProposal sdk.CodeType = 1
CodeInactiveProposal sdk.CodeType = 2
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/simulation/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGovWithRandomMessages(t *testing.T) {
mapp.Cdc,
govKey,
bankKeeper, stakeKeeper,
mapp.RegisterCodespace(gov.DefaultCodespace),
gov.DefaultCodespace,
)

mapp.Router().AddRoute("gov", []*sdk.KVStoreKey{govKey, mapp.KeyAccount, stakeKey, paramKey}, gov.NewHandler(govKeeper))
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper,
mapp.Cdc,
mapp.KeyStake, mapp.TkeyStake,
mapp.BankKeeper, mapp.ParamsKeeper.Subspace(stake.DefaultParamspace),
mapp.RegisterCodespace(stake.DefaultCodespace))
stake.DefaultCodespace)
gk := NewKeeper(mapp.Cdc, keyGov, ck, sk, DefaultCodespace)

mapp.Router().AddRoute("gov", []*sdk.KVStoreKey{keyGov}, NewHandler(gk))
Expand Down
2 changes: 1 addition & 1 deletion modules/guardian/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

const (
DefaultCodespace sdk.CodespaceType = 25
DefaultCodespace sdk.CodespaceType = "guardian"

CodeProfilerExists sdk.CodeType = 100
CodeProfilerNotExists sdk.CodeType = 101
Expand Down
3 changes: 2 additions & 1 deletion modules/mock/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func TestMsgSendWithAccounts(t *testing.T) {
tx.Signatures[0].Sequence = 1

res := mapp.Deliver(tx)
require.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
require.Equal(t, sdk.CodeUnauthorized, res.Code, res.Log)
require.Equal(t, sdk.CodespaceRoot, res.Codespace)

// resigning the tx with the bumped sequence should work
SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []int64{0}, []int64{1}, true, true, priv1)
Expand Down
12 changes: 6 additions & 6 deletions modules/mock/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func CheckGenTx(
res := app.Check(tx)

if expPass {
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
} else {
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
}

return res
Expand All @@ -79,19 +79,19 @@ func SignCheckDeliver(
res := app.Simulate(tx)

if expSimPass {
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
} else {
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
}

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

if expPass {
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
require.Equal(t, sdk.CodeOK, res.Code, res.Log)
} else {
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
require.NotEqual(t, sdk.CodeOK, res.Code, res.Log)
}

app.EndBlock(abci.RequestEndBlock{})
Expand Down
2 changes: 1 addition & 1 deletion modules/params/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

const (
DefaultCodespace sdk.CodespaceType = 20
DefaultCodespace sdk.CodespaceType = "params"
CodeInvalidMinDeposit sdk.CodeType = 100
CodeInvalidMinDepositDenom sdk.CodeType = 101
CodeInvalidMinDepositAmount sdk.CodeType = 102
Expand Down
2 changes: 1 addition & 1 deletion modules/record/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
DefaultCodespace sdk.CodespaceType = 22
DefaultCodespace sdk.CodespaceType = "record"

CodeInvalidDataSize sdk.CodeType = 1
CodeInvalidFileDescription sdk.CodeType = 2
Expand Down
Loading

0 comments on commit 51a288f

Please sign in to comment.