code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/parties_cancel_the_following_orders.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 steps
    17  
    18  import (
    19  	"context"
    20  
    21  	"code.vegaprotocol.io/vega/core/integration/stubs"
    22  	"code.vegaprotocol.io/vega/core/types"
    23  
    24  	"github.com/cucumber/godog"
    25  )
    26  
    27  func PartiesCancelTheFollowingOrders(
    28  	broker *stubs.BrokerStub,
    29  	exec Execution,
    30  	table *godog.Table,
    31  ) error {
    32  	for _, r := range parseCancelOrderTable(table) {
    33  		row := cancelOrderRow{row: r}
    34  
    35  		party := row.Party()
    36  
    37  		order, err := broker.GetByReference(party, row.Reference())
    38  		if err != nil {
    39  			return errOrderNotFound(row.Reference(), party, err)
    40  		}
    41  
    42  		cancel := types.OrderCancellation{
    43  			OrderID:  order.Id,
    44  			MarketID: order.MarketId,
    45  		}
    46  
    47  		_, err = exec.CancelOrder(context.Background(), &cancel, party)
    48  		err = checkExpectedError(row, err, nil)
    49  		if err != nil {
    50  			return err
    51  		}
    52  	}
    53  
    54  	return nil
    55  }
    56  
    57  type cancelOrderRow struct {
    58  	row RowWrapper
    59  }
    60  
    61  func parseCancelOrderTable(table *godog.Table) []RowWrapper {
    62  	return StrictParseTable(table, []string{
    63  		"party",
    64  		"reference",
    65  	}, []string{
    66  		"error",
    67  	})
    68  }
    69  
    70  func (r cancelOrderRow) Party() string {
    71  	return r.row.MustStr("party")
    72  }
    73  
    74  func (r cancelOrderRow) HasMarketID() bool {
    75  	return r.row.HasColumn("market id")
    76  }
    77  
    78  func (r cancelOrderRow) Reference() string {
    79  	return r.row.Str("reference")
    80  }
    81  
    82  func (r cancelOrderRow) Error() string {
    83  	return r.row.Str("error")
    84  }
    85  
    86  func (r cancelOrderRow) ExpectError() bool {
    87  	return r.row.HasColumn("error")
    88  }