Skip to content

Commit

Permalink
Merge pull request #52 from bze-alphateam/hotfix/queue-checker
Browse files Browse the repository at this point in the history
Hotfix/queue checker
  • Loading branch information
faneaatiku authored Oct 12, 2024
2 parents 49feb49 + 972edb3 commit bf4be92
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app

import (
"github.com/bze-alphateam/bze/app/openapi"
v710 "github.com/bze-alphateam/bze/app/upgrades/v710"
v711 "github.com/bze-alphateam/bze/app/upgrades/v711"
"github.com/bze-alphateam/bze/x/epochs"
epochskeeper "github.com/bze-alphateam/bze/x/epochs/keeper"
epochstypes "github.com/bze-alphateam/bze/x/epochs/types"
Expand Down Expand Up @@ -710,8 +710,8 @@ func New(

func (app *App) setupUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
v710.UpgradeName,
v710.CreateUpgradeHandler(cfg, app.mm),
v711.UpgradeName,
v711.CreateUpgradeHandler(cfg, app.mm),
)
}

Expand Down
16 changes: 16 additions & 0 deletions app/upgrades/v711/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package v711

import (
"github.com/bze-alphateam/bze/app/upgrades"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const UpgradeName = "v7.1.1"

func CreateUpgradeHandler(
_ module.Configurator,
_ *module.Manager,
) upgradetypes.UpgradeHandler {
return upgrades.EmptyUpgradeHandler()
}
6 changes: 3 additions & 3 deletions testutil/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package simapp

import (
"github.com/bze-alphateam/bze/app/openapi"
v710 "github.com/bze-alphateam/bze/app/upgrades/v710"
v711 "github.com/bze-alphateam/bze/app/upgrades/v711"
"github.com/bze-alphateam/bze/x/epochs"
epochskeeper "github.com/bze-alphateam/bze/x/epochs/keeper"
epochstypes "github.com/bze-alphateam/bze/x/epochs/types"
Expand Down Expand Up @@ -710,8 +710,8 @@ func New(

func (app *SimApp) setupUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
v710.UpgradeName,
v710.CreateUpgradeHandler(cfg, app.mm),
v711.UpgradeName,
v711.CreateUpgradeHandler(cfg, app.mm),
)
}

Expand Down
3 changes: 3 additions & 0 deletions x/burner/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/bze-alphateam/bze/testutil/simapp"
"github.com/bze-alphateam/bze/x/burner/keeper"
"github.com/bze-alphateam/bze/x/burner/types"
epochskeeper "github.com/bze-alphateam/bze/x/epochs/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand All @@ -18,6 +19,7 @@ type IntegrationTestSuite struct {
ctx sdk.Context
k *keeper.Keeper
msgServer types.MsgServer
ek *epochskeeper.Keeper
}

func (suite *IntegrationTestSuite) SetupTest() {
Expand All @@ -28,6 +30,7 @@ func (suite *IntegrationTestSuite) SetupTest() {
suite.ctx = ctx

suite.k = &app.BurnerKeeper
suite.ek = &app.EpochsKeeper
suite.msgServer = keeper.NewMsgServerImpl(app.BurnerKeeper)
}

Expand Down
2 changes: 1 addition & 1 deletion x/burner/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (k msgServer) JoinRaffle(goCtx context.Context, msg *types.MsgJoinRaffle) (
}

//do not allow participants to join close to expiration
if raffle.EndAt <= (k.GetRaffleCurrentEpoch(ctx) - (raffleDelayHeight + 1)) {
if raffle.EndAt <= (k.GetRaffleCurrentEpoch(ctx) - 1) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "raffle has expired")
}

Expand Down
16 changes: 8 additions & 8 deletions x/burner/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,21 +724,21 @@ func (suite *IntegrationTestSuite) TestJoinRaffle_Stress() {
func (suite *IntegrationTestSuite) TestJoinRaffle_Simulation() {
goCtx := sdk.WrapSDKContext(suite.ctx)

addr1 := sdk.AccAddress("addr1_______________")
addr2 := sdk.AccAddress("addr2_______________")
addr1 := sdk.AccAddress("addr13___20______")
addr2 := sdk.AccAddress("addr2__5__9______")
initialBalanceAmount := sdk.NewInt(1_000_000_000_000_000)
balances := sdk.NewCoins(sdk.NewInt64Coin("aau", initialBalanceAmount.Int64()))
suite.Require().NoError(simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr1, balances))
suite.Require().NoError(simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr2, balances))

potInt := sdk.NewInt(50_000_000_000)
ticketCost := sdk.NewInt(10_000_000)
suite.ek.BeginBlocker(suite.ctx)
potInt := sdk.NewInt(200_000_000_000)
ticketCost := sdk.NewInt(25_000_000)
msg := types.MsgStartRaffle{
Creator: addr1.String(),
Pot: potInt.String(),
Duration: "1",
Duration: "14",
Chances: "100",
Ratio: "0.15",
Ratio: "0.50",
TicketPrice: ticketCost.String(),
Denom: "aau",
}
Expand All @@ -760,7 +760,7 @@ func (suite *IntegrationTestSuite) TestJoinRaffle_Simulation() {

winCount := 0
ticketsStart := time.Now().Unix()
ticketsToPlace := int64(10000)
ticketsToPlace := int64(50000)
totalPotWon := sdk.ZeroInt()

for i := ticketsStart; i < ticketsStart+ticketsToPlace; i++ {
Expand Down
8 changes: 4 additions & 4 deletions x/tradebin/keeper/msg_server_create_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (k msgServer) checkPrice(ctx sdk.Context, msg *types.MsgCreateOrder) error
return fmt.Errorf("could not parse current price: %s", msg.Price)
}

err = k.checkPriceInQueueMessages(ctx, msg.OrderType, &currentPrice)
err = k.checkPriceInQueueMessages(ctx, msg, &currentPrice)
if err != nil {
return err
}
Expand Down Expand Up @@ -219,13 +219,13 @@ func (k Keeper) checkPriceInOrderBook(ctx sdk.Context, msg *types.MsgCreateOrder
return nil
}

func (k Keeper) checkPriceInQueueMessages(ctx sdk.Context, msgType string, currentPrice *sdk.Dec) error {
oppositeType := types.TheOtherOrderType(msgType)
func (k Keeper) checkPriceInQueueMessages(ctx sdk.Context, msg *types.MsgCreateOrder, currentPrice *sdk.Dec) error {
oppositeType := types.TheOtherOrderType(msg.OrderType)
queueMessages := k.GetAllQueueMessage(ctx)
msgsPrice := sdk.ZeroDec()
for _, queueMessage := range queueMessages {
//check against MessageType because we have "cancel" type besides "buy" and "sell"
if queueMessage.MessageType != oppositeType {
if queueMessage.MarketId != msg.MarketId || queueMessage.MessageType != oppositeType {
continue
}

Expand Down

0 comments on commit bf4be92

Please sign in to comment.