Test repeat auction bidding (#1159)

* improve error messages

* add tests for re-bidding with small balance
This commit is contained in:
Ruaridh 2022-02-08 16:42:00 +00:00 committed by GitHub
parent 1ccaf2ef06
commit c0f71921d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
package keeper_test package keeper_test
import ( import (
"errors"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -39,6 +38,8 @@ func TestAuctionBidding(t *testing.T) {
collateralAddrs := addrs[2:] collateralAddrs := addrs[2:]
collateralWeights := is(30, 20, 10) collateralWeights := is(30, 20, 10)
initialBalance := cs(c("token1", 1000), c("token2", 1000))
type auctionArgs struct { type auctionArgs struct {
auctionType AuctionType auctionType AuctionType
seller string seller string
@ -330,6 +331,18 @@ func TestAuctionBidding(t *testing.T) {
false, false,
false, false,
}, },
{
"collateral [forward]: bidder replaces previous bid with only funds for difference",
auctionArgs{Collateral, modName, c("token1", 1000), c("token2", 2000), c("debt", 50), collateralAddrs, collateralWeights}, // lot, max bid
[]bidArgs{{buyer, c("token2", 900)}},
bidArgs{buyer, c("token2", 1000)}, // buyer only has enough to cover the increase from previous bid
nil,
someTime.Add(types.DefaultBidDuration),
buyer,
c("token2", 1000),
true,
false,
},
{ {
"collateral [reverse]: normal", "collateral [reverse]: normal",
auctionArgs{Collateral, modName, c("token1", 20), c("token2", 50), c("debt", 50), collateralAddrs, collateralWeights}, // lot, max bid auctionArgs{Collateral, modName, c("token1", 20), c("token2", 50), c("debt", 50), collateralAddrs, collateralWeights}, // lot, max bid
@ -402,6 +415,18 @@ func TestAuctionBidding(t *testing.T) {
false, false,
false, false,
}, },
{
"collateral [reverse]: bidder replaces previous bid without funds",
auctionArgs{Collateral, modName, c("token1", 1000), c("token2", 1000), c("debt", 50), collateralAddrs, collateralWeights}, // lot, max bid
[]bidArgs{{buyer, c("token2", 1000)}},
bidArgs{buyer, c("token1", 100)}, // buyer has already bid all of their token2
nil,
someTime.Add(types.DefaultBidDuration),
buyer,
c("token2", 1000),
true,
false,
},
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
@ -414,11 +439,10 @@ func TestAuctionBidding(t *testing.T) {
modAcc := authtypes.NewModuleAccount(modBaseAcc, modName, []string{authtypes.Minter, authtypes.Burner}...) modAcc := authtypes.NewModuleAccount(modBaseAcc, modName, []string{authtypes.Minter, authtypes.Burner}...)
// Set up normal accounts // Set up normal accounts
coins := cs(c("token1", 1000), c("token2", 1000))
addrs := []sdk.AccAddress{buyer, secondBuyer, collateralAddrs[0], collateralAddrs[1], collateralAddrs[2]} addrs := []sdk.AccAddress{buyer, secondBuyer, collateralAddrs[0], collateralAddrs[1], collateralAddrs[2]}
// Initialize app // Initialize app
authGS := app.NewFundedGenStateWithSameCoinsWithModuleAccount(tApp.AppCodec(), coins, addrs, modAcc) authGS := app.NewFundedGenStateWithSameCoinsWithModuleAccount(tApp.AppCodec(), initialBalance, addrs, modAcc)
params := types.NewParams( params := types.NewParams(
types.DefaultMaxAuctionDuration, types.DefaultMaxAuctionDuration,
types.DefaultBidDuration, types.DefaultBidDuration,
@ -487,7 +511,7 @@ func TestAuctionBidding(t *testing.T) {
// Check success/failure // Check success/failure
if tc.expectPass { if tc.expectPass {
require.Nil(t, err) require.NoError(t, err)
// Check auction was found // Check auction was found
newAuction, found := keeper.GetAuction(ctx, id) newAuction, found := keeper.GetAuction(ctx, id)
require.True(t, found) require.True(t, found)
@ -526,8 +550,8 @@ func TestAuctionBidding(t *testing.T) {
} else { } else {
// Check expected error code type // Check expected error code type
require.NotNil(t, err, "PlaceBid did not return an error") // catch nil values before they cause a panic below require.Error(t, err, "PlaceBid did not return an error")
require.True(t, errors.Is(err, tc.expectedError)) require.ErrorIs(t, err, tc.expectedError)
// Check auction values // Check auction values
newAuction, found := keeper.GetAuction(ctx, id) newAuction, found := keeper.GetAuction(ctx, id)