• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

razor-network / oracle-node / 10882594019

16 Sep 2024 05:47AM UTC coverage: 80.604% (+0.1%) from 80.5%
10882594019

push

github

web-flow
Releases/v1.2.0 (#1236)

* chore: merge develop to releases/v1.2.0 (#1227)

* feat: Github Migration  (#1146)

* feat: migrate to github actions

* chore: migrate from circle ci

* Update develop.yml (#1148)

* Update develop.yml (#1149)

* Update develop.yml

* Update develop.yml

* Update develop.yml

* Fix go mod tidy

* Replaced curve instance elliptic.P256() with crypto.S256() (#1150)

* fix: Update Dockerfile with version bumps (#1152)

* chore: hotfix missing workflow

* chore: fix dockerfile versions

* Feature/v1.1.0 (#1154)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Merged `v1.3.0-alpha` into `v1.0.5` (#973)

* Merged `v1` into `v1.3.0-aplha` with hotfixes (#966)

* Hotfix-proposed data (#913)

* Updated propose data global variables correctly

* Fixed tests

* Returned correct waitForBlockCompletion error

* coverage increase

* GetLocalData returns type types.ProposeFileData

* fixed benchmark

* Fetched Last proposed from contracts (#917)

* fetched getLastProposedEpoch from contracts and tests for it

* typo fix

* V1 propose hotfix (#918)

* Change propose.go to get sorted proposed block ids.
* Fix sorted proposed block issue.

Signed-off-by: Ashish Kumar Mishra <ashish10677@gmail.com>

* allow stakers to addStake < minSafeRazor (#928)

* Call claimStakerReward only if there reward to claim (#926)

* Make contract call only if there is commission to claim

* Add tests for claimCommission file

* update check

* Hotfix-giveSorted (#921)

* ResetDi... (continued)

887 of 1091 new or added lines in 40 files covered. (81.3%)

22 existing lines in 6 files now uncovered.

6641 of 8239 relevant lines covered (80.6%)

2524.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.19
/cmd/setConfig.go
1
// Package cmd provides all functions related to command line
2
package cmd
3

4
import (
5
        "razor/core"
6
        "razor/core/types"
7
        "razor/metrics"
8
        "razor/utils"
9

10
        "github.com/spf13/cobra"
11
        "github.com/spf13/pflag"
12
        "github.com/spf13/viper"
13
)
14

15
var setConfig = &cobra.Command{
16
        Use:   "setConfig",
17
        Short: "setConfig enables user to set the values of provider and gas multiplier",
18
        Long: `Setting the provider helps the CLI to know which provider to connect to.
19
Setting the gas multiplier value enables the CLI to multiply the gas with that value for all the transactions
20

21
Example:
22
  ./razor setConfig --provider https://infura/v3/matic --gasmultiplier 1.5 --buffer 20 --wait 70 --gasprice 1 --logLevel debug --gasLimit 5
23
`,
24
        Run: func(cmd *cobra.Command, args []string) {
×
25
                err := cmdUtils.SetConfig(cmd.Flags())
×
26
                utils.CheckError("SetConfig error: ", err)
×
27
        },
×
28
}
29

30
// This function returns the error if there is any and sets the config
31
func (*UtilsStruct) SetConfig(flagSet *pflag.FlagSet) error {
5✔
32
        log.Debug("Checking to assign log file...")
5✔
33
        fileUtils.AssignLogFile(flagSet, types.Configurations{})
5✔
34

5✔
35
        flagDetails := []types.FlagDetail{
5✔
36
                {Name: "provider", Type: "string"},
5✔
37
                {Name: "alternateProvider", Type: "string"},
5✔
38
                {Name: "gasmultiplier", Type: "float32"},
5✔
39
                {Name: "buffer", Type: "int32"},
5✔
40
                {Name: "wait", Type: "int32"},
5✔
41
                {Name: "gasprice", Type: "int32"},
5✔
42
                {Name: "logLevel", Type: "string"},
5✔
43
                {Name: "gasLimitOverride", Type: "uint64"},
5✔
44
                {Name: "gasLimit", Type: "float32"},
5✔
45
                {Name: "rpcTimeout", Type: "int64"},
5✔
46
                {Name: "httpTimeout", Type: "int64"},
5✔
47
                {Name: "logFileMaxSize", Type: "int"},
5✔
48
                {Name: "logFileMaxBackups", Type: "int"},
5✔
49
                {Name: "logFileMaxAge", Type: "int"},
5✔
50
        }
5✔
51

5✔
52
        // Storing the fetched flag values in a map
5✔
53
        flagValues := make(map[string]interface{})
5✔
54
        for _, flagDetail := range flagDetails {
75✔
55
                flagValue, err := flagSetUtils.FetchFlagInput(flagSet, flagDetail.Name, flagDetail.Type)
70✔
56
                if err != nil {
70✔
NEW
57
                        log.Errorf("Error in fetching value for flag %v: %v", flagDetail.Name, err)
×
NEW
58
                        return err
×
NEW
59
                }
×
60
                flagValues[flagDetail.Name] = flagValue
70✔
61
        }
62

63
        configDetails := []types.ConfigDetail{
5✔
64
                {FlagName: "provider", Key: "provider", DefaultValue: ""},
5✔
65
                {FlagName: "alternateProvider", Key: "alternateProvider", DefaultValue: ""},
5✔
66
                {FlagName: "gasmultiplier", Key: "gasmultiplier", DefaultValue: core.DefaultGasMultiplier},
5✔
67
                {FlagName: "buffer", Key: "buffer", DefaultValue: core.DefaultBufferPercent},
5✔
68
                {FlagName: "wait", Key: "wait", DefaultValue: core.DefaultWaitTime},
5✔
69
                {FlagName: "gasprice", Key: "gasprice", DefaultValue: core.DefaultGasPrice},
5✔
70
                {FlagName: "logLevel", Key: "logLevel", DefaultValue: core.DefaultLogLevel},
5✔
71
                {FlagName: "gasLimitOverride", Key: "gasLimitOverride", DefaultValue: core.DefaultGasLimitOverride},
5✔
72
                {FlagName: "gasLimit", Key: "gasLimit", DefaultValue: core.DefaultGasLimit},
5✔
73
                {FlagName: "rpcTimeout", Key: "rpcTimeout", DefaultValue: core.DefaultRPCTimeout},
5✔
74
                {FlagName: "httpTimeout", Key: "httpTimeout", DefaultValue: core.DefaultHTTPTimeout},
5✔
75
                {FlagName: "logFileMaxSize", Key: "logFileMaxSize", DefaultValue: core.DefaultLogFileMaxSize},
5✔
76
                {FlagName: "logFileMaxBackups", Key: "logFileMaxBackups", DefaultValue: core.DefaultLogFileMaxBackups},
5✔
77
                {FlagName: "logFileMaxAge", Key: "logFileMaxAge", DefaultValue: core.DefaultLogFileMaxAge},
5✔
78
        }
5✔
79

5✔
80
        var areConfigSet bool
5✔
81

5✔
82
        // Setting the respective config values in config file only if the flag was set with a value in `setConfig` command
5✔
83
        for _, configDetail := range configDetails {
75✔
84
                if flagValue, exists := flagValues[configDetail.FlagName]; exists {
140✔
85
                        // Check if the flag was set with a value in `setConfig` command
70✔
86
                        if flagSetUtils.Changed(flagSet, configDetail.FlagName) {
98✔
87
                                viper.Set(configDetail.Key, flagValue)
28✔
88
                                areConfigSet = true
28✔
89
                        }
28✔
90
                }
91
        }
92

93
        // If no config parameter was set than all the config parameters will be set to default config values
94
        if !areConfigSet {
8✔
95
                setDefaultConfigValues(configDetails)
3✔
96
        }
3✔
97

98
        path, pathErr := pathUtils.GetConfigFilePath()
5✔
99
        if pathErr != nil {
6✔
100
                log.Error("Error in fetching config file path")
1✔
101
                return pathErr
1✔
102
        }
1✔
103

104
        if razorUtils.IsFlagPassed("exposeMetrics") {
5✔
105
                metricsErr := handleMetrics(flagSet)
1✔
106
                if metricsErr != nil {
1✔
NEW
107
                        log.Error("Error in handling metrics: ", metricsErr)
×
NEW
108
                        return metricsErr
×
UNCOV
109
                }
×
110
        }
111

112
        configErr := viperUtils.ViperWriteConfigAs(path)
4✔
113
        if configErr != nil {
5✔
114
                log.Error("Error in writing config: ", configErr)
1✔
115
                return configErr
1✔
116
        }
1✔
117
        return nil
3✔
118
}
119

120
func setDefaultConfigValues(configDetails []types.ConfigDetail) {
3✔
121
        log.Info("No value is set to any flag in `setConfig` command")
3✔
122
        log.Info("Setting the config values to default. Use `setConfig` again to modify the values.")
3✔
123
        for _, configDetail := range configDetails {
45✔
124
                viper.Set(configDetail.Key, configDetail.DefaultValue)
42✔
125
        }
42✔
126
}
127

128
func handleMetrics(flagSet *pflag.FlagSet) error {
1✔
129
        port, err := flagSetUtils.FetchFlagInput(flagSet, "exposeMetrics", "string")
1✔
130
        if err != nil {
1✔
NEW
131
                return err
×
UNCOV
132
        }
×
133
        certKey, err := flagSetUtils.FetchFlagInput(flagSet, "certKey", "string")
1✔
134
        if err != nil {
1✔
NEW
135
                return err
×
UNCOV
136
        }
×
137
        certFile, err := flagSetUtils.FetchFlagInput(flagSet, "certFile", "string")
1✔
138
        if err != nil {
1✔
NEW
139
                return err
×
UNCOV
140
        }
×
141
        viper.Set("exposeMetricsPort", port)
1✔
142

1✔
143
        err = metrics.Run(port.(string), certFile.(string), certKey.(string))
1✔
144
        if err != nil {
2✔
145
                log.Error("Failed to start metrics http server: ", err)
1✔
146
        }
1✔
147
        return nil
1✔
148
}
149

150
func init() {
1✔
151
        rootCmd.AddCommand(setConfig)
1✔
152

1✔
153
        var (
1✔
154
                Provider           string
1✔
155
                AlternateProvider  string
1✔
156
                GasMultiplier      float32
1✔
157
                BufferPercent      int32
1✔
158
                WaitTime           int32
1✔
159
                GasPrice           int32
1✔
160
                LogLevel           string
1✔
161
                GasLimitMultiplier float32
1✔
162
                GasLimitOverride   uint64
1✔
163
                RPCTimeout         int64
1✔
164
                HTTPTimeout        int64
1✔
165
                ExposeMetrics      string
1✔
166
                CertFile           string
1✔
167
                CertKey            string
1✔
168
                LogFileMaxSize     int
1✔
169
                LogFileMaxBackups  int
1✔
170
                LogFileMaxAge      int
1✔
171
        )
1✔
172
        setConfig.Flags().StringVarP(&Provider, "provider", "p", "", "provider name")
1✔
173
        setConfig.Flags().StringVarP(&AlternateProvider, "alternateProvider", "", "", "alternate provider name")
1✔
174
        setConfig.Flags().Float32VarP(&GasMultiplier, "gasmultiplier", "g", -1, "gas multiplier value")
1✔
175
        setConfig.Flags().Int32VarP(&BufferPercent, "buffer", "b", 0, "buffer percent")
1✔
176
        setConfig.Flags().Int32VarP(&WaitTime, "wait", "w", 0, "wait time (in secs)")
1✔
177
        setConfig.Flags().Int32VarP(&GasPrice, "gasprice", "", -1, "custom gas price")
1✔
178
        setConfig.Flags().StringVarP(&LogLevel, "logLevel", "", "", "log level")
1✔
179
        setConfig.Flags().Float32VarP(&GasLimitMultiplier, "gasLimit", "", -1, "gas limit percentage increase")
1✔
180
        setConfig.Flags().Uint64VarP(&GasLimitOverride, "gasLimitOverride", "", 0, "gas limit to be over ridden for a transaction")
1✔
181
        setConfig.Flags().Int64VarP(&RPCTimeout, "rpcTimeout", "", 0, "RPC timeout if its not responding")
1✔
182
        setConfig.Flags().Int64VarP(&HTTPTimeout, "httpTimeout", "", 0, "http request timeout if its not responding")
1✔
183
        setConfig.Flags().StringVarP(&ExposeMetrics, "exposeMetrics", "", "", "port number")
1✔
184
        setConfig.Flags().StringVarP(&CertFile, "certFile", "", "", "ssl certificate path")
1✔
185
        setConfig.Flags().StringVarP(&CertKey, "certKey", "", "", "ssl certificate key path")
1✔
186
        setConfig.Flags().IntVarP(&LogFileMaxSize, "logFileMaxSize", "", 0, "max size of log file in MB")
1✔
187
        setConfig.Flags().IntVarP(&LogFileMaxBackups, "logFileMaxBackups", "", 0, "max number of old log files to retain")
1✔
188
        setConfig.Flags().IntVarP(&LogFileMaxAge, "logFileMaxAge", "", 0, "max number of days to retain old log files")
1✔
189

1✔
190
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc