8000 chore(vesting): miscellaneous clean up in vesting module by MalteHerrmann · Pull Request #1708 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(vesting): miscellaneous clean up in vesting module #1708

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

Merged
merged 46 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c516f3a
adjust comment on handleClawbackProposal
Aug 15, 2023
ea0d8e6
adjust comment on NewHandler
Aug 16, 2023
b215f1e
move gov clawback functions to own file
Aug 16, 2023
97ac03e
fix some comments
Aug 16, 2023
61a333c
refactor checking vesting account
Aug 16, 2023
bc853c6
fix: redundant checks for amounts, no need to automatically convert b…
Vvaradinov Aug 16, 2023
0b209e4
remove unnecessary comment
Aug 16, 2023
437d3ce
remove unused key
Aug 16, 2023
732c24a
update comments
Aug 16, 2023
ed92115
apply refactored account validation in convert vesting account method
Aug 16, 2023
5850987
add error types and rework some error messages
Aug 16, 2023
4d83b8c
update example for cli cmd
Aug 17, 2023
fe175eb
run make proto-all
Aug 17, 2023
84c9e1d
add missing lics
Aug 17, 2023
6d621db
fix: re-add the conversion to ETH account
Vvaradinov Aug 17, 2023
f3301f1
Merge branch 'malte/vesting-nits' of https://github.com/evmos/evmos i…
Vvaradinov Aug 17, 2023
b179101
fix: integration tests to return correct error
Vvaradinov Aug 17, 2023
7e1b3fa
add note explaining logic
Aug 17, 2023
17ac480
remove check for clawback before start time
Aug 17, 2023
4ee8d41
fix some tests
Aug 17, 2023
ecf8b78
fix more tests
Aug 17, 2023
c1beb41
fix use of CoinEq and export it
Aug 17, 2023
6d7f4e7
add changelog entry
Aug 17, 2023
30cb228
run gofumpt
Aug 17, 2023
1a1cf07
fix clawback before start time
Aug 17, 2023
81cf911
avoid shadowing err var
Aug 17, 2023
ff5ec59
improve clawback method structure
Aug 17, 2023
d74c615
improve error message
Aug 17, 2023
3e63ebd
avoid multiple function calls
Aug 17, 2023
d72e33a
remove unnecessary redefinition of query helper
Aug 17, 2023
a6608d9
add unit tests
Aug 17, 2023
bb8b468
enhance grpc_query_test.go
Aug 17, 2023
1d64736
add keeper test
Aug 17, 2023
3388dbc
add missing tests for fundVestingAccount
Aug 17, 2023
ae84a68
add missing test for blocked addr in clawback
Aug 17, 2023
8bfd64a
imp(vesting): add clawed back coins to response for clawback method (…
MalteHerrmann Aug 17, 2023
e377a42
add tests for handleProposalClawback
Aug 17, 2023
ed7605c
Merge branch 'release/v14.0.x' into malte/vesting-nits
MalteHerrmann Aug 17, 2023
dac62b2
update vesting test helpers for sdk 47
Aug 17, 2023
e4deab9
remove unused pack functions
Aug 18, 2023
905715b
address TODO
Aug 18, 2023
ab2c7ff
address TODO
Aug 18, 2023
89698fe
remove type for MsgUpdateParams
Aug 18, 2023
6e5e294
add test for convert vesting account getters
Aug 18, 2023
1319030
escape linter
Aug 18, 2023
c71e20f
Update x/vesting/keeper/integration_test.go
MalteHerrmann Aug 18, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (mod) [#1674](https://github.com/evmos/evmos/pull/1674) Update `evmos` module name to `evmos/v14`
- (cli) [#1677](https://github.com/evmos/evmos/pull/1677) Update docs for `vesting` cli
- (proto) [#1684](https://github.com/evmos/evmos/pull/1684) Update proto files to use `evmos/v14`
- (deps) [#1682](https://github.com/evmos/evmos/pull/1682) Migrate `evmos-ledger-go` logic to this repository.
- (deps) [#1682](https://github.com/evmos/evmos/pull/1682) Migrate [evmos-ledger-go](https://github.com/evmos/evmos-ledger-go) logic to this repository
- (vesting) [#1708](https://github.com/evmos/evmos/pull/1708) Minor improvements to `vesting` module
- (vesting) [#1709](https://github.com/evmos/evmos/pull/1709) Add clawed back coins to `MsgClawbackResponse`

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion cmd/evmosd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa

// The vesting and lockup schedules must describe the same total amount.
// IsEqual can panic, so use (a == b) <=> (a <= b && b <= a).
if !(vestingCoins.IsAllLTE(lockupCoins) && lockupCoins.IsAllLTE(vestingCoins)) {
if !vestingtypes.CoinEq(lockupCoins, vestingCoins) {
return fmt.Errorf("lockup (%s) and vesting (%s) amounts must be equal",
lockupCoins, vestingCoins,
)
Expand Down
2 changes: 1 addition & 1 deletion precompiles/vesting/Vesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface VestingI {
address funderAddress,
address accountAddress,
address destAddress
) external returns (bool success);
) external returns (Coin[]);

/// @dev Defines a method for updating the funder of a vesting account.
/// @param funderAddress The address of the account that funded the vesting account.
Expand Down
18 changes: 15 additions & 3 deletions precompiles/vesting/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,21 @@
"name": "clawback",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
"components": [
{
"internalType": "string",
"name": "denom",
"type": "string"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"internalType": "struct Coin[]",
"name": "coins",
"type": "tuple[]"
}
],
"stateMutability": "nonpayable",
Expand Down
55 changes: 40 additions & 15 deletions precompiles/vesting/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,13 @@ var _ = Describe("Interacting with the vesting extension", func() {
})

It(fmt.Sprintf("should not fund the vesting when defining different total coins for lockup and vesting (%s)", callType.name), func() {
s.CreateTestClawbackVestingAccount()

createClawbackArgs := s.BuildCallArgs(callType, contractAddr).
WithMethodName(vesting.FundVestingAccountMethod).
WithArgs(
s.address,
vestingAddr,
toAddr,
uint64(time.Now().Unix()),
defaultPeriods,
doublePeriods,
Expand All @@ -299,6 +301,8 @@ var _ = Describe("Interacting with the vesting extension", func() {
})

It(fmt.Sprintf("should not fund the vesting when defining neither lockup nor vesting (%s)", callType.name), func() {
s.CreateTestClawbackVestingAccount()

createClawbackArgs := s.BuildCallArgs(callType, contractAddr).
WithMethodName(vesting.FundVestingAccountMethod).
WithArgs(
Expand Down Expand Up @@ -327,6 +331,7 @@ var _ = Describe("Interacting with the vesting extension", func() {

It(fmt.Sprintf("should not fund the vesting when exceeding the funder balance (%s)", callType.name), func() {
s.CreateTestClawbackVestingAccount()

balance := s.app.BankKeeper.GetBalance(s.ctx, s.address.Bytes(), s.bondDenom)
exceededBalance := new(big.Int).Add(big.NewInt(1), balance.Amount.BigInt())

Expand Down Expand Up @@ -364,6 +369,7 @@ var _ = Describe("Interacting with the vesting extension", func() {
})

It(fmt.Sprintf("should not fund the vesting when not sending as the funder (%s)", callType.name), func() {
s.CreateTestClawbackVestingAccount()
differentFunder := testutiltx.GenerateAddress()

createClawbackArgs := s.BuildCallArgs(callType, contractAddr).
Expand Down Expand Up @@ -399,6 +405,7 @@ var _ = Describe("Interacting with the vesting extension", func() {
})

It(fmt.Sprintf("should not fund the vesting when the address is blocked (%s)", callType.name), func() {
s.CreateTestClawbackVestingAccount()
moduleAddr := common.BytesToAddress(authtypes.NewModuleAddress("distribution").Bytes())

createClawbackArgs := s.BuildCallArgs(callType, contractAddr).
Expand Down Expand Up @@ -465,7 +472,7 @@ var _ = Describe("Interacting with the vesting extension", func() {

fundClawbackVestingCheck := execRevertedCheck
if callType.directCall {
fundClawbackVestingCheck = failCheck.WithErrContains("is not allowed to receive funds")
fundClawbackVestingCheck = failCheck.WithErrContains("does not exist")
}

_, _, err := contracts.CallContractAndCheckLogs(s.ctx, s.app, createClawbackArgs, fundClawbackVestingCheck)
Expand All @@ -492,7 +499,10 @@ var _ = Describe("Interacting with the vesting extension", func() {
}

_, _, err := contracts.CallContractAndCheckLogs(s.ctx, s.app, createClawbackArgs, fundClawbackVestingCheck)
Expect(err).To(HaveOccurred(), "error while creating a clawback vesting account for a module address", err)
Expect(err).To(HaveOccurred(), "error while creating a clawback vesting account for the zero address", err)
if callType.directCall {
Expect(err.Error()).To(ContainSubstring("vesting address cannot be the zero address"))
}
})
}
})
Expand Down Expand Up @@ -521,9 +531,14 @@ var _ = Describe("Interacting with the vesting extension", func() {
clawbackCheck := passCheck.
WithExpEvents(vesting.EventTypeClawback)

_, _, err = contracts.CallContractAndCheckLogs(s.ctx, s.app, clawbackArgs, clawbackCheck)
_, ethRes, err := contracts.CallContractAndCheckLogs(s.ctx, s.app, clawbackArgs, clawbackCheck)
Expect(err).ToNot(HaveOccurred(), "error while calling the contract: %v", err)

10000 var co vesting.ClawbackOutput
err = s.precompile.UnpackIntoInterface(&co, vesting.ClawbackMethod, ethRes.Ret)
Expect(err).ToNot(HaveOccurred(), "error while unpacking the clawback output: %v", err)
Expect(co.Coins).To(Equal(balances), "expected different clawback amount")

balancePost := s.app.BankKeeper.GetBalance(s.ctx, toAddr.Bytes(), s.bondDenom)
Expect(balancePost.Amount.Int64()).To(Equal(int64(100)), "expected only initial balance after clawback")
balanceReceiver := s.app.BankKeeper.GetBalance(s.ctx, differentAddr.Bytes(), s.bondDenom)
Expand Down Expand Up @@ -580,19 +595,20 @@ var _ = Describe("Interacting with the vesting extension", func() {
)

clawbackCheck := execRevertedCheck
// FIXME: error messages in fail check now work differently!
if callType.directCall {
clawbackCheck = failCheck.
WithErrContains("account not subject to clawback")
WithErrContains(vestingtypes.ErrNotSubjectToClawback.Error())
}

_, _, err = contracts.CallContractAndCheckLogs(s.ctx, s.app, clawbackArgs, clawbackCheck)
Expect(err).To(HaveOccurred(), "error while calling the contract: %v", err)
if callType.directCall {
Expect(err.Error()).To(ContainSubstring("account not subject to clawback"))
Expect(err.Error()).To(ContainSubstring("%s: %s", sdk.AccAddress(differentAddr.Bytes()), vestingtypes.ErrNotSubjectToClawback.Error()))
}
})

It(fmt.Sprintf("should no-op when all tokens are vested (%s)", callType.name), func() {
It(fmt.Sprintf("should succeed and return empty Coins when all tokens are vested (%s)", callType.name), func() {
// commit block with time so that vesting has ended
ctx, err := evmosutil.CommitAndCreateNewCtx(s.ctx, s.app, time.Hour*24, nil)
Expect(err).ToNot(HaveOccurred(), "error while committing block: %v", err)
Expand All @@ -609,11 +625,14 @@ var _ = Describe("Interacting with the vesting extension", func() {
s.address,
)

clawbackCheck := failCheck.WithErrContains("has no vesting or lockup periods")

_, _, err = contracts.CallContractAndCheckLogs(s.ctx, s.app, clawbackArgs, clawbackCheck)
_, ethRes, err := contracts.CallContractAndCheckLogs(s.ctx, s.app, clawbackArgs, passCheck)
Expect(err).To(HaveOccurred(), "error while calling the contract: %v", err)

var co vesting.ClawbackOutput
err = s.precompile.UnpackIntoInterface(&co, vesting.ClawbackMethod, ethRes.Ret)
Expect(err).ToNot(HaveOccurred(), "error while unpacking the clawback output: %v", err)
Expect(co.Coins).To(BeEmpty(), "expected empty clawback amount")

balancePost := s.app.BankKeeper.GetBalance(s.ctx, toAddr.Bytes(), s.bondDenom)
Expect(balancePost).To(Equal(balancePre), "expected balance not to have changed")
})
Expand Down Expand Up @@ -731,15 +750,21 @@ var _ = Describe("Interacting with the vesting extension", func() {
if callType.directCall {
updateFunderCheck = failCheck.
WithErrContains(fmt.Sprintf(
"account not subject to clawback: %s",
sdk.AccAddress(nonVestingAddr.Bytes()).String(),
"%s: %s",
sdk.AccAddress(nonVestingAddr.Bytes()),
vestingtypes.ErrNotSubjectToClawback.Error(),
))
}

_, _, err = contracts.CallContractAndCheckLogs(s.ctx, s.app, updateFunderArgs, updateFunderCheck)
Expect(err).To(HaveOccurred(), "error while calling the contract: %v", err)
if callType.directCall {
Expect(err.Error()).To(ContainSubstring("account not subject to clawback"))
Expect(err.Error()).To(
ContainSubstring("%s: %s",
sdk.AccAddress(nonVestingAddr.Bytes()).String(),
vestingtypes.ErrNotSubjectToClawback.Error(),
),
)
}
})

Expand Down Expand Up @@ -806,7 +831,7 @@ var _ = Describe("Interacting with the vesting extension", func() {
_, _, err = contracts.CallContractAndCheckLogs(s.ctx, s.app, updateFunderArgs, updateFunderCheck)
Expect(err).To(HaveOccurred(), "error while updating the funder to a module address: %v", err)
if callType.directCall {
Expect(err.Error()).To(ContainSubstring("is not allowed to receive funds"))
Expect(err.Error()).To(ContainSubstring("is a blocked address and not allowed to fund vesting accounts"))
}
})
}
Expand Down Expand Up @@ -992,7 +1017,7 @@ var _ = Describe("Interacting with the vesting extension", func() {
_, _, err := contracts.CallContractAndCheckLogs(s.ctx, s.app, balancesArgs, balancesCheck)
Expect(err).To(HaveOccurred(), "error while calling the contract: %v", err)
if callType.directCall {
Expect(err.Error()).To(ContainSubstring("NotFound desc = account for address"))
Expect(err.Error()).To(ContainSubstring("account at address '%s' either does not exist or is not a vesting account", sdk.AccAddress(toAddr.Bytes())))
}
})

Expand Down
Loading
0