code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_time_trigger_oracle_spec.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 "time" 21 22 "code.vegaprotocol.io/vega/core/datasource" 23 "code.vegaprotocol.io/vega/core/datasource/definition" 24 "code.vegaprotocol.io/vega/core/integration/steps/market" 25 vgrand "code.vegaprotocol.io/vega/libs/rand" 26 protoTypes "code.vegaprotocol.io/vega/protos/vega" 27 datav1 "code.vegaprotocol.io/vega/protos/vega/data/v1" 28 29 "github.com/cucumber/godog" 30 ) 31 32 func TheTimeTriggerOracleSpec(config *market.Config, now time.Time, table *godog.Table) error { 33 rows := parseTimeTriggerSpecTable(table) 34 for _, r := range rows { 35 row := internalTimeTriggerOracleSpecRow{row: r} 36 initial := row.initial() 37 name := row.name() 38 spec := &protoTypes.DataSourceSpec{ 39 Id: vgrand.RandomStr(10), 40 Data: &protoTypes.DataSourceDefinition{ 41 SourceType: &protoTypes.DataSourceDefinition_Internal{ 42 Internal: &protoTypes.DataSourceDefinitionInternal{ 43 SourceType: &protoTypes.DataSourceDefinitionInternal_TimeTrigger{ 44 TimeTrigger: &protoTypes.DataSourceSpecConfigurationTimeTrigger{ 45 Triggers: []*datav1.InternalTimeTrigger{ 46 { 47 Initial: &initial, 48 Every: row.every(), 49 }, 50 }, 51 Conditions: []*datav1.Condition{ 52 { 53 Operator: datav1.Condition_OPERATOR_GREATER_THAN_OR_EQUAL, 54 Value: fmt.Sprintf("%d", 0), 55 }, 56 }, 57 }, 58 }, 59 }, 60 }, 61 }, 62 } 63 specDef, err := definition.FromProto(spec.Data, nil) 64 if err != nil { 65 return err 66 } 67 specFromDef := datasource.SpecFromDefinition(*definition.NewWith(specDef)) 68 tt := specFromDef.Data.GetInternalTimeTriggerSpecConfiguration() 69 tt.SetNextTrigger(now.Truncate(time.Second)) 70 config.OracleConfigs.AddTimeTrigger(name, specFromDef) 71 } 72 return nil 73 } 74 75 func parseTimeTriggerSpecTable(table *godog.Table) []RowWrapper { 76 return StrictParseTable(table, []string{ 77 "name", 78 "initial", 79 "every", 80 }, []string{}) 81 } 82 83 type internalTimeTriggerOracleSpecRow struct { 84 row RowWrapper 85 } 86 87 func (r internalTimeTriggerOracleSpecRow) name() string { 88 return r.row.MustStr("name") 89 } 90 91 func (r internalTimeTriggerOracleSpecRow) initial() int64 { 92 return r.row.MustI64("initial") 93 } 94 95 func (r internalTimeTriggerOracleSpecRow) every() int64 { 96 return r.row.MustI64("every") 97 }