Skip to content

Commit

Permalink
Refactor/vesting (#3)
Browse files Browse the repository at this point in the history
* refactor: remove merge logic

* refactor: update test
  • Loading branch information
hoanguyenkh authored and hoanguyenkh committed Jul 27, 2022
1 parent b6649d1 commit eb8e776
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 115 deletions.
7 changes: 0 additions & 7 deletions proto/evmos/vesting/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ message MsgCreateClawbackVestingAccount {
(gogoproto.castrepeated) =
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types.Periods"
];

// merge specifies a the creation mechanism for existing
// ClawbackVestingAccounts. If true, merge this new grant into an existing
// ClawbackVestingAccount, or create it if it does not exist. If false,
// creates a new account. New grants to an existing account must be from the
// same from_address.
bool merge = 6;
}

// MsgCreateClawbackVestingAccountResponse defines the
Expand Down
5 changes: 1 addition & 4 deletions x/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ with a start time and an array of coins strings and durations relative to the st

commonStart, _ := types.AlignSchedules(lockupStart, vestingStart, lockupPeriods, vestingPeriods)

merge, _ := cmd.Flags().GetBool(FlagMerge)

msg := types.NewMsgCreateClawbackVestingAccount(clientCtx.GetFromAddress(), toAddr, time.Unix(commonStart, 0), lockupPeriods, vestingPeriods, merge)
msg := types.NewMsgCreateClawbackVestingAccount(clientCtx.GetFromAddress(), toAddr, time.Unix(commonStart, 0), lockupPeriods, vestingPeriods)
if err := msg.ValidateBasic(); err != nil {
return err
}
Expand All @@ -121,7 +119,6 @@ with a start time and an array of coins strings and durations relative to the st
},
}

