refactor(vesting): fix build (#19539)
This commit is contained in:
parent
4b73e31b00
commit
619e0da8da
20
.github/workflows/build.yml
vendored
20
.github/workflows/build.yml
vendored
@ -1,5 +1,4 @@
|
||||
name: Build SimApp
|
||||
# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum have been changed
|
||||
on:
|
||||
pull_request:
|
||||
merge_group:
|
||||
@ -28,28 +27,12 @@ jobs:
|
||||
with:
|
||||
go-version: "1.22"
|
||||
check-latest: true
|
||||
- uses: technote-space/get-diff-action@v6.1.2
|
||||
id: git_diff
|
||||
with:
|
||||
PATTERNS: |
|
||||
**/*.go
|
||||
go.mod
|
||||
go.sum
|
||||
**/go.mod
|
||||
**/go.sum
|
||||
**/Makefile
|
||||
Makefile
|
||||
flake.lock
|
||||
flake.nix
|
||||
simapp/default.nix
|
||||
###################
|
||||
#### Build App ####
|
||||
###################
|
||||
- name: Build
|
||||
if: env.GIT_DIFF
|
||||
run: GOARCH=${{ matrix.go-arch }} make build
|
||||
- name: Build Legacy
|
||||
if: env.GIT_DIFF
|
||||
run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS=legacy make build
|
||||
- name: Build with rocksdb backend
|
||||
if: |
|
||||
@ -60,11 +43,8 @@ jobs:
|
||||
## Build Tooling ##
|
||||
###################
|
||||
- name: Build Cosmovisor
|
||||
if: env.GIT_DIFF
|
||||
run: GOARCH=${{ matrix.go-arch }} make cosmovisor
|
||||
- name: Build Confix
|
||||
if: env.GIT_DIFF
|
||||
run: GOARCH=${{ matrix.go-arch }} make confix
|
||||
- name: Build Hubl
|
||||
if: env.GIT_DIFF
|
||||
run: GOARCH=${{ matrix.go-arch }} make hubl
|
||||
|
||||
@ -218,11 +218,6 @@ var (
|
||||
// upgrade
|
||||
GenType(&upgradetypes.MsgSoftwareUpgrade{}, &upgradeapi.MsgSoftwareUpgrade{}, GenOpts.WithDisallowNil()),
|
||||
GenType(&upgradetypes.MsgCancelUpgrade{}, &upgradeapi.MsgCancelUpgrade{}, GenOpts),
|
||||
|
||||
// vesting
|
||||
GenType(&vestingtypes.MsgCreateVestingAccount{}, &vestingapi.MsgCreateVestingAccount{}, GenOpts),
|
||||
GenType(&vestingtypes.MsgCreatePermanentLockedAccount{}, &vestingapi.MsgCreatePermanentLockedAccount{}, GenOpts),
|
||||
GenType(&vestingtypes.MsgCreatePeriodicVestingAccount{}, &vestingapi.MsgCreatePeriodicVestingAccount{}, GenOpts),
|
||||
}
|
||||
NonsignableTypes = []GeneratedType{
|
||||
GenType(&authtypes.Params{}, &authapi.Params{}, GenOpts),
|
||||
|
||||
@ -4,6 +4,11 @@ sidebar_position: 1
|
||||
|
||||
# `x/auth/vesting`
|
||||
|
||||
:::warning
|
||||
This module is deprecated in favor of x/accounts.
|
||||
The creation of vesting account, using x/auth/vesting, is not possible since v0.51.
|
||||
For existing chains, importing the x/auth/vesting module is still required for backward compatibility purposes.
|
||||
:::
|
||||
|
||||
* [Intro and Requirements](#intro-and-requirements)
|
||||
* [Note](#note)
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"start_time": 1625204910,
|
||||
"period": [
|
||||
{
|
||||
"coins": "10test",
|
||||
"length_seconds": 2592000
|
||||
},
|
||||
{
|
||||
"coins": "10test",
|
||||
"length_seconds": 2592000
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,116 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/x/auth/vesting/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// GetTxCmd returns vesting module's transaction commands.
|
||||
func GetTxCmd() *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Vesting transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
NewMsgCreatePeriodicVestingAccountCmd(),
|
||||
)
|
||||
|
||||
return txCmd
|
||||
}
|
||||
|
||||
type VestingData struct {
|
||||
StartTime int64 `json:"start_time"`
|
||||
Periods []InputPeriod `json:"periods"`
|
||||
}
|
||||
|
||||
type InputPeriod struct {
|
||||
Coins string `json:"coins"`
|
||||
Length int64 `json:"length_seconds"`
|
||||
}
|
||||
|
||||
// NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a MsgCreatePeriodicVestingAccountCmd transaction.
|
||||
// This command can be migrated to AutoCLI but it would be CLI breaking to do so.
|
||||
func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-periodic-vesting-account [to_address] [periods_json_file]",
|
||||
Short: "Create a new vesting account funded with an allocation of tokens.",
|
||||
Long: `A sequence of coins and period length in seconds. Periods are sequential, in that the duration of of a period only starts at the end of the previous period. The duration of the first period starts upon account creation. For instance, the following periods.json file shows 20 "test" coins vesting 30 days apart from each other.
|
||||
Where periods.json contains an array of coin strings and unix epoch times for coins to vest:
|
||||
{
|
||||
"start_time": 1625204910,
|
||||
"periods": [
|
||||
{
|
||||
"coins": "10test",
|
||||
"length_seconds": 2592000 //30 days
|
||||
},
|
||||
{
|
||||
"coins": "10test",
|
||||
"length_seconds": 2592000 //30 days
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
toAddr, err := clientCtx.AddressCodec.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
contents, err := os.ReadFile(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var vestingData VestingData
|
||||
|
||||
err = json.Unmarshal(contents, &vestingData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var periods []types.Period
|
||||
|
||||
for i, p := range vestingData.Periods {
|
||||
|
||||
amount, err := sdk.ParseCoinsNormalized(p.Coins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.Length < 0 {
|
||||
return fmt.Errorf("invalid period length of %d in period %d, length must be greater than 0", p.Length, i)
|
||||
}
|
||||
|
||||
period := types.Period{Length: p.Length, Amount: amount}
|
||||
periods = append(periods, period)
|
||||
}
|
||||
|
||||
msg := types.NewMsgCreatePeriodicVestingAccount(clientCtx.GetFromAddress(), toAddr, vestingData.StartTime, periods)
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@ -1,105 +0,0 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"cosmossdk.io/x/auth/vesting"
|
||||
"cosmossdk.io/x/auth/vesting/client/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
type CLITestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
kr keyring.Keyring
|
||||
encCfg testutilmod.TestEncodingConfig
|
||||
baseCtx client.Context
|
||||
}
|
||||
|
||||
func TestMigrateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(CLITestSuite))
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) SetupSuite() {
|
||||
s.encCfg = testutilmod.MakeTestEncodingConfig(vesting.AppModule{})
|
||||
s.kr = keyring.NewInMemory(s.encCfg.Codec)
|
||||
s.baseCtx = client.Context{}.
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
WithValidatorAddressCodec(addresscodec.NewBech32Codec("cosmosvaloper")).
|
||||
WithConsensusAddressCodec(addresscodec.NewBech32Codec("cosmosvalcons"))
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreatePeriodicVestingAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd()
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("photon", sdkmath.NewInt(10))).String()),
|
||||
fmt.Sprintf("--%s=test-chain", flags.FlagChainID),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, accounts[0].Address),
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
to sdk.AccAddress
|
||||
extraArgs []string
|
||||
expectErrMsg string
|
||||
}{
|
||||
{
|
||||
"valid transaction",
|
||||
accounts[0].Address,
|
||||
extraArgs,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"invalid to address",
|
||||
sdk.AccAddress{},
|
||||
extraArgs,
|
||||
"empty address string is not allowed",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(append([]string{tc.to.String(), "./periods.json"}, tc.extraArgs...))
|
||||
|
||||
s.Require().NoError(client.SetCmdClientContextHandler(s.baseCtx, cmd))
|
||||
|
||||
err := cmd.Execute()
|
||||
if tc.expectErrMsg != "" {
|
||||
s.Require().ErrorContains(err, "empty address string is not allowed")
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,123 +0,0 @@
|
||||
package vesting
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/log"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
authkeeper "cosmossdk.io/x/auth/keeper"
|
||||
authtypes "cosmossdk.io/x/auth/types"
|
||||
vestingtypes "cosmossdk.io/x/auth/vesting/types"
|
||||
"cosmossdk.io/x/bank/keeper"
|
||||
banktestutil "cosmossdk.io/x/bank/testutil"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
var (
|
||||
fromAddr = sdk.AccAddress([]byte("from1________________"))
|
||||
to2Addr = sdk.AccAddress([]byte("to2__________________"))
|
||||
to3Addr = sdk.AccAddress([]byte("to3__________________"))
|
||||
fooCoin = sdk.NewInt64Coin("foo", 100)
|
||||
accAddrs = []sdk.AccAddress{
|
||||
sdk.AccAddress([]byte("addr1_______________")),
|
||||
sdk.AccAddress([]byte("addr2_______________")),
|
||||
sdk.AccAddress([]byte("addr3_______________")),
|
||||
sdk.AccAddress([]byte("addr4_______________")),
|
||||
sdk.AccAddress([]byte("addr5_______________")),
|
||||
}
|
||||
)
|
||||
|
||||
func FuzzMsgServerCreateVestingAccount(f *testing.F) {
|
||||
if testing.Short() {
|
||||
f.Skip("Skipping in -short mode")
|
||||
}
|
||||
|
||||
// 1. Add some seeds.
|
||||
seeds := []*vestingtypes.MsgCreateVestingAccount{
|
||||
vestingtypes.NewMsgCreateVestingAccount(
|
||||
fromAddr,
|
||||
to2Addr,
|
||||
sdk.Coins{fooCoin},
|
||||
time.Now().Unix(),
|
||||
true,
|
||||
),
|
||||
vestingtypes.NewMsgCreateVestingAccount(
|
||||
fromAddr,
|
||||
to3Addr,
|
||||
sdk.Coins{fooCoin},
|
||||
time.Now().Unix(),
|
||||
false,
|
||||
),
|
||||
}
|
||||
|
||||
gf := fuzz.New()
|
||||
for _, seed := range seeds {
|
||||
for i := 0; i <= 1e4; i++ {
|
||||
blob, err := json.Marshal(seed)
|
||||
if err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
f.Add(blob)
|
||||
|
||||
// 1.5. Now mutate that seed a couple of times for the next round.
|
||||
gf.Fuzz(seed)
|
||||
}
|
||||
}
|
||||
|
||||
key := storetypes.NewKVStoreKey(authtypes.StoreKey)
|
||||
env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger())
|
||||
maccPerms := map[string][]string{}
|
||||
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig()
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
env,
|
||||
encCfg.Codec,
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
address.NewBech32Codec("cosmos"),
|
||||
"cosmos",
|
||||
authtypes.NewModuleAddress("gov").String(),
|
||||
)
|
||||
|
||||
vestingtypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
authtypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
|
||||
// 2. Now run the fuzzers.
|
||||
f.Fuzz(func(t *testing.T, in []byte) {
|
||||
va := new(vestingtypes.MsgCreateVestingAccount)
|
||||
if err := json.Unmarshal(in, va); err != nil {
|
||||
// Skip over malformed inputs that can JSON unmarshal.
|
||||
return
|
||||
}
|
||||
|
||||
storeService := runtime.NewKVStoreService(key)
|
||||
ctrl := gomock.NewController(t)
|
||||
authKeeper := banktestutil.NewMockAccountKeeper(ctrl)
|
||||
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
|
||||
bankKeeper := keeper.NewBaseKeeper(
|
||||
runtime.NewEnvironment(storeService, log.NewNopLogger()),
|
||||
encCfg.Codec,
|
||||
authKeeper,
|
||||
map[string]bool{accAddrs[4].String(): true},
|
||||
authtypes.NewModuleAddress(banktypes.GovModuleName).String(),
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
msgServer := NewMsgServerImpl(accountKeeper, bankKeeper)
|
||||
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()})
|
||||
_, _ = msgServer.CreateVestingAccount(ctx, va)
|
||||
})
|
||||
}
|
||||
@ -1,12 +1,8 @@
|
||||
package vesting
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/x/auth/keeper"
|
||||
"cosmossdk.io/x/auth/vesting/client/cli"
|
||||
"cosmossdk.io/x/auth/vesting/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -53,16 +49,5 @@ func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
types.RegisterInterfaces(registry)
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the vesting module.
|
||||
func (AppModule) GetTxCmd() *cobra.Command {
|
||||
return cli.GetTxCmd()
|
||||
}
|
||||
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
||||
types.RegisterMsgServer(registrar, NewMsgServerImpl(am.accountKeeper, am.bankKeeper))
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConsensusVersion implements HasConsensusVersion.
|
||||
func (AppModule) ConsensusVersion() uint64 { return 1 }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user