update x/genaccounts to match module spec (#4759)

This commit is contained in:
Federico Kunze 2019-07-22 17:26:42 +02:00 committed by Alessio Treglia
parent bbb7113309
commit e85a734a57
55 changed files with 237 additions and 189 deletions

View File

@ -0,0 +1 @@
#4758 update `x/genaccounts` to match module spec

View File

@ -7,6 +7,8 @@ import (
"fmt"
"sort"
bip39 "github.com/bartekn/go-bip39"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/keys"
@ -15,8 +17,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/go-bip39"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/libs/cli"

View File

@ -4,8 +4,9 @@ import (
"bufio"
"io/ioutil"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/input"
)
func importKeyCommand() *cobra.Command {

View File

@ -1,8 +1,9 @@
package keys
import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/flags"
)
func listKeysCmd() *cobra.Command {

View File

@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/libs/bech32"
"github.com/tendermint/tendermint/libs/cli"

View File

@ -8,7 +8,7 @@ import (
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"

1
go.mod
View File

@ -9,7 +9,6 @@ require (
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/gogo/protobuf v1.2.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
github.com/golang/protobuf v1.3.0
github.com/gorilla/mux v1.7.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.6

View File

@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/libs/cli"

View File

@ -14,10 +14,11 @@ import (
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/cosmos/cosmos-sdk/codec"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmtypes "github.com/tendermint/tendermint/types"

View File

@ -9,10 +9,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/distribution"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
@ -52,37 +53,37 @@ func TestGetSimulationLog(t *testing.T) {
kvPairs []cmn.KVPair
}{
{auth.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: auth.AddressStoreKey(delAddr1), Value: cdc.MustMarshalBinaryBare(auth.BaseAccount{})},
cmn.KVPair{Key: auth.AddressStoreKey(delAddr1), Value: cdc.MustMarshalBinaryBare(auth.BaseAccount{})},
{Key: auth.AddressStoreKey(delAddr1), Value: cdc.MustMarshalBinaryBare(auth.BaseAccount{})},
{Key: auth.AddressStoreKey(delAddr1), Value: cdc.MustMarshalBinaryBare(auth.BaseAccount{})},
}},
{mint.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: mint.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(mint.Minter{})},
cmn.KVPair{Key: mint.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(mint.Minter{})},
{Key: mint.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(mint.Minter{})},
{Key: mint.MinterKey, Value: cdc.MustMarshalBinaryLengthPrefixed(mint.Minter{})},
}},
{staking.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: staking.LastValidatorPowerKey, Value: valAddr1.Bytes()},
cmn.KVPair{Key: staking.LastValidatorPowerKey, Value: valAddr1.Bytes()},
{Key: staking.LastValidatorPowerKey, Value: valAddr1.Bytes()},
{Key: staking.LastValidatorPowerKey, Value: valAddr1.Bytes()},
}},
{gov.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: gov.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(gov.Vote{})},
cmn.KVPair{Key: gov.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(gov.Vote{})},
{Key: gov.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(gov.Vote{})},
{Key: gov.VoteKey(1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(gov.Vote{})},
}},
{distribution.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: distr.ProposerKey, Value: consAddr1.Bytes()},
cmn.KVPair{Key: distr.ProposerKey, Value: consAddr1.Bytes()},
{Key: distr.ProposerKey, Value: consAddr1.Bytes()},
{Key: distr.ProposerKey, Value: consAddr1.Bytes()},
}},
{slashing.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: slashing.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(true)},
cmn.KVPair{Key: slashing.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(true)},
{Key: slashing.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(true)},
{Key: slashing.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(true)},
}},
{supply.StoreKey, []cmn.KVPair{
cmn.KVPair{Key: supply.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(supply.NewSupply(sdk.Coins{}))},
cmn.KVPair{Key: supply.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(supply.NewSupply(sdk.Coins{}))},
{Key: supply.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(supply.NewSupply(sdk.Coins{}))},
{Key: supply.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(supply.NewSupply(sdk.Coins{}))},
}},
{"Empty", []cmn.KVPair{cmn.KVPair{}, cmn.KVPair{}}},
{"Empty", []cmn.KVPair{{}, {}}},
{"OtherStore", []cmn.KVPair{
cmn.KVPair{Key: []byte("key"), Value: []byte("value")},
cmn.KVPair{Key: []byte("key"), Value: []byte("other_value")},
{Key: []byte("key"), Value: []byte("value")},
{Key: []byte("key"), Value: []byte("other_value")},
}},
}

