Skip to content

Commit

Permalink
fix launch hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 16, 2024
1 parent 1f3c57e commit 4ca2d1b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
30 changes: 30 additions & 0 deletions x/launch/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper

import (
"context"

"github.com/ignite/network/x/launch/types"
)

// Implements LaunchHooks interface
var _ types.LaunchHooks = Keeper{}

// RequestCreated calls associated hook if registered
func (k Keeper) RequestCreated(
ctx context.Context,
creator string,
launchID,
requestID uint64,
content types.RequestContent,
) error {
if k.hooks == nil {
return types.ErrHookNotImplemented
}
return k.hooks.RequestCreated(
ctx,
creator,
launchID,
requestID,
content,
)
}
2 changes: 1 addition & 1 deletion x/launch/keeper/msg_server_send_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (k msgServer) SendRequest(ctx context.Context, msg *types.MsgSendRequest) (
}

// call request created hook
err = k.hooks.RequestCreated(ctx, msg.Creator, msg.LaunchID, request.RequestID, msg.Content)
err = k.RequestCreated(ctx, msg.Creator, msg.LaunchID, request.RequestID, msg.Content)
return &types.MsgSendRequestResponse{
RequestID: request.RequestID,
AutoApproved: approved,
Expand Down
1 change: 1 addition & 0 deletions x/launch/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ var (
ErrInvalidModuleName = sdkerrors.Register(ModuleName, 1136, "invalid module name")
ErrInvalidParamName = sdkerrors.Register(ModuleName, 1137, "invalid param name")
ErrChainNotFound = sdkerrors.Register(ModuleName, 1138, "chain not found for launch id")
ErrHookNotImplemented = sdkerrors.Register(ModuleName, 1139, "launch hooks not implemented")
)
29 changes: 13 additions & 16 deletions x/project/keeper/msg_server_redeem_vouchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ func TestMsgRedeemVouchers(t *testing.T) {
existAddr = sample.AccAddress(r)
project = sample.Project(r, 0)
projectMainnetLaunched = sample.Project(r, 1)
shares types.Shares
vouchers sdk.Coins
err error
vouchersTooBig = sdk.NewCoins(
sdk.NewCoin("v/0/foo", sdkmath.NewInt(networktypes.TotalShareNumber+1)),
)
)

t.Run("should allow creation of valid shares", func(t *testing.T) {
shares, err = types.NewShares("1000foo,500bar,300foobar")
require.NoError(t, err)
})
shares, err := types.NewShares("1000foo,500bar,300foobar")
require.NoError(t, err)

// Set projects
project.AllocatedShares = shares
Expand All @@ -51,10 +46,12 @@ func TestMsgRedeemVouchers(t *testing.T) {
projectMainnetLaunched.ProjectID, err = tk.ProjectKeeper.AppendProject(ctx, projectMainnetLaunched)
require.NoError(t, err)

t.Run("should allow creation of valid vouchers", func(t *testing.T) {
vouchers, err = types.SharesToVouchers(shares, project.ProjectID)
require.NoError(t, err)
})
vouchers, err := types.SharesToVouchers(shares, project.ProjectID)
require.NoError(t, err)

invalidProjectID := uint64(10000)
vouchersErr, err := types.SharesToVouchers(shares, invalidProjectID)
require.NoError(t, err)

t.Run("should allow setting test balances", func(t *testing.T) {
err = tk.BankKeeper.MintCoins(ctx, types.ModuleName, vouchers)
Expand Down Expand Up @@ -120,8 +117,8 @@ func TestMsgRedeemVouchers(t *testing.T) {
msg: types.MsgRedeemVouchers{
Sender: addr.String(),
Account: addr.String(),
ProjectID: 10000,
Vouchers: sample.Coins(r),
ProjectID: invalidProjectID,
Vouchers: vouchersErr,
},
err: types.ErrProjectNotFound,
},
Expand All @@ -131,7 +128,7 @@ func TestMsgRedeemVouchers(t *testing.T) {
Sender: addr.String(),
Account: addr.String(),
ProjectID: project.ProjectID,
Vouchers: sample.Coins(r),
Vouchers: vouchersErr,
},
err: ignterrors.ErrCritical,
},
Expand All @@ -143,7 +140,7 @@ func TestMsgRedeemVouchers(t *testing.T) {
ProjectID: project.ProjectID,
Vouchers: vouchers,
},
err: ignterrors.ErrCritical,
err: types.ErrInvalidSigner,
},
{
name: "should fail with insufficient funds",
Expand Down Expand Up @@ -182,7 +179,7 @@ func TestMsgRedeemVouchers(t *testing.T) {
Sender: addr.String(),
Account: addr.String(),
ProjectID: projectMainnetLaunched.ProjectID,
Vouchers: sample.Coins(r),
Vouchers: vouchers,
},
err: types.ErrMainnetLaunchTriggered,
},
Expand Down
4 changes: 3 additions & 1 deletion x/project/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func TestMsgUpdateParams(t *testing.T) {
name: "send enabled param",
input: &types.MsgUpdateParams{
Authority: k.GetAuthority(),
Params: types.Params{},
Params: types.Params{
TotalSupplyRange: types.DefaultTotalSupplyRange(),
},
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions x/project/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func NewTotalSupplyRange(minTotalSupply, maxTotalSupply sdkmath.Int) TotalSupply
}
}

// DefaultTotalSupplyRange returns default total supply range.
func DefaultTotalSupplyRange() TotalSupplyRange {
return NewTotalSupplyRange(
DefaultMinTotalSupply,
DefaultMaxTotalSupply,
)
}

// NewParams creates a new Params instance
func NewParams(
minTotalSupply,
Expand Down

0 comments on commit 4ca2d1b

Please sign in to comment.