code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/cancelled_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 "fmt" 20 21 "code.vegaprotocol.io/vega/core/integration/stubs" 22 23 "github.com/cucumber/godog" 24 ) 25 26 func TheCancelledOrdersEventContains(broker *stubs.BrokerStub, market string, table *godog.Table) error { 27 allCancelled := broker.GetCancelledOrdersPerMarket() 28 cancelled, ok := allCancelled[market] 29 if !ok { 30 return fmt.Errorf("no cancelled orders event for market %s", market) 31 } 32 rows := parseReferenceTable(table) 33 for _, r := range rows { 34 rr := referenceRow{ 35 r: r, 36 } 37 o, err := broker.GetFirstByReference(rr.Party(), rr.Reference()) 38 if err != nil { 39 return err 40 } 41 if o.MarketId != market { 42 return fmt.Errorf("could not find order with reference %s for party %s and market %s", rr.Reference(), rr.Party(), market) 43 } 44 // now check if this ID was indeed emitted as part of a cancelled orders event. 45 if _, ok := cancelled[o.Id]; !ok { 46 return fmt.Errorf("order with reference %s for party %s and market %s (ID %s) missing from cancelled orders event", rr.Reference(), rr.Party(), market, o.Id) 47 } 48 } 49 return nil 50 } 51 52 func parseReferenceTable(table *godog.Table) []RowWrapper { 53 return StrictParseTable(table, []string{ 54 "reference", 55 "party", 56 }, []string{}) 57 } 58 59 type referenceRow struct { 60 r RowWrapper 61 } 62 63 func (r referenceRow) Reference() string { 64 return r.r.MustStr("reference") 65 } 66 67 func (r referenceRow) Party() string { 68 return r.r.MustStr("party") 69 }