code.vegaprotocol.io/vega@v0.79.0/core/matching/invalidorders_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  
    21  	"code.vegaprotocol.io/vega/core/types"
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  )
    26  
    27  func TestOrderBookInvalid_emptyMarketID(t *testing.T) {
    28  	market := "testMarket"
    29  	book := getTestOrderBook(t, market)
    30  	defer book.Finish()
    31  	order := types.Order{
    32  		MarketID:    "",
    33  		Party:       "A",
    34  		Side:        types.SideBuy,
    35  		Price:       num.NewUint(100),
    36  		Size:        1,
    37  		Remaining:   1,
    38  		TimeInForce: types.OrderTimeInForceGTC,
    39  		Type:        types.OrderTypeLimit,
    40  	}
    41  	confirm, err := book.SubmitOrder(&order)
    42  	assert.Equal(t, types.ErrInvalidMarketID, err)
    43  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
    44  }
    45  
    46  func TestOrderBookInvalid_emptyPartyID(t *testing.T) {
    47  	market := "testMarket"
    48  	book := getTestOrderBook(t, market)
    49  	defer book.Finish()
    50  	order := types.Order{
    51  		MarketID:    market,
    52  		Party:       "",
    53  		Side:        types.SideBuy,
    54  		Price:       num.NewUint(100),
    55  		Size:        1,
    56  		Remaining:   1,
    57  		TimeInForce: types.OrderTimeInForceGTC,
    58  		Type:        types.OrderTypeLimit,
    59  	}
    60  	confirm, err := book.SubmitOrder(&order)
    61  	assert.Equal(t, types.ErrInvalidPartyID, err)
    62  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
    63  }
    64  
    65  func TestOrderBookInvalid_ZeroSize(t *testing.T) {
    66  	market := "testMarket"
    67  	book := getTestOrderBook(t, market)
    68  	defer book.Finish()
    69  	order := types.Order{
    70  		MarketID:    market,
    71  		Party:       "A",
    72  		Side:        types.SideBuy,
    73  		Price:       num.NewUint(100),
    74  		Size:        0,
    75  		Remaining:   0,
    76  		TimeInForce: types.OrderTimeInForceGTC,
    77  		Type:        types.OrderTypeLimit,
    78  	}
    79  	confirm, err := book.SubmitOrder(&order)
    80  	assert.Equal(t, types.ErrInvalidRemainingSize, err)
    81  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
    82  }
    83  
    84  func TestOrderBookInvalid_ZeroPrice(t *testing.T) {
    85  	market := "testMarket"
    86  	book := getTestOrderBook(t, market)
    87  	defer book.Finish()
    88  	order := types.Order{
    89  		MarketID:    market,
    90  		Party:       "A",
    91  		Side:        types.SideBuy,
    92  		Price:       num.UintZero(),
    93  		Size:        1,
    94  		Remaining:   1,
    95  		TimeInForce: types.OrderTimeInForceGTC,
    96  		Type:        types.OrderTypeLimit,
    97  	}
    98  	confirm, err := book.SubmitOrder(&order)
    99  	assert.NoError(t, err)
   100  	assert.Equal(t, uint64(0), confirm.Order.Price.Uint64())
   101  }
   102  
   103  func TestOrderBookInvalid_RemainingTooBig(t *testing.T) {
   104  	market := "testMarket"
   105  	book := getTestOrderBook(t, market)
   106  	defer book.Finish()
   107  	order := types.Order{
   108  		MarketID:    market,
   109  		Party:       "A",
   110  		Side:        types.SideBuy,
   111  		Price:       num.NewUint(100),
   112  		Size:        10,
   113  		Remaining:   11,
   114  		TimeInForce: types.OrderTimeInForceGTC,
   115  		Type:        types.OrderTypeLimit,
   116  	}
   117  	confirm, err := book.SubmitOrder(&order)
   118  	assert.Equal(t, types.ErrInvalidRemainingSize, err)
   119  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   120  }
   121  
   122  func TestOrderBookInvalid_GTCMarket(t *testing.T) {
   123  	market := "testMarket"
   124  	book := getTestOrderBook(t, market)
   125  	defer book.Finish()
   126  	order := types.Order{
   127  		MarketID:    market,
   128  		Party:       "A",
   129  		Side:        types.SideBuy,
   130  		Price:       num.NewUint(100),
   131  		Size:        10,
   132  		Remaining:   10,
   133  		TimeInForce: types.OrderTimeInForceGTC,
   134  		Type:        types.OrderTypeMarket,
   135  	}
   136  	confirm, err := book.SubmitOrder(&order)
   137  	assert.Equal(t, types.ErrInvalidPersistence, err)
   138  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   139  }
   140  
   141  func TestOrderBookInvalid_GTCNetwork(t *testing.T) {
   142  	market := "testMarket"
   143  	book := getTestOrderBook(t, market)
   144  	defer book.Finish()
   145  	order := types.Order{
   146  		MarketID:    market,
   147  		Party:       "A",
   148  		Side:        types.SideBuy,
   149  		Price:       num.NewUint(100),
   150  		Size:        10,
   151  		Remaining:   10,
   152  		TimeInForce: types.OrderTimeInForceGTC,
   153  		Type:        types.OrderTypeNetwork,
   154  	}
   155  	confirm, err := book.SubmitOrder(&order)
   156  	assert.Equal(t, types.ErrInvalidPersistence, err)
   157  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   158  }
   159  
   160  func TestOrderBookInvalid_GTTMarket(t *testing.T) {
   161  	market := "testMarket"
   162  	book := getTestOrderBook(t, market)
   163  	defer book.Finish()
   164  	order := types.Order{
   165  		MarketID:    market,
   166  		Party:       "A",
   167  		Side:        types.SideBuy,
   168  		Price:       num.NewUint(100),
   169  		Size:        10,
   170  		Remaining:   10,
   171  		TimeInForce: types.OrderTimeInForceGTT,
   172  		Type:        types.OrderTypeMarket,
   173  		ExpiresAt:   1,
   174  	}
   175  	confirm, err := book.SubmitOrder(&order)
   176  	assert.Equal(t, types.ErrInvalidPersistence, err)
   177  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   178  }
   179  
   180  func TestOrderBookInvalid_GTTNetwork(t *testing.T) {
   181  	market := "testMarket"
   182  	book := getTestOrderBook(t, market)
   183  	defer book.Finish()
   184  	order := types.Order{
   185  		MarketID:    market,
   186  		Party:       "A",
   187  		Side:        types.SideBuy,
   188  		Price:       num.NewUint(100),
   189  		Size:        10,
   190  		Remaining:   10,
   191  		TimeInForce: types.OrderTimeInForceGTT,
   192  		Type:        types.OrderTypeNetwork,
   193  		ExpiresAt:   1,
   194  	}
   195  	confirm, err := book.SubmitOrder(&order)
   196  	assert.Equal(t, types.ErrInvalidPersistence, err)
   197  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   198  }
   199  
   200  func TestOrderBookInvalid_IOCNetwork(t *testing.T) {
   201  	market := "testMarket"
   202  	book := getTestOrderBook(t, market)
   203  	defer book.Finish()
   204  	order := types.Order{
   205  		MarketID:    market,
   206  		Party:       "A",
   207  		Side:        types.SideBuy,
   208  		Price:       num.NewUint(100),
   209  		Size:        10,
   210  		Remaining:   10,
   211  		TimeInForce: types.OrderTimeInForceIOC,
   212  		Type:        types.OrderTypeNetwork,
   213  	}
   214  	confirm, err := book.SubmitOrder(&order)
   215  	assert.Equal(t, types.ErrInvalidPersistence, err)
   216  	assert.Equal(t, (*types.OrderConfirmation)(nil), confirm)
   217  }