Skip to content

Commit

Permalink
fix coin transfer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Apr 18, 2024
1 parent ce11e1c commit 7b94d3e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion x/badges/keeper/approved_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func (k Keeper) DeductAndGetUserApprovals(
for _, coin := range toTransfer {
newCoins, underflow := spendableCoins.SafeSub(*coin)
if underflow {

underflows = true
}
spendableCoins = newCoins
Expand Down
38 changes: 19 additions & 19 deletions x/badges/keeper/approved_transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ func (suite *TestSuite) TestCoinTransfersWithApprovals() {
err := CreateCollections(suite, wctx, collectionsToCreate)
suite.Require().Nil(err, "error creating badges")

bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(1000), bobBalanceBefore.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(0), aliceBalanceBefore.Amount, "Error deducting outgoing approvals")

Expand All @@ -658,8 +658,8 @@ func (suite *TestSuite) TestCoinTransfersWithApprovals() {
})
suite.Require().Nil(err, "Error deducting outgoing approvals")

bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(900), bobBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), aliceBalanceAfter.Amount, "Error deducting outgoing approvals")

Expand Down Expand Up @@ -687,8 +687,8 @@ func (suite *TestSuite) TestCoinTransfersWithApprovalsUnderflow() {
err := CreateCollections(suite, wctx, collectionsToCreate)
suite.Require().Nil(err, "error creating badges")

bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(1000), bobBalanceBefore.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(0), aliceBalanceBefore.Amount, "Error deducting outgoing approvals")

Expand All @@ -711,8 +711,8 @@ func (suite *TestSuite) TestCoinTransfersWithApprovalsUnderflow() {
})
suite.Require().Error(err, "Error deducting outgoing approvals")

bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(1000), bobBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(0), aliceBalanceAfter.Amount, "Error deducting outgoing approvals")
}
Expand Down Expand Up @@ -748,8 +748,8 @@ func (suite *TestSuite) TestCoinTransfersWithApprovalsMultiple() {
err := CreateCollections(suite, wctx, collectionsToCreate)
suite.Require().Nil(err, "error creating badges")

bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(1000), bobBalanceBefore.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(0), aliceBalanceBefore.Amount, "Error deducting outgoing approvals")

Expand All @@ -772,11 +772,11 @@ func (suite *TestSuite) TestCoinTransfersWithApprovalsMultiple() {
})
suite.Require().Nil(err, "Error deducting outgoing approvals")

bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(800), bobBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), aliceBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(charlie), "badge").Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(charlie), "badge").Amount, "Error deducting outgoing approvals")
}

func (suite *TestSuite) TestCoinTransfersWithOverflowIntoNextApprovals() {
Expand Down Expand Up @@ -840,8 +840,8 @@ func (suite *TestSuite) TestCoinTransfersWithOverflowIntoNextApprovals() {
err := CreateCollections(suite, wctx, collectionsToCreate)
suite.Require().Nil(err, "error creating badges")

bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceBefore := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(1000), bobBalanceBefore.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(0), aliceBalanceBefore.Amount, "Error deducting outgoing approvals")

Expand All @@ -863,7 +863,7 @@ func (suite *TestSuite) TestCoinTransfersWithOverflowIntoNextApprovals() {
},
})
suite.Require().Nil(err, "Error deducting outgoing approvals")

err = TransferBadges(suite, wctx, &types.MsgTransferBadges{
Creator: bob,
CollectionId: sdkmath.NewUint(1),
Expand All @@ -883,9 +883,9 @@ func (suite *TestSuite) TestCoinTransfersWithOverflowIntoNextApprovals() {
})
suite.Require().Nil(err, "Error deducting outgoing approvals")

bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(alice), "badge")
bobBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(bob), "badge")
aliceBalanceAfter := suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(alice), "badge")
suite.Require().Equal(sdk.NewInt(700), bobBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(200), aliceBalanceAfter.Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), suite.app.BankKeeper.GetBalance(suite.ctx, sdk.AccAddress(charlie), "badge").Amount, "Error deducting outgoing approvals")
suite.Require().Equal(sdk.NewInt(100), suite.app.BankKeeper.GetBalance(suite.ctx, sdk.MustAccAddressFromBech32(charlie), "badge").Amount, "Error deducting outgoing approvals")
}
2 changes: 1 addition & 1 deletion x/badges/keeper/grpc_query_get_approvals_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) GetApprovalTracker(goCtx context.Context, req *types.QueryGetApp
}

ctx := sdk.UnwrapSDKContext(goCtx)
// collectionId math.Uint, addressForApproval string, amountTrackerId string, level string, trackerType string, address string)

address, found := k.GetApprovalTrackerFromStore(ctx, req.CollectionId, req.ApproverAddress, req.ApprovalId, req.AmountTrackerId, req.ApprovalLevel, req.TrackerType, req.ApprovedAddress)
if !found {
return nil, status.Error(codes.InvalidArgument, "invalid request")
Expand Down
2 changes: 1 addition & 1 deletion x/badges/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (suite *TestSuite) SetupTest() {
// suite.app.AccountKeeper.SetAccount(suite.ctx, suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, sdk.AccAddress([]byte{byte(i)})))
// }

banktestutil.FundAccount(suite.app.BankKeeper, suite.ctx, sdk.AccAddress(bob), sdk.NewCoins(sdk.NewInt64Coin("badge", 1000)))
banktestutil.FundAccount(suite.app.BankKeeper, suite.ctx, sdk.MustAccAddressFromBech32(bob), sdk.NewCoins(sdk.NewInt64Coin("badge", 1000)))
}

func TestBadgesKeeperTestSuite(t *testing.T) {
Expand Down

0 comments on commit 7b94d3e

Please sign in to comment.