-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for queries and msg servers and fixed bugs
- Loading branch information
1 parent
9fa71eb
commit 3eb65d3
Showing
18 changed files
with
1,004 additions
and
387 deletions.
There are no files selected for viewing
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,32 @@ | ||
package keeper_test | ||
|
||
func (suite *IntegrationTestSuite) TestCounter() { | ||
key := []byte("test") | ||
initial := suite.k.GetCounter(suite.ctx, key) | ||
suite.Require().Equal(initial, uint64(0)) | ||
|
||
suite.k.SetCounter(suite.ctx, key, 2) | ||
|
||
counter := suite.k.GetCounter(suite.ctx, key) | ||
suite.Require().Equal(counter, uint64(2)) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestStakingRewardsCounter() { | ||
initial := suite.k.GetStakingRewardsCounter(suite.ctx) | ||
suite.Require().Equal(initial, uint64(0)) | ||
|
||
suite.k.SetStakingRewardsCounter(suite.ctx, uint64(2323)) | ||
|
||
counter := suite.k.GetStakingRewardsCounter(suite.ctx) | ||
suite.Require().Equal(counter, uint64(2323)) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestTradingRewardsCounter() { | ||
initial := suite.k.GetTradingRewardsCounter(suite.ctx) | ||
suite.Require().Equal(initial, uint64(0)) | ||
|
||
suite.k.SetTradingRewardsCounter(suite.ctx, uint64(2323)) | ||
|
||
counter := suite.k.GetTradingRewardsCounter(suite.ctx) | ||
suite.Require().Equal(counter, uint64(2323)) | ||
} |
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,75 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
) | ||
|
||
func (suite *IntegrationTestSuite) TestHandleActivateTradingRewardProposal_AlreadyActiveError() { | ||
tr := types.TradingReward{RewardId: "123"} | ||
suite.k.SetActiveTradingReward(suite.ctx, tr) | ||
|
||
prop := types.ActivateTradingRewardProposal{ | ||
Title: "", | ||
Description: "", | ||
RewardId: tr.RewardId, | ||
} | ||
|
||
suite.Require().Error(suite.k.HandleActivateTradingRewardProposal(suite.ctx, &prop)) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestHandleActivateTradingRewardProposal_TradingRewardNotFoundError() { | ||
prop := types.ActivateTradingRewardProposal{ | ||
Title: "", | ||
Description: "", | ||
RewardId: "0", | ||
} | ||
|
||
suite.Require().Error(suite.k.HandleActivateTradingRewardProposal(suite.ctx, &prop)) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestHandleActivateTradingRewardProposal_Success() { | ||
tr := types.TradingReward{ | ||
RewardId: "123", | ||
ExpireAt: 123, | ||
MarketId: "da", | ||
} | ||
suite.k.SetPendingTradingReward(suite.ctx, tr) | ||
|
||
trExp := types.TradingRewardExpiration{ | ||
RewardId: tr.RewardId, | ||
ExpireAt: tr.ExpireAt, | ||
} | ||
suite.k.SetPendingTradingRewardExpiration(suite.ctx, trExp) | ||
|
||
prop := types.ActivateTradingRewardProposal{ | ||
Title: "", | ||
Description: "", | ||
RewardId: tr.RewardId, | ||
} | ||
|
||
suite.Require().NoError(suite.k.HandleActivateTradingRewardProposal(suite.ctx, &prop)) | ||
|
||
//check the reward is not in pending anymore | ||
_, found := suite.k.GetPendingTradingReward(suite.ctx, tr.RewardId) | ||
suite.Require().False(found) | ||
|
||
//check the expiration does not exist | ||
allPendingExp := suite.k.GetAllPendingTradingRewardExpiration(suite.ctx) | ||
suite.Require().Empty(allPendingExp) | ||
|
||
//check it is active | ||
activeTr, found := suite.k.GetActiveTradingReward(suite.ctx, tr.RewardId) | ||
suite.Require().True(found) | ||
//check the expire at was modified in the document | ||
suite.Require().NotEqual(activeTr.ExpireAt, tr.ExpireAt) | ||
|
||
//check there's an active exp | ||
allActiveExp := suite.k.GetAllActiveTradingRewardExpiration(suite.ctx) | ||
suite.Require().Equal(len(allActiveExp), 1) | ||
//check the reward id exists in active exp | ||
suite.Require().Equal(allActiveExp[0].RewardId, tr.RewardId) | ||
|
||
//check we can find the TR by market id | ||
_, found = suite.k.GetMarketIdRewardId(suite.ctx, tr.MarketId) | ||
suite.Require().True(found) | ||
} |
25 changes: 0 additions & 25 deletions
25
x/rewards/keeper/grpc_query_get_market_id_trading_reward_id_handler.go
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
x/rewards/keeper/grpc_query_get_trading_reward_leaderboard.go
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
testkeeper "github.com/bze-alphateam/bze/testutil/keeper" | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParamsQuery(t *testing.T) { | ||
keeper, ctx := testkeeper.RewardsKeeper(t) | ||
wctx := sdk.WrapSDKContext(ctx) | ||
params := types.DefaultParams() | ||
keeper.SetParams(ctx, params) | ||
func (suite *IntegrationTestSuite) TestQueryGetParams_InvalidRequest() { | ||
goCtx := sdk.WrapSDKContext(suite.ctx) | ||
_, err := suite.k.Params(goCtx, nil) | ||
suite.Require().Error(err) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestQueryGetParams_Success() { | ||
goCtx := sdk.WrapSDKContext(suite.ctx) | ||
|
||
resp, err := suite.k.Params(goCtx, &types.QueryParamsRequest{}) | ||
suite.Require().NoError(err) | ||
|
||
response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) | ||
require.NoError(t, err) | ||
require.Equal(t, &types.QueryParamsResponse{Params: params}, response) | ||
def := types.DefaultGenesis() | ||
suite.Require().Equal(resp.Params, def.GetParams()) | ||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.