Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/auth)!: remove Address.String() #19990

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions simapp/genesis_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package simapp
import (
"errors"

"cosmossdk.io/core/address"
authtypes "cosmossdk.io/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -28,7 +29,7 @@ type SimGenesisAccount struct {
}

// Validate checks for errors on the vesting and module account parameters
func (sga SimGenesisAccount) Validate() error {
func (sga SimGenesisAccount) Validate(addressCodec address.Codec) error {
if !sga.OriginalVesting.IsZero() {
if sga.StartTime >= sga.EndTime {
return errors.New("vesting start-time cannot be before end-time")
Expand All @@ -39,10 +40,10 @@ func (sga SimGenesisAccount) Validate() error {
ma := authtypes.ModuleAccount{
BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions,
}
if err := ma.Validate(); err != nil {
if err := ma.Validate(addressCodec); err != nil {
return err
}
}

return sga.BaseAccount.Validate()
return sga.BaseAccount.Validate(addressCodec)
}
11 changes: 8 additions & 3 deletions simapp/genesis_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import (
"cosmossdk.io/simapp"
authtypes "cosmossdk.io/x/auth/types"

codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestSimGenesisAccountValidate(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())

ac := codectestutil.CodecOptions{}.GetAddressCodec()
addr, err := ac.BytesToString(pubkey.Address())
require.NoError(t, err)
modAddr, err := ac.BytesToString(crypto.AddressHash([]byte("testmod")))
require.NoError(t, err)
vestingStart := time.Now().UTC()

coins := sdk.NewCoins(sdk.NewInt64Coin("test", 1000))
Expand Down Expand Up @@ -45,7 +50,7 @@ func TestSimGenesisAccountValidate(t *testing.T) {
{
"valid basic account with module name",
simapp.SimGenesisAccount{
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, 0, 0),
BaseAccount: authtypes.NewBaseAccount(modAddr, nil, 0, 0),
ModuleName: "testmod",
},
false,
Expand Down Expand Up @@ -83,7 +88,7 @@ func TestSimGenesisAccountValidate(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.wantErr, tc.sga.Validate() != nil)
require.Equal(t, tc.wantErr, tc.sga.Validate(ac) != nil)
})
}
}
8 changes: 6 additions & 2 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ func initTestnetFiles(
_ = os.RemoveAll(args.outputDir)
return err
}
addrStr, err := clientCtx.AddressCodec.BytesToString(addr)
if err != nil {
return err
}

info := map[string]string{"secret": secret}

Expand All @@ -296,8 +300,8 @@ func initTestnetFiles(
sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens),
}

genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))
genBalances = append(genBalances, banktypes.Balance{Address: addrStr, Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addrStr, nil, 0, 0))

valStr, err := clientCtx.ValidatorAddressCodec.BytesToString(sdk.ValAddress(addr))
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -65,7 +66,9 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(senderPrivKey.PubKey().Address())
require.NoError(t, err)
acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
Expand Down Expand Up @@ -107,7 +110,9 @@ func Setup(t *testing.T, isCheckTx bool) *SimApp {

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(senderPrivKey.PubKey().Address())
require.NoError(t, err)
acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
Expand Down Expand Up @@ -167,7 +172,9 @@ func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState {

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
addr, err := app.AuthKeeper.AddressCodec().BytesToString(senderPrivKey.PubKey().Address())
require.NoError(t, err)
acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0)
balances := []banktypes.Balance{
{
Address: acc.GetAddress().String(),
Expand Down
Loading
Loading