code.vegaprotocol.io/vega@v0.79.0/core/matching/2385_panic_in_leave_opening_auction_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package matching
    17  
    18  import (
    19  	"testing"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	"code.vegaprotocol.io/vega/libs/num"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  func TestPanicInLeaveAuction(t *testing.T) {
    29  	market := "testMarket"
    30  	book := getTestOrderBook(t, market)
    31  	defer book.Finish()
    32  	orders := []types.Order{
    33  		{
    34  			MarketID:    market,
    35  			Party:       "A",
    36  			Side:        types.SideBuy,
    37  			Price:       num.NewUint(100),
    38  			Size:        5,
    39  			Remaining:   5,
    40  			TimeInForce: types.OrderTimeInForceGTC,
    41  			Type:        types.OrderTypeLimit,
    42  			ID:          "v0000000000000-0000001",
    43  		},
    44  		{
    45  			MarketID:    market,
    46  			Party:       "B",
    47  			Side:        types.SideSell,
    48  			Price:       num.NewUint(100),
    49  			Size:        5,
    50  			Remaining:   5,
    51  			TimeInForce: types.OrderTimeInForceGTC,
    52  			Type:        types.OrderTypeLimit,
    53  			ID:          "v0000000000000-0000002",
    54  		},
    55  		{
    56  			MarketID:    market,
    57  			Party:       "C",
    58  			Side:        types.SideBuy,
    59  			Price:       num.NewUint(150),
    60  			Size:        2,
    61  			Remaining:   2,
    62  			TimeInForce: types.OrderTimeInForceGTC,
    63  			Type:        types.OrderTypeLimit,
    64  			ID:          "v0000000000000-0000003",
    65  		},
    66  		{
    67  			MarketID:    market,
    68  			Party:       "D",
    69  			Side:        types.SideBuy,
    70  			Price:       num.NewUint(150),
    71  			Size:        2,
    72  			Remaining:   2,
    73  			TimeInForce: types.OrderTimeInForceGTC,
    74  			Type:        types.OrderTypeLimit,
    75  			ID:          "v0000000000000-0000004",
    76  		},
    77  		{
    78  			MarketID:    market,
    79  			Party:       "E",
    80  			Side:        types.SideSell,
    81  			Price:       num.NewUint(150),
    82  			Size:        2,
    83  			Remaining:   2,
    84  			TimeInForce: types.OrderTimeInForceGTC,
    85  			Type:        types.OrderTypeLimit,
    86  			ID:          "v0000000000000-0000005",
    87  		},
    88  		{
    89  			MarketID:    market,
    90  			Party:       "F",
    91  			Side:        types.SideBuy,
    92  			Price:       num.NewUint(150),
    93  			Size:        2,
    94  			Remaining:   2,
    95  			TimeInForce: types.OrderTimeInForceGTC,
    96  			Type:        types.OrderTypeLimit,
    97  			ID:          "v0000000000000-0000006",
    98  		},
    99  		{
   100  			MarketID:    market,
   101  			Party:       "G",
   102  			Side:        types.SideSell,
   103  			Price:       num.NewUint(150),
   104  			Size:        2,
   105  			Remaining:   2,
   106  			TimeInForce: types.OrderTimeInForceGTC,
   107  			Type:        types.OrderTypeLimit,
   108  			ID:          "v0000000000000-0000007",
   109  		},
   110  		{
   111  			MarketID:    market,
   112  			Party:       "A",
   113  			Side:        types.SideBuy,
   114  			Price:       num.NewUint(120),
   115  			Size:        33,
   116  			Remaining:   33,
   117  			TimeInForce: types.OrderTimeInForceGTC,
   118  			Type:        types.OrderTypeLimit,
   119  			ID:          "v0000000000000-0000008",
   120  		},
   121  	}
   122  
   123  	// enter auction, should return no error and no orders
   124  	cnlorders := book.EnterAuction()
   125  	assert.Len(t, cnlorders, 0)
   126  
   127  	for _, o := range orders {
   128  		o := o
   129  		o.OriginalPrice = o.Price.Clone()
   130  		cnf, err := book.SubmitOrder(&o)
   131  		assert.NoError(t, err)
   132  		assert.Len(t, cnf.Trades, 0)
   133  		assert.Len(t, cnf.PassiveOrdersAffected, 0)
   134  	}
   135  
   136  	cnf, porders, err := book.LeaveAuction(time.Now())
   137  	assert.NoError(t, err)
   138  	_ = cnf
   139  	_ = porders
   140  }