cmd.Flags().Bool(FlagMerge, false, "Merge new amount and schedule with existing ClawbackVestingAccount, if any")
cmd.Flags().String(FlagLockup, "", "path to file containing unlocking periods")
cmd.Flags().String(FlagVesting, "", "path to file containing vesting periods")
flags.AddTxFlagsToCmd(cmd)
Expand Down
1 change: 0 additions & 1 deletion x/vesting/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (suite *KeeperTestSuite) TestBalances() {
vestingStart,
lockupPeriods,
vestingPeriods,
false,
)
ctx := sdk.WrapSDKContext(suite.ctx)
_, err = suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg)
Expand Down
2 changes: 1 addition & 1 deletion x/vesting/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ var _ = Describe("Clawback Vesting Accounts - claw back tokens", Ordered, func()
s.Require().Equal(balanceGrantee, sdk.NewInt64Coin(stakeDenom, 0))
s.Require().Equal(balanceDest, sdk.NewInt64Coin(stakeDenom, 0))

msg := types.NewMsgCreateClawbackVestingAccount(funder, grantee, vestingStart, lockupPeriods, vestingPeriods, true)
msg := types.NewMsgCreateClawbackVestingAccount(funder, grantee, vestingStart, lockupPeriods, vestingPeriods)

_, err := s.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg)
s.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion x/vesting/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
// Set Context
suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{
Height: 1,
ChainID: "evmos_9001-1",
ChainID: "evmos_9000-1",
Time: time.Now().UTC(),
ProposerAddress: suite.consAddress.Bytes(),

Expand Down
8 changes: 2 additions & 6 deletions x/vesting/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"strconv"
"time"

"github.com/armon/go-metrics"
Expand Down Expand Up @@ -76,11 +75,9 @@ func (k Keeper) CreateClawbackVestingAccount(
vestingAcc, isClawback = acc.(*types.ClawbackVestingAccount)

switch {
case !msg.Merge && isClawback:
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists; consider using --merge", msg.ToAddress)
case !msg.Merge && !isClawback:
case isClawback:
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
case msg.Merge && !isClawback:
case !isClawback:
return nil, sdkerrors.Wrapf(sdkerrors.ErrNotSupported, "account %s must be a clawback vesting account", msg.ToAddress)
case msg.FromAddress != vestingAcc.FunderAddress:
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s can only accept grants from account %s", msg.ToAddress, vestingAcc.FunderAddress)
Expand Down Expand Up @@ -134,7 +131,6 @@ func (k Keeper) CreateClawbackVestingAccount(
sdk.NewAttribute(sdk.AttributeKeySender, msg.FromAddress),
sdk.NewAttribute(types.AttributeKeyCoins, vestingCoins.String()),
sdk.NewAttribute(types.AttributeKeyStartTime, msg.StartTime.String()),
sdk.NewAttribute(types.AttributeKeyMerge, strconv.FormatBool(msg.Merge)),
sdk.NewAttribute(types.AttributeKeyAccount, msg.ToAddress),
),
},
Expand Down
5 changes: 2 additions & 3 deletions x/vesting/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (suite *KeeperTestSuite) TestMsgCreateClawbackVestingAccount() {
vestingPeriods,
true,
1000,
true,
false,
},
}
for _, tc := range testCases {
Expand All @@ -193,7 +193,6 @@ func (suite *KeeperTestSuite) TestMsgCreateClawbackVestingAccount() {
tc.startTime,
tc.lockup,
tc.vesting,
tc.merge,
)
res, err := suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, msg)

Expand Down Expand Up @@ -300,7 +299,7 @@ func (suite *KeeperTestSuite) TestMsgClawback() {
testutil.FundAccount(suite.app.BankKeeper, suite.ctx, addr, balances)

// Create Clawback Vesting Account
createMsg := types.NewMsgCreateClawbackVestingAccount(addr, addr2, tc.startTime, lockupPeriods, vestingPeriods, false)
createMsg := types.NewMsgCreateClawbackVestingAccount(addr, addr2, tc.startTime, lockupPeriods, vestingPeriods)
createRes, err := suite.app.VestingKeeper.CreateClawbackVestingAccount(ctx, createMsg)
suite.Require().NoError(err)
suite.Require().NotNil(createRes)
Expand Down
1 change: 0 additions & 1 deletion x/vesting/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const (

AttributeKeyCoins = "coins"
AttributeKeyStartTime = "start_time"
AttributeKeyMerge = "merge"
AttributeKeyAccount = "account"
AttributeKeyFunder = "funder"
AttributeKeyDestination = "destination"
Expand Down
2 changes: 0 additions & 2 deletions x/vesting/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ func NewMsgCreateClawbackVestingAccount(
startTime time.Time,
lockupPeriods,
vestingPeriods sdkvesting.Periods,
merge bool,
) *MsgCreateClawbackVestingAccount {
return &MsgCreateClawbackVestingAccount{
FromAddress: fromAddr.String(),
ToAddress: toAddr.String(),
StartTime: startTime,
LockupPeriods: lockupPeriods,
VestingPeriods: vestingPeriods,
Merge: merge,
}
}

Expand Down
3 changes: 0 additions & 3 deletions x/vesting/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func (suite *MsgsTestSuite) TestMsgCreateClawbackVestingAccountGetters() {
time.Unix(100200300, 0),
sdkvesting.Periods{{Length: 200000, Amount: sdk.Coins{sdk.NewInt64Coin("atom", 10000000)}}},
sdkvesting.Periods{{Length: 300000, Amount: sdk.Coins{sdk.NewInt64Coin("atom", 10000000)}}},
true,
)
suite.Require().Equal(RouterKey, msg.Route())
suite.Require().Equal(TypeMsgCreateClawbackVestingAccount, msg.Type())
Expand Down Expand Up @@ -65,7 +64,6 @@ func (suite *MsgsTestSuite) TestMsgCreateClawbackVestingAccountNew() {
tc.startTime,
tc.lockupPeriods,
tc.vestingPeriods,
tc.merge,
)
err := tx.ValidateBasic()

Expand Down Expand Up @@ -167,7 +165,6 @@ func (suite *MsgsTestSuite) TestMsgCreateClawbackVestingAccount() {
tc.startTime,
tc.lockupPeriods,
tc.vestingPeriods,
tc.merge,
}
err := tx.ValidateBasic()

Expand Down
1 change: 0 additions & 1 deletion x/vesting/types/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
// value at the last step, which can speed evaluation of the step function after
// the last step.
//
// ReadSchedule returns the value of a schedule at readTime.
func ReadSchedule(
startTime, endTime int64,
periods sdkvesting.Periods,
Expand Down
121 changes: 37 additions & 84 deletions x/vesting/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/vesting/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func coinEq(a, b sdk.Coins) bool {
return a.IsAllLTE(b) && b.IsAllLTE(a)
}

// max64 returns the maximum of its inputs.
// Max64 returns the maximum of its inputs.
func Max64(i, j int64) int64 {
if i > j {
return i
Expand Down

0 comments on commit eb8e776

Please sign in to comment.