Skip to content

Commit

Permalink
Merge branch 'master' into cyberbono3/8529-add-client-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia authored Mar 24, 2021
2 parents 287ece2 + 8ee9da7 commit a889d7e
Show file tree
Hide file tree
Showing 24 changed files with 1,318 additions and 1,312 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#8849](https://github.com/cosmos/cosmos-sdk/pull/8849) Upgrade module no longer supports time based upgrades.
* [\#8880](https://github.com/cosmos/cosmos-sdk/pull/8880) The CLI `simd migrate v0.40 ...` command has been renamed to `simd migrate v0.42`.


### API Breaking Changes

* (keyring) [#\8662](https://github.com/cosmos/cosmos-sdk/pull/8662) `NewMnemonic` now receives an additional `passphrase` argument to secure the key generated by the bip39 mnemonic.
Expand All @@ -67,7 +66,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error.
* [\#8682](https://github.com/cosmos/cosmos-sdk/pull/8682) `ante.NewAnteHandler` updated to receive all positional params as `ante.HandlerOptions` struct. If required fields aren't set, throws error accordingly.


### State Machine Breaking

* (x/{bank,distrib,gov,slashing,staking}) [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Store keys have been modified to allow for variable-length addresses.
Expand All @@ -84,6 +82,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.
* (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) Add tracking module versions as per ADR-041
* (types) [\#8962](https://github.com/cosmos/cosmos-sdk/issues/8962) Add `Abs()` method to `sdk.Int`.

### Bug Fixes

Expand Down
4 changes: 2 additions & 2 deletions docs/architecture/adr-003-dynamic-capability-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

## Context

Full implementation of the [IBC specification](https://github.com/cosmos/ics) requires the ability to create and authenticate object-capability keys at runtime (i.e., during transaction execution),
as described in [ICS 5](https://github.com/cosmos/ics/tree/master/spec/ics-005-port-allocation#technical-specification). In the IBC specification, capability keys are created for each newly initialised
Full implementation of the [IBC specification](https://github.com/cosmos/ibs) requires the ability to create and authenticate object-capability keys at runtime (i.e., during transaction execution),
as described in [ICS 5](https://github.com/cosmos/ibc/tree/master/spec/core/ics-005-port-allocation#technical-specification). In the IBC specification, capability keys are created for each newly initialised
port & channel, and are used to authenticate future usage of the port or channel. Since channels and potentially ports can be initialised during transaction execution, the state machine must be able to create
object-capability keys at this time.

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-015-ibc-packet-receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Context

[ICS 26 - Routing Module](https://github.com/cosmos/ics/tree/master/spec/ics-026-routing-module) defines a function [`handlePacketRecv`](https://github.com/cosmos/ics/tree/master/spec/ics-026-routing-module#packet-relay).
[ICS 26 - Routing Module](https://github.com/cosmos/ibc/tree/master/spec/core/ics-026-routing-module) defines a function [`handlePacketRecv`](https://github.com/cosmos/ibc/tree/master/spec/core/ics-026-routing-module#packet-relay).

In ICS 26, the routing module is defined as a layer above each application module
which verifies and routes messages to the destination modules. It is possible to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ We elect not to deal with chains which have actually halted, which is necessaril

Note that clients frozen due to misbehaviour must wait for the evidence to expire to avoid becoming refrozen.

This ADR does not address planned upgrades, which are handled separately as per the [specification](https://github.com/cosmos/ics/tree/master/spec/ics-007-tendermint-client#upgrades).
This ADR does not address planned upgrades, which are handled separately as per the [specification](https://github.com/cosmos/ibc/tree/master/spec/client/ics-007-tendermint-client#upgrades).

## Consequences

Expand Down
2,416 changes: 1,187 additions & 1,229 deletions docs/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"vuepress-theme-cosmos": "^1.0.180"
"vuepress-theme-cosmos": "^1.0.181"
}
}
26 changes: 22 additions & 4 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,30 @@ func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

// FundAccount is a utility function that funds an account by minting and sending the coins to the address
// TODO(fdymylja): instead of using the mint module account, which has the permission of minting, create a "faucet" account
// FundAccount is a utility function that funds an account by minting and
// sending the coins to the address. This should be used for testing purposes
// only!
//
// TODO: Instead of using the mint module account, which has the
// permission of minting, create a "faucet" account. (@fdymylja)
func FundAccount(app *SimApp, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error {
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts)
if err != nil {
if err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
}

// FundModuleAccount is a utility function that funds a module account by
// minting and sending the coins to the address. This should be used for testing
// purposes only!
//
// TODO: Instead of using the mint module account, which has the
// permission of minting, create a "faucet" account. (@fdymylja)
func FundModuleAccount(app *SimApp, ctx sdk.Context, recipientMod string, amounts sdk.Coins) error {
if err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts)
}
7 changes: 7 additions & 0 deletions types/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func mod(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mod(i, i2) }

func neg(i *big.Int) *big.Int { return new(big.Int).Neg(i) }

func abs(i *big.Int) *big.Int { return new(big.Int).Abs(i) }

func min(i *big.Int, i2 *big.Int) *big.Int {
if i.Cmp(i2) == 1 {
return new(big.Int).Set(i2)
Expand Down Expand Up @@ -304,6 +306,11 @@ func (i Int) Neg() (res Int) {
return Int{neg(i.i)}
}

// Abs returns the absolute value of Int.
func (i Int) Abs() Int {
return Int{abs(i.i)}
}

// return the minimum of the ints
func MinInt(i1, i2 Int) Int {
return Int{min(i1.BigInt(), i2.BigInt())}
Expand Down
3 changes: 3 additions & 0 deletions types/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (s *intTestSuite) TestArithInt() {
{sdk.MinInt(i1, i2), minint(n1, n2)},
{sdk.MaxInt(i1, i2), maxint(n1, n2)},
{i1.Neg(), -n1},
{i1.Abs(), n1},
{i1.Neg().Abs(), n1},
}

for tcnum, tc := range cases {
Expand Down Expand Up @@ -206,6 +208,7 @@ func (s *intTestSuite) TestImmutabilityAllInt() {
func(i *sdk.Int) { _ = i.MulRaw(rand.Int63()) },
func(i *sdk.Int) { _ = i.QuoRaw(rand.Int63()) },
func(i *sdk.Int) { _ = i.Neg() },
func(i *sdk.Int) { _ = i.Abs() },
func(i *sdk.Int) { _ = i.IsZero() },
func(i *sdk.Int) { _ = i.Sign() },
func(i *sdk.Int) { _ = i.Equal(randint()) },
Expand Down
6 changes: 3 additions & 3 deletions x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ func (suite *IntegrationTestSuite) TestExportGenesis() {

func (suite *IntegrationTestSuite) getTestBalancesAndSupply() ([]types.Balance, sdk.Coins) {
addr2, _ := sdk.AccAddressFromBech32("cosmos1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0556gh0")
addr1, _ := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh")
addr1, _ := sdk.AccAddressFromBech32("cosmos1t5u0jfg3ljsjrh2m9e47d4ny2hea7eehxrzdgd")
addr1Balance := sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)}
addr2Balance := sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)}

totalSupply := addr1Balance
totalSupply = totalSupply.Add(addr2Balance...)

return []types.Balance{
{Address: addr2.String(), Coins: addr2Balance},
{Address: addr1.String(), Coins: addr1Balance},
}, totalSupply

}

func (suite *IntegrationTestSuite) TestInitGenesis() {
Expand All @@ -70,7 +70,7 @@ func (suite *IntegrationTestSuite) TestTotalSupply() {
defaultGenesis := types.DefaultGenesisState()
balances := []types.Balance{
{Coins: sdk.NewCoins(sdk.NewCoin("foocoin", sdk.NewInt(1))), Address: "cosmos1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0556gh0"},
{Coins: sdk.NewCoins(sdk.NewCoin("barcoin", sdk.NewInt(1))), Address: "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"},
{Coins: sdk.NewCoins(sdk.NewCoin("barcoin", sdk.NewInt(1))), Address: "cosmos1t5u0jfg3ljsjrh2m9e47d4ny2hea7eehxrzdgd"},
{Coins: sdk.NewCoins(sdk.NewCoin("foocoin", sdk.NewInt(10)), sdk.NewCoin("barcoin", sdk.NewInt(20))), Address: "cosmos1m3h30wlvsf8llruxtpukdvsy0km2kum8g38c8q"},
}
totalSupply := sdk.NewCoins(sdk.NewCoin("foocoin", sdk.NewInt(11)), sdk.NewCoin("barcoin", sdk.NewInt(21)))
Expand Down
7 changes: 6 additions & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metada
}

// SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress.
// It will panic if the module account does not exist.
// It will panic if the module account does not exist. An error is returned if
// the recipient address is black-listed or if sending the tokens fails.
func (k BaseKeeper) SendCoinsFromModuleToAccount(
ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error {
Expand All @@ -278,6 +279,10 @@ func (k BaseKeeper) SendCoinsFromModuleToAccount(
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule))
}

if k.BlockedAddr(recipientAddr) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr)
}

return k.SendCoins(ctx, senderAddr, recipientAddr, amt)
}

Expand Down
30 changes: 30 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ func (suite *IntegrationTestSuite) TestSupply() {
suite.Require().Equal(totalSupply, total)
}

func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blacklist() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
appCodec := app.AppCodec()

// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[authtypes.Burner] = []string{authtypes.Burner}
maccPerms[authtypes.Minter] = []string{authtypes.Minter}
maccPerms[multiPerm] = []string{authtypes.Burner, authtypes.Minter, authtypes.Staking}
maccPerms[randomPerm] = []string{"random"}

addr1 := sdk.AccAddress([]byte("addr1_______________"))

authKeeper := authkeeper.NewAccountKeeper(
appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName),
authtypes.ProtoBaseAccount, maccPerms,
)
keeper := keeper.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), authKeeper,
app.GetSubspace(types.ModuleName), map[string]bool{addr1.String(): true},
)

suite.Require().NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins))
suite.Require().Error(keeper.SendCoinsFromModuleToAccount(
ctx, minttypes.ModuleName, addr1, initCoins,
))
}

func (suite *IntegrationTestSuite) TestSupply_SendCoins() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
require.NotNil(t, feeCollector)

// fund fee collector
require.NoError(t, simapp.FundAccount(app, ctx, feeCollector.GetAddress(), fees))
require.NoError(t, simapp.FundModuleAccount(app, ctx, feeCollector.GetName(), fees))

app.AccountKeeper.SetAccount(ctx, feeCollector)

Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
feeCollector := app.AccountKeeper.GetModuleAccount(ctx, types.FeeCollectorName)
require.NotNil(t, feeCollector)

require.NoError(t, simapp.FundAccount(app, ctx, feeCollector.GetAddress(), fees))
require.NoError(t, simapp.FundModuleAccount(app, ctx, feeCollector.GetName(), fees))

app.AccountKeeper.SetAccount(ctx, feeCollector)

Expand Down
4 changes: 2 additions & 2 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {

// set module account coins
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
require.NoError(t, simapp.FundAccount(app, ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, balanceTokens))))
require.NoError(t, simapp.FundModuleAccount(app, ctx, distrAcc.GetName(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, balanceTokens))))
app.AccountKeeper.SetModuleAccount(ctx, distrAcc)

// create validator with 50% commission
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {

// set module account coins
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
require.NoError(t, simapp.FundAccount(app, ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)))))
require.NoError(t, simapp.FundModuleAccount(app, ctx, distrAcc.GetName(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)))))
app.AccountKeeper.SetModuleAccount(ctx, distrAcc)

tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestWithdrawValidatorCommission(t *testing.T) {
// set module account coins
distrAcc := app.DistrKeeper.GetDistributionAccount(ctx)
coins := sdk.NewCoins(sdk.NewCoin("mytoken", sdk.NewInt(2)), sdk.NewCoin("stake", sdk.NewInt(2)))
require.NoError(t, simapp.FundAccount(app, ctx, distrAcc.GetAddress(), coins))
require.NoError(t, simapp.FundModuleAccount(app, ctx, distrAcc.GetName(), coins))

app.AccountKeeper.SetModuleAccount(ctx, distrAcc)

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestProposalHandlerPassed(t *testing.T) {
// add coins to the module account
macc := app.DistrKeeper.GetDistributionAccount(ctx)
balances := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress())
require.NoError(t, simapp.FundAccount(app, ctx, macc.GetAddress(), amount))
require.NoError(t, simapp.FundModuleAccount(app, ctx, macc.GetName(), amount))

app.AccountKeeper.SetModuleAccount(ctx, macc)

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName

// set module account coins
distrAcc := suite.app.DistrKeeper.GetDistributionAccount(suite.ctx)
suite.Require().NoError(simapp.FundAccount(suite.app, suite.ctx, distrAcc.GetAddress(), sdk.NewCoins(
suite.Require().NoError(simapp.FundModuleAccount(suite.app, suite.ctx, distrAcc.GetName(), sdk.NewCoins(
sdk.NewCoin(tokenName, sdk.NewInt(10)),
sdk.NewCoin("stake", sdk.NewInt(5)),
)))
Expand Down
3 changes: 0 additions & 3 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ func CollectTxs(cdc codec.JSONMarshaler, txJSONDecoder sdk.TxDecoder, moniker, g

// genesis transactions must be single-message
msgs := genTx.GetMsgs()
if len(msgs) != 1 {
return appGenTxs, persistentPeers, errors.New("each genesis transaction must provide a single genesis message")
}

// TODO abstract out staking message validation back to staking
msg := msgs[0].(*stakingtypes.MsgCreateValidator)
Expand Down
21 changes: 8 additions & 13 deletions x/staking/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"log"
"testing"

auth "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -66,15 +64,12 @@ func TestInitGenesis(t *testing.T) {
log.Printf("%#v", len(validators))
// mint coins in the bonded pool representing the validators coins
require.NoError(t,
simapp.FundAccount(
simapp.FundModuleAccount(
app,
ctx,
auth.NewModuleAddress(types.BondedPoolName),
types.BondedPoolName,
sdk.NewCoins(
sdk.NewCoin(
params.BondDenom,
valTokens.MulRaw((int64)(len(validators))),
),
sdk.NewCoin(params.BondDenom, valTokens.MulRaw((int64)(len(validators)))),
),
),
)
Expand Down Expand Up @@ -182,16 +177,16 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
// add bonded coins
bondedPoolAmt = bondedPoolAmt.Add(tokens)
}

genesisState := types.NewGenesisState(params, validators, delegations)

// mint coins in the bonded pool representing the validators coins
require.NoError(t,
simapp.FundAccount(
simapp.FundModuleAccount(
app,
ctx,
auth.NewModuleAddress(types.BondedPoolName),
sdk.NewCoins(
sdk.NewCoin(params.BondDenom, bondedPoolAmt),
),
types.BondedPoolName,
sdk.NewCoins(sdk.NewCoin(params.BondDenom, bondedPoolAmt)),
),
)

Expand Down
2 changes: 1 addition & 1 deletion x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmo

// set non bonded pool balance
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
require.NoError(t, simapp.FundAccount(app, ctx, notBondedPool.GetAddress(), totalSupply))
require.NoError(t, simapp.FundModuleAccount(app, ctx, notBondedPool.GetName(), totalSupply))
return app, ctx, addrDels, addrVals
}

Expand Down
Loading

0 comments on commit a889d7e

Please sign in to comment.