code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/long_block_auction.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 "time" 21 22 "code.vegaprotocol.io/vega/protos/vega" 23 24 "github.com/cucumber/godog" 25 ) 26 27 func TheLongBlockDurationTableIsUploaded(ctx context.Context, exec Execution, data *godog.Table) error { 28 rows := parseLongBlockAuctionTable(data) 29 tbl := &vega.LongBlockAuctionDurationTable{ 30 ThresholdAndDuration: make([]*vega.LongBlockAuction, 0, len(rows)), 31 } 32 for _, row := range rows { 33 d := lbDuration{ 34 r: row, 35 } 36 d.validate() 37 tbl.ThresholdAndDuration = append(tbl.ThresholdAndDuration, d.ToRow()) 38 } 39 return exec.OnNetworkWideAuctionDurationUpdated(ctx, tbl) 40 } 41 42 func ThePreviousBlockDurationWas(ctx context.Context, exec Execution, duration string) error { 43 prevDuration, err := time.ParseDuration(duration) 44 if err != nil { 45 return err 46 } 47 exec.BeginBlock(ctx, prevDuration) 48 return nil 49 } 50 51 func parseLongBlockAuctionTable(table *godog.Table) []RowWrapper { 52 return StrictParseTable(table, []string{ 53 "threshold", 54 "duration", 55 }, []string{}) 56 } 57 58 type lbDuration struct { 59 r RowWrapper 60 Threshold time.Duration 61 Duration time.Duration 62 } 63 64 func (l *lbDuration) validate() { 65 l.Threshold = l.r.MustDurationStr("threshold") 66 l.Duration = l.r.MustDurationStr("duration") 67 } 68 69 func (l lbDuration) ToRow() *vega.LongBlockAuction { 70 return &vega.LongBlockAuction{ 71 Threshold: l.Threshold.String(), 72 Duration: l.Duration.String(), 73 } 74 }