-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,411 additions
and
348 deletions.
There are no files selected for viewing
1,647 changes: 1,378 additions & 269 deletions
1,647
api/regen/ecocredit/marketplace/v1/tx.pulsar.go
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
x/ecocredit/marketplace/keeper/features/msg_gov_send_from_fee_pool.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Feature: Msg/SendFromFeePool | ||
|
||
Background: | ||
Given recipient "regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68" | ||
|
||
Rule: gov authority must be authorized | ||
Scenario: gov authority is not authorized | ||
Given authority is set to "regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw" | ||
When funds are sent | ||
Then expect error contains "unauthorized" | ||
|
||
Scenario: gov authority is authorized | ||
Given authority is set to the keeper authority | ||
When funds are sent | ||
Then expect no error | ||
|
||
Rule: the fee pool must have enough funds to cover the fee | ||
Background: | ||
Given authority is set to the keeper authority | ||
|
||
Scenario: fee pool is underfunded | ||
Given fee pool balance "100foo" | ||
And send amount "200foo" | ||
When funds are sent | ||
Then expect error contains "insufficient funds" | ||
|
||
Scenario: fee pool is well funded | ||
Given fee pool balance "1000foo" | ||
And send amount "200foo" | ||
When funds are sent | ||
Then expect no error | ||
|
||
Rule: funds are transferred from the fee pool to the recipient | ||
Scenario: funds are transferred | ||
Given authority is set to the keeper authority | ||
Given fee pool balance "1000foo" | ||
And send amount "200foo" | ||
When funds are sent | ||
Then expect no error | ||
And fee pool balance "800foo" | ||
And recipient balance "200foo" |
51 changes: 51 additions & 0 deletions
51
x/ecocredit/marketplace/keeper/features/msg_gov_set_fee_params.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Feature: Msg/SetFeeParams | ||
|
||
Rule: gov authority must be authorized | ||
Background: | ||
Given fee params | ||
""" | ||
{} | ||
""" | ||
|
||
Scenario: gov authority is not authorized | ||
Given authority is set to "regen1elq7ys34gpkj3jyvqee0h6yk4h9wsfxmgqelsw" | ||
When fee params are set | ||
Then expect error contains "unauthorized" | ||
|
||
Scenario: gov authority is authorized | ||
Given authority is set to the keeper authority | ||
When fee params are set | ||
Then expect no error | ||
|
||
Rule: fee params get saved | ||
Scenario: non-empty fee params | ||
Given authority is set to the keeper authority | ||
And fee params | ||
""" | ||
{ | ||
"buyer_percentage_fee": "0.01", | ||
"seller_percentage_fee": "0.01" | ||
} | ||
""" | ||
When fee params are set | ||
Then expect no error | ||
And expect fee params | ||
""" | ||
{ | ||
"buyer_percentage_fee": "0.01", | ||
"seller_percentage_fee": "0.01" | ||
} | ||
""" | ||
|
||
Scenario: empty fee params | ||
Given authority is set to the keeper authority | ||
And fee params | ||
""" | ||
{} | ||
""" | ||
When fee params are set | ||
Then expect no error | ||
And expect fee params | ||
""" | ||
{} | ||
""" |
35 changes: 35 additions & 0 deletions
35
x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
types "github.com/regen-network/regen-ledger/x/ecocredit/v3/marketplace/types/v1" | ||
) | ||
|
||
func (k Keeper) GovSendFromFeePool(ctx context.Context, msg *types.MsgGovSendFromFeePool) (*types.MsgGovSendFromFeePoolResponse, error) { | ||
authority, err := sdk.AccAddressFromBech32(msg.Authority) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !authority.Equals(k.authority) { | ||
return nil, sdkerrors.ErrUnauthorized | ||
} | ||
|
||
recipient, err := sdk.AccAddressFromBech32(msg.Recipient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
amount := types.ToSDKCoins(msg.Amount) | ||
|
||
err = k.bankKeeper.SendCoinsFromModuleToAccount(sdk.UnwrapSDKContext(ctx), k.feePoolName, recipient, amount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgGovSendFromFeePoolResponse{}, nil | ||
} |
107 changes: 107 additions & 0 deletions
107
x/ecocredit/marketplace/keeper/msg_gov_send_from_fee_pool_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/golang/mock/gomock" | ||
"github.com/regen-network/gocuke" | ||
"github.com/stretchr/testify/require" | ||
|
||
types "github.com/regen-network/regen-ledger/x/ecocredit/v3/marketplace/types/v1" | ||
) | ||
|
||
type govSendFromFeePool struct { | ||
*baseSuite | ||
err error | ||
msg *types.MsgGovSendFromFeePool | ||
moduleBalances map[string]sdk.Coins | ||
accountBalances map[string]sdk.Coins | ||
} | ||
|
||
func TestGovSendFromFeePool(t *testing.T) { | ||
gocuke.NewRunner(t, &govSendFromFeePool{}).Path("./features/msg_gov_send_from_fee_pool.feature").Run() | ||
} | ||
|
||
func (s *govSendFromFeePool) Before(t gocuke.TestingT) { | ||
s.baseSuite = setupBase(t, 2) | ||
s.msg = &types.MsgGovSendFromFeePool{} | ||
s.moduleBalances = make(map[string]sdk.Coins) | ||
s.accountBalances = make(map[string]sdk.Coins) | ||
s.bankKeeper.EXPECT(). | ||
SendCoinsFromModuleToAccount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). | ||
AnyTimes(). | ||
DoAndReturn(func(_ sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amount sdk.Coins) error { | ||
newModBalance, neg := s.moduleBalances[senderModule].SafeSub(amount...) | ||
if neg { | ||
return sdkerrors.ErrInsufficientFunds | ||
} | ||
|
||
s.moduleBalances[senderModule] = newModBalance | ||
s.accountBalances[recipientAddr.String()] = s.accountBalances[recipientAddr.String()].Add(amount...) | ||
return nil | ||
}) | ||
} | ||
|
||
func (s *govSendFromFeePool) AuthorityIsSetToTheKeeperAuthority() { | ||
s.msg.Authority = s.k.authority.String() | ||
} | ||
|
||
func (s *govSendFromFeePool) AuthorityIsSetTo(a string) { | ||
s.msg.Authority = a | ||
} | ||
|
||
func (s *govSendFromFeePool) Recipient(a string) { | ||
s.msg.Recipient = a | ||
} | ||
|
||
func (s *govSendFromFeePool) SendAmount(a string) { | ||
coins, err := sdk.ParseCoinsNormalized(a) | ||
require.NoError(s.t, err) | ||
var ptrCoins []*sdk.Coin | ||
for _, coin := range coins { | ||
ptrCoins = append(ptrCoins, &coin) | ||
} | ||
s.msg.Amount = ptrCoins | ||
} | ||
|
||
func (s *govSendFromFeePool) FeePoolBalance(a string) { | ||
coins, err := sdk.ParseCoinsNormalized(a) | ||
require.NoError(s.t, err) | ||
s.moduleBalances[s.k.feePoolName] = coins | ||
} | ||
|
||
func (s *govSendFromFeePool) RecipientBalance(a string) { | ||
coins, err := sdk.ParseCoinsNormalized(a) | ||
require.NoError(s.t, err) | ||
s.accountBalances[s.msg.Recipient] = coins | ||
} | ||
|
||
func (s *govSendFromFeePool) FundsAreSent() { | ||
_, s.err = s.k.GovSendFromFeePool(s.ctx, s.msg) | ||
} | ||
|
||
func (s *govSendFromFeePool) ExpectErrorContains(a string) { | ||
if s.err != nil { | ||
require.ErrorContains(s.t, s.err, a) | ||
} else { | ||
require.NoError(s.t, s.err) | ||
} | ||
} | ||
|
||
func (s *govSendFromFeePool) ExpectNoError() { | ||
require.NoError(s.t, s.err) | ||
} | ||
|
||
func (s *govSendFromFeePool) ExpectFeePoolBalance(a string) { | ||
coins, err := sdk.ParseCoinsNormalized(a) | ||
require.NoError(s.t, err) | ||
require.True(s.t, coins.IsEqual(s.moduleBalances[s.k.feePoolName])) | ||
} | ||
|
||
func (s *govSendFromFeePool) ExpectRecipientBalance(a string) { | ||
coins, err := sdk.ParseCoinsNormalized(a) | ||
require.NoError(s.t, err) | ||
require.True(s.t, coins.IsEqual(s.accountBalances[s.msg.Recipient])) | ||
} |
Oops, something went wrong.