View File

@ -1,8 +1,9 @@
package mocks
import (
gomock "github.com/golang/mock/gomock"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
)
type MockNodeQuerier struct {

View File

@ -8,10 +8,9 @@ import (
"fmt"
"strings"
"gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/crypto"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/libs/bech32"
)

View File

@ -8,7 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"

View File

@ -4,9 +4,10 @@ import (
"strings"
"testing"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
)
var (

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/libs/cli"
)

View File

@ -1,9 +1,10 @@
package v0_36
import (
"testing"
"github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
"testing"
"github.com/stretchr/testify/require"
)

View File

@ -4,9 +4,10 @@ import (
"strings"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

View File

@ -178,7 +178,7 @@ func (keeper BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.In
}
for _, in := range inputs {
_, err := keeper.SubtractCoins(ctx, in.Address, in.Coins)
_, err := keeper.SubtractCoins(ctx, in.Address, in.Coins)
if err != nil {
return err
}

View File

@ -123,8 +123,8 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
types.ModuleName: nil,
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, supply.DefaultCodespace, maccPerms)

View File

@ -1,10 +1,12 @@
package v0_36
import (
"testing"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
"github.com/tendermint/tendermint/crypto/secp256k1"
"testing"
"github.com/stretchr/testify/require"
)

View File

@ -5,9 +5,10 @@ import (
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/stretchr/testify/require"
)
var (

32
x/genaccounts/alias.go Normal file
View File

@ -0,0 +1,32 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types
package genaccounts
import (
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)
const (
ModuleName = types.ModuleName
)
var (
// functions aliases
NewGenesisAccountRaw = types.NewGenesisAccountRaw
NewGenesisAccount = types.NewGenesisAccount
NewGenesisAccountI = types.NewGenesisAccountI
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
SetGenesisStateInAppState = types.SetGenesisStateInAppState
ValidateGenesis = types.ValidateGenesis
// variable aliases
ModuleCdc = types.ModuleCdc
)
type (
GenesisAccount = types.GenesisAccount
GenesisAccounts = types.GenesisAccounts
GenesisState = types.GenesisState
)

View File

@ -1,14 +0,0 @@
package genaccounts
import (
"github.com/cosmos/cosmos-sdk/codec"
)
// generic sealed codec to be used throughout this module
var moduleCdc *codec.Codec
func init() {
moduleCdc = codec.New()
codec.RegisterCrypto(moduleCdc)
moduleCdc.Seal()
}

View File

@ -1,13 +0,0 @@
package genaccounts
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)
// expected account keeper
type AccountKeeper interface {
NewAccount(sdk.Context, auth.Account) auth.Account
SetAccount(sdk.Context, auth.Account)
IterateAccounts(ctx sdk.Context, process func(auth.Account) (stop bool))
}

View File

@ -1,25 +0,0 @@
package genaccounts
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)
// export genesis for all accounts
func ExportGenesis(ctx sdk.Context, accountKeeper AccountKeeper) GenesisState {
// iterate to get the accounts
accounts := []GenesisAccount{}
accountKeeper.IterateAccounts(ctx,
func(acc auth.Account) (stop bool) {
account, err := NewGenesisAccountI(acc)
if err != nil {
panic(err)
}
accounts = append(accounts, account)
return false
},
)
return accounts
}

39
x/genaccounts/genesis.go Normal file
View File

@ -0,0 +1,39 @@
package genaccounts
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)
// InitGenesis initializes accounts and deliver genesis transactions
func InitGenesis(ctx sdk.Context, _ *codec.Codec, accountKeeper types.AccountKeeper, genesisState GenesisState) {
genesisState.Sanitize()
// load the accounts
for _, gacc := range genesisState {
acc := gacc.ToAccount()
acc = accountKeeper.NewAccount(ctx, acc) // set account number
accountKeeper.SetAccount(ctx, acc)
}
}
// ExportGenesis exports genesis for all accounts
func ExportGenesis(ctx sdk.Context, accountKeeper types.AccountKeeper) GenesisState {
// iterate to get the accounts
accounts := []GenesisAccount{}
accountKeeper.IterateAccounts(ctx,
func(acc authexported.Account) (stop bool) {
account, err := NewGenesisAccountI(acc)
if err != nil {
panic(err)
}
accounts = append(accounts, account)
return false
},
)
return accounts
}

View File

@ -1,18 +0,0 @@
package genaccounts
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// initialize accounts and deliver genesis transactions
func InitGenesis(ctx sdk.Context, _ *codec.Codec, accountKeeper AccountKeeper, genesisState GenesisState) {
genesisState.Sanitize()
// load the accounts
for _, gacc := range genesisState {
acc := gacc.ToAccount()
acc = accountKeeper.NewAccount(ctx, acc) // set account number
accountKeeper.SetAccount(ctx, acc)
}
}

View File

@ -0,0 +1,17 @@
package genaccounts
import (
"github.com/cosmos/cosmos-sdk/codec"
)
// ModuleName is "accounts"
const ModuleName = "accounts"
// ModuleCdc - generic sealed codec to be used throughout this module
var ModuleCdc *codec.Codec
func init() {
ModuleCdc = codec.New()
codec.RegisterCrypto(ModuleCdc)
ModuleCdc.Seal()
}

View File

@ -0,0 +1,13 @@
package genaccounts
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
)
// AccountKeeper defines the expected account keeper (noalias)
type AccountKeeper interface {
NewAccount(sdk.Context, authexported.Account) authexported.Account
SetAccount(sdk.Context, authexported.Account)
IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool))
}

View File

@ -6,8 +6,8 @@ import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/supply"
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
)
@ -71,7 +71,7 @@ func NewGenesisAccountRaw(address sdk.AccAddress, coins,
}
// NewGenesisAccount creates a GenesisAccount instance from a BaseAccount.
func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
func NewGenesisAccount(acc *authtypes.BaseAccount) GenesisAccount {
return GenesisAccount{
Address: acc.Address,
Coins: acc.Coins,
@ -109,21 +109,21 @@ func NewGenesisAccountI(acc authexported.Account) (GenesisAccount, error) {
}
// ToAccount converts a GenesisAccount to an Account interface
func (ga *GenesisAccount) ToAccount() auth.Account {
bacc := auth.NewBaseAccount(ga.Address, ga.Coins.Sort(), nil, ga.AccountNumber, ga.Sequence)
func (ga *GenesisAccount) ToAccount() authexported.Account {
bacc := authtypes.NewBaseAccount(ga.Address, ga.Coins.Sort(), nil, ga.AccountNumber, ga.Sequence)
// vesting accounts
if !ga.OriginalVesting.IsZero() {
baseVestingAcc := auth.NewBaseVestingAccount(
baseVestingAcc := authtypes.NewBaseVestingAccount(
bacc, ga.OriginalVesting, ga.DelegatedFree,
ga.DelegatedVesting, ga.EndTime,
)
switch {
case ga.StartTime != 0 && ga.EndTime != 0:
return auth.NewContinuousVestingAccountRaw(baseVestingAcc, ga.StartTime)
return authtypes.NewContinuousVestingAccountRaw(baseVestingAcc, ga.StartTime)
case ga.EndTime != 0:
return auth.NewDelayedVestingAccountRaw(baseVestingAcc)
return authtypes.NewDelayedVestingAccountRaw(baseVestingAcc)
default:
panic(fmt.Sprintf("invalid genesis vesting account: %+v", ga))
}
@ -137,10 +137,10 @@ func (ga *GenesisAccount) ToAccount() auth.Account {
return bacc
}
//___________________________________
// GenesisAccounts defines a set of genesis account
type GenesisAccounts []GenesisAccount
// genesis accounts contain an address
// Contains checks if a set of genesis accounts contain an address
func (gaccs GenesisAccounts) Contains(acc sdk.AccAddress) bool {
for _, gacc := range gaccs {
if gacc.Address.Equals(acc) {

View File

@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/crypto/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
@ -70,22 +70,22 @@ func TestToAccount(t *testing.T) {
addr := sdk.AccAddress(priv.PubKey().Address())
// base account
authAcc := auth.NewBaseAccountWithAddress(addr)
authAcc := authtypes.NewBaseAccountWithAddress(addr)
authAcc.SetCoins(sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)))
genAcc := NewGenesisAccount(&authAcc)
acc := genAcc.ToAccount()
require.IsType(t, &auth.BaseAccount{}, acc)
require.Equal(t, &authAcc, acc.(*auth.BaseAccount))
require.IsType(t, &authtypes.BaseAccount{}, acc)
require.Equal(t, &authAcc, acc.(*authtypes.BaseAccount))
// vesting account
vacc := auth.NewContinuousVestingAccount(
vacc := authtypes.NewContinuousVestingAccount(
&authAcc, time.Now().Unix(), time.Now().Add(24*time.Hour).Unix(),
)
genAcc, err := NewGenesisAccountI(vacc)
require.NoError(t, err)
acc = genAcc.ToAccount()
require.IsType(t, &auth.ContinuousVestingAccount{}, acc)
require.Equal(t, vacc, acc.(*auth.ContinuousVestingAccount))
require.IsType(t, &authtypes.ContinuousVestingAccount{}, acc)
require.Equal(t, vacc, acc.(*authtypes.ContinuousVestingAccount))
// module account
macc := supply.NewEmptyModuleAccount("mint", supply.Minter)

View File

@ -9,10 +9,10 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
)
// State to Unmarshal
// GenesisState is a wrapper for GenAccounts
type GenesisState GenesisAccounts
// get the genesis state from the expected app state
// GetGenesisStateFromAppState gets the genesis state from the expected app state
func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawMessage) GenesisState {
var genesisState GenesisState
if appState[ModuleName] != nil {
@ -22,7 +22,7 @@ func GetGenesisStateFromAppState(cdc *codec.Codec, appState map[string]json.RawM
return genesisState
}
// set the genesis state within the expected app state
// SetGenesisStateInAppState sets the genesis state within the expected app state
func SetGenesisStateInAppState(cdc *codec.Codec,
appState map[string]json.RawMessage, genesisState GenesisState) map[string]json.RawMessage {

View File

@ -3,16 +3,17 @@ package genaccounts
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
func TestSanitize(t *testing.T) {
addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
authAcc1 := auth.NewBaseAccountWithAddress(addr1)
authAcc1 := authtypes.NewBaseAccountWithAddress(addr1)
authAcc1.SetCoins(sdk.Coins{
sdk.NewInt64Coin("bcoin", 150),
sdk.NewInt64Coin("acoin", 150),
@ -21,7 +22,7 @@ func TestSanitize(t *testing.T) {
genAcc1 := NewGenesisAccount(&authAcc1)
addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
authAcc2 := auth.NewBaseAccountWithAddress(addr2)
authAcc2 := authtypes.NewBaseAccountWithAddress(addr2)
authAcc2.SetCoins(sdk.Coins{
sdk.NewInt64Coin("acoin", 150),
sdk.NewInt64Coin("bcoin", 150),
@ -50,7 +51,7 @@ var (
// require duplicate accounts fails validation
func TestValidateGenesisDuplicateAccounts(t *testing.T) {
acc1 := auth.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
acc1.Coins = sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
genAccs := make([]GenesisAccount, 2)
@ -64,9 +65,9 @@ func TestValidateGenesisDuplicateAccounts(t *testing.T) {
// require invalid vesting account fails validation (invalid end time)
func TestValidateGenesisInvalidAccounts(t *testing.T) {
acc1 := auth.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
acc1.Coins = sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
acc2 := auth.NewBaseAccountWithAddress(sdk.AccAddress(addr2))
acc2 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr2))
acc2.Coins = sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
genAccs := make([]GenesisAccount, 2)

View File

@ -1,14 +1,16 @@
package v0_36
import (
"testing"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/secp256k1"
"testing"
"github.com/stretchr/testify/require"
)

View File

@ -12,7 +12,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)
var (
@ -20,9 +21,6 @@ var (
_ module.AppModuleBasic = AppModuleBasic{}
)
// module name
const ModuleName = "accounts"
// app module basics object
type AppModuleBasic struct{}
@ -36,13 +34,13 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
// default genesis state
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return moduleCdc.MustMarshalJSON(GenesisState{})
return ModuleCdc.MustMarshalJSON(GenesisState{})
}
// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data GenesisState
err := moduleCdc.UnmarshalJSON(bz, &data)
err := ModuleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
@ -62,7 +60,7 @@ func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
// iterate the genesis accounts and perform an operation at each of them
// - to used by other modules
func (AppModuleBasic) IterateGenesisAccounts(cdc *codec.Codec, appGenesis map[string]json.RawMessage,
iterateFn func(auth.Account) (stop bool)) {
iterateFn func(exported.Account) (stop bool)) {
genesisState := GetGenesisStateFromAppState(cdc, appGenesis)
for _, genAcc := range genesisState {
@ -77,11 +75,11 @@ func (AppModuleBasic) IterateGenesisAccounts(cdc *codec.Codec, appGenesis map[st
// app module
type AppModule struct {
AppModuleBasic
accountKeeper AccountKeeper
accountKeeper types.AccountKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(accountKeeper AccountKeeper) module.AppModule {
func NewAppModule(accountKeeper types.AccountKeeper) module.AppModule {
return module.NewGenesisOnlyAppModule(AppModule{
AppModuleBasic: AppModuleBasic{},
@ -92,13 +90,13 @@ func NewAppModule(accountKeeper AccountKeeper) module.AppModule {
// module init-genesis
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
moduleCdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, moduleCdc, am.accountKeeper, genesisState)
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, ModuleCdc, am.accountKeeper, genesisState)
return []abci.ValidatorUpdate{}
}
// module export genesis
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.accountKeeper)
return moduleCdc.MustMarshalJSON(gs)
return ModuleCdc.MustMarshalJSON(gs)
}

View File

@ -3,11 +3,12 @@ package genutil
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
)
var (

View File

@ -4,9 +4,10 @@ import (
"strings"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

View File

@ -60,9 +60,9 @@ func getMockApp(t *testing.T, numGenAccs int, genState GenesisState, genAccs []a
bk := bank.NewBaseKeeper(mApp.AccountKeeper, mApp.ParamsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace)
maccPerms := map[string][]string{
types.ModuleName: []string{supply.Burner},
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
types.ModuleName: {supply.Burner},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, bk, supply.DefaultCodespace, maccPerms)
sk := staking.NewKeeper(mApp.Cdc, keyStaking, tKeyStaking, supplyKeeper, pk.Subspace(staking.DefaultParamspace), staking.DefaultCodespace)

View File

@ -4,9 +4,10 @@ import (
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var addr = sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())

View File

@ -59,9 +59,9 @@ func newTestInput(t *testing.T) testInput {
bankKeeper := bank.NewBaseKeeper(accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace)
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
types.ModuleName: []string{supply.Minter},
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
types.ModuleName: {supply.Minter},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(types.ModuleCdc, keySupply, accountKeeper, bankKeeper, supply.DefaultCodespace, maccPerms)
supplyKeeper.SetSupply(ctx, supply.NewSupply(sdk.Coins{}))

View File

@ -40,8 +40,8 @@ func getMockApp(t *testing.T) (*mock.App, staking.Keeper, Keeper) {
bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper, mapp.ParamsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace)
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(mapp.Cdc, keySupply, mapp.AccountKeeper, bankKeeper, supply.DefaultCodespace, maccPerms)
stakingKeeper := staking.NewKeeper(mapp.Cdc, keyStaking, tkeyStaking, supplyKeeper, mapp.ParamsKeeper.Subspace(staking.DefaultParamspace), staking.DefaultCodespace)

View File

@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
)
// NewHandler creates an sdk.Handler for all the slashing type messages
// NewHandler creates an sdk.Handler for all the slashing type messages
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
ctx = ctx.WithEventManager(sdk.NewEventManager())
@ -26,7 +26,7 @@ func NewHandler(k Keeper) sdk.Handler {
// Validators must submit a transaction to unjail itself after
// having been jailed (and thus unbonded) for downtime
func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {
err := k.Unjail(ctx, msg.ValidatorAddr)
if err != nil {
return err.Result()

View File

@ -5,7 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
)
// GetValidatorSigningInfo retruns the ValidatorSigningInfo for a specific validator
// GetValidatorSigningInfo retruns the ValidatorSigningInfo for a specific validator
// ConsAddress
func (k Keeper) GetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info types.ValidatorSigningInfo, found bool) {
store := ctx.KVStore(k.storeKey)
@ -26,7 +26,6 @@ func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress
store.Set(types.GetValidatorSigningInfoKey(address), bz)
}
// IterateValidatorSigningInfos iterates over the stored ValidatorSigningInfo
func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context,
handler func(address sdk.ConsAddress, info types.ValidatorSigningInfo) (stop bool)) {

View File

@ -82,8 +82,8 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee
bk := bank.NewBaseKeeper(accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace)
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, supply.DefaultCodespace, maccPerms)

View File

@ -47,4 +47,4 @@ func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) sdk.Error
k.sk.Unjail(ctx, consAddr)
return nil
}
}

View File

@ -28,8 +28,8 @@ func getMockApp(t *testing.T) (*mock.App, Keeper) {
bankKeeper := bank.NewBaseKeeper(mApp.AccountKeeper, mApp.ParamsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace)
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
types.NotBondedPoolName: []string{supply.Burner, supply.Staking},
types.BondedPoolName: []string{supply.Burner, supply.Staking},
types.NotBondedPoolName: {supply.Burner, supply.Staking},
types.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, bankKeeper, supply.DefaultCodespace, maccPerms)
keeper := NewKeeper(mApp.Cdc, keyStaking, tkeyStaking, supplyKeeper, mApp.ParamsKeeper.Subspace(DefaultParamspace), DefaultCodespace)

View File

@ -1,8 +1,9 @@
package exported
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DelegationI delegation bond for a delegated proof of stake system

View File

@ -126,8 +126,8 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context
maccPerms := map[string][]string{
auth.FeeCollectorName: nil,
types.NotBondedPoolName: []string{supply.Burner, supply.Staking},
types.BondedPoolName: []string{supply.Burner, supply.Staking},
types.NotBondedPoolName: {supply.Burner, supply.Staking},
types.BondedPoolName: {supply.Burner, supply.Staking},
}
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bk, supply.DefaultCodespace, maccPerms)

View File

@ -119,11 +119,11 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
// Update the pools based on the recent updates in the validator set:
// - The tokens from the non-bonded candidates that enter the new validator set need to be transferred
// to the Bonded pool.
// - The tokens from the bonded validators that are being kicked out from the validator set
// - The tokens from the bonded validators that are being kicked out from the validator set
// need to be transferred to the NotBonded pool.
switch {
// Compare and subtract the respective amounts to only perform one transfer.
// This is done in order to avoid doing multiple updates inside each iterator/loop.
// Compare and subtract the respective amounts to only perform one transfer.
// This is done in order to avoid doing multiple updates inside each iterator/loop.
case amtFromNotBondedToBonded.GT(amtFromBondedToNotBonded):
k.notBondedTokensToBonded(ctx, amtFromNotBondedToBonded.Sub(amtFromBondedToNotBonded))
case amtFromNotBondedToBonded.LT(amtFromBondedToNotBonded):

View File

@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -4,13 +4,14 @@ import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
"github.com/spf13/cobra"
)
// GetQueryCmd returns the cli query commands for this module

View File

@ -80,10 +80,10 @@ func createTestInput(t *testing.T, isCheckTx bool, initPower int64, nAccs int64)
maccPerms := map[string][]string{
holder: nil,
types.Minter: []string{types.Minter},
types.Burner: []string{types.Burner},
multiPerm: []string{types.Minter, types.Burner, types.Staking},
randomPerm: []string{"random"},
types.Minter: {types.Minter},
types.Burner: {types.Burner},
multiPerm: {types.Minter, types.Burner, types.Staking},
randomPerm: {"random"},
}
keeper := NewKeeper(cdc, keySupply, ak, bk, DefaultCodespace, maccPerms)
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens.MulRaw(nAccs)))

View File

@ -4,9 +4,10 @@ import (
"fmt"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

View File

@ -3,8 +3,9 @@ package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Supply represents a struct that passively keeps track of the total supply amounts in the network

View File

@ -4,7 +4,7 @@ import (
"fmt"
"testing"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"