mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
Test repeat auction bidding (#1159)
* improve error messages * add tests for re-bidding with small balance
This commit is contained in:
parent
1ccaf2ef06
commit
c0f71921d9
@ -1,7 +1,6 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -39,6 +38,8 @@ func TestAuctionBidding(t *testing.T) {
|
||||
collateralAddrs := addrs[2:]
|
||||
collateralWeights := is(30, 20, 10)
|
||||
|
||||
initialBalance := cs(c("token1", 1000), c("token2", 1000))
|
||||
|
||||
type auctionArgs struct {
|
||||
auctionType AuctionType
|
||||
seller string
|
||||
@ -330,6 +331,18 @@ func TestAuctionBidding(t *testing.T) {
|
||||
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",
|
||||
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,
|
||||
},
|
||||
{
|
||||
"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 {
|
||||
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}...)
|
||||
|
||||
// Set up normal accounts
|
||||
coins := cs(c("token1", 1000), c("token2", 1000))
|
||||
addrs := []sdk.AccAddress{buyer, secondBuyer, collateralAddrs[0], collateralAddrs[1], collateralAddrs[2]}
|
||||
|
||||
// Initialize app
|
||||
authGS := app.NewFundedGenStateWithSameCoinsWithModuleAccount(tApp.AppCodec(), coins, addrs, modAcc)
|
||||
authGS := app.NewFundedGenStateWithSameCoinsWithModuleAccount(tApp.AppCodec(), initialBalance, addrs, modAcc)
|
||||
params := types.NewParams(
|
||||
types.DefaultMaxAuctionDuration,
|
||||
types.DefaultBidDuration,
|
||||
@ -487,7 +511,7 @@ func TestAuctionBidding(t *testing.T) {
|
||||
|
||||
// Check success/failure
|
||||
if tc.expectPass {
|
||||
require.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
// Check auction was found
|
||||
newAuction, found := keeper.GetAuction(ctx, id)
|
||||
require.True(t, found)
|
||||
@ -526,8 +550,8 @@ func TestAuctionBidding(t *testing.T) {
|
||||
|
||||
} else {
|
||||
// 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.True(t, errors.Is(err, tc.expectedError))
|
||||
require.Error(t, err, "PlaceBid did not return an error")
|
||||
require.ErrorIs(t, err, tc.expectedError)
|
||||
|
||||
// Check auction values
|
||||
newAuction, found := keeper.GetAuction(ctx, id)
|
||||
|
Loading…
Reference in New Issue
Block a user