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

razor-network / oracle-node / 14033474177

24 Mar 2025 10:55AM UTC coverage: 78.481% (+0.6%) from 77.925%
14033474177

push

github

web-flow
chore: merge main to develop post release v2.1.0

Merge pull request #1273 from razor-network/main

49 of 72 new or added lines in 28 files covered. (68.06%)

6 existing lines in 1 file now uncovered.

6583 of 8388 relevant lines covered (78.48%)

609.6 hits per line

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

87.66
/cmd/cmd-utils.go
1
//This function add the following command to the root command
2
package cmd
3

4
import (
5
        "context"
6
        "errors"
7
        "github.com/ethereum/go-ethereum/ethclient"
8
        "math/big"
9
        "razor/accounts"
10
        "razor/block"
11
        "razor/core"
12
        "razor/core/types"
13
        "razor/logger"
14
        "razor/rpc"
15
        "razor/utils"
16
        "strconv"
17
        "time"
18

19
        "github.com/spf13/pflag"
20
)
21

22
//This function takes client as a parameter and returns the epoch and state
23
func (*UtilsStruct) GetEpochAndState(rpcParameter rpc.RPCParameters) (uint32, int64, error) {
7✔
24
        epoch, err := razorUtils.GetEpoch(rpcParameter)
7✔
25
        if err != nil {
8✔
26
                return 0, 0, err
1✔
27
        }
1✔
28
        bufferPercent, err := cmdUtils.GetBufferPercent()
6✔
29
        if err != nil {
7✔
30
                return 0, 0, err
1✔
31
        }
1✔
32
        err = ValidateBufferPercentLimit(rpcParameter, bufferPercent)
5✔
33
        if err != nil {
7✔
34
                return 0, 0, err
2✔
35
        }
2✔
36
        latestHeader, err := clientUtils.GetLatestBlockWithRetry(rpcParameter)
3✔
37
        if err != nil {
4✔
38
                log.Error("Error in fetching block: ", err)
1✔
39
                return 0, 0, err
1✔
40
        }
1✔
41
        stateBuffer, err := razorUtils.GetStateBuffer(rpcParameter)
2✔
42
        if err != nil {
2✔
43
                log.Error("Error in getting state buffer: ", err)
×
44
                return 0, 0, err
×
45
        }
×
46
        state, err := razorUtils.GetBufferedState(latestHeader, stateBuffer, bufferPercent)
2✔
47
        if err != nil {
3✔
48
                return 0, 0, err
1✔
49
        }
1✔
50
        log.Debug("Epoch ", epoch)
1✔
51
        log.Debug("State ", utils.GetStateName(state))
1✔
52
        return epoch, state, nil
1✔
53
}
54

55
//This function waits for the appropriate states which are required
56
func (*UtilsStruct) WaitForAppropriateState(rpcParameter rpc.RPCParameters, action string, states ...int) (uint32, error) {
4✔
57
        statesAllowed := GetFormattedStateNames(states)
4✔
58
        for {
8✔
59
                epoch, state, err := cmdUtils.GetEpochAndState(rpcParameter)
4✔
60
                if err != nil {
5✔
61
                        log.Error("Error in fetching epoch and state: ", err)
1✔
62
                        return epoch, err
1✔
63
                }
1✔
64
                if !utils.Contains(states, int(state)) {
3✔
65
                        log.Infof("Can only %s during %s state(s). Retrying in 5 seconds...", action, statesAllowed)
×
66
                        timeUtils.Sleep(5 * time.Second)
×
67
                } else {
3✔
68
                        return epoch, nil
3✔
69
                }
3✔
70
        }
71
}
72

73
//This function wait if the state is commit state
74
func (*UtilsStruct) WaitIfCommitState(rpcParameter rpc.RPCParameters, action string) (uint32, error) {
2✔
75
        for {
4✔
76
                epoch, state, err := cmdUtils.GetEpochAndState(rpcParameter)
2✔
77
                if err != nil {
3✔
78
                        log.Error("Error in fetching epoch and state: ", err)
1✔
79
                        return epoch, err
1✔
80
                }
1✔
81
                if state == 0 || state == -1 {
1✔
82
                        log.Debugf("Cannot perform %s during commit state. Retrying in 5 seconds...", action)
×
83
                        timeUtils.Sleep(5 * time.Second)
×
84
                } else {
1✔
85
                        return epoch, nil
1✔
86
                }
1✔
87
        }
88
}
89

90
//This function assignes amount in wei
91
func (*UtilsStruct) AssignAmountInWei(flagSet *pflag.FlagSet) (*big.Int, error) {
5✔
92
        amount, err := flagSetUtils.GetStringValue(flagSet)
5✔
93
        if err != nil {
6✔
94
                log.Error("Error in reading value: ", err)
1✔
95
                return nil, err
1✔
96
        }
1✔
97
        log.Debug("AssignAmountInWei: Amount: ", amount)
4✔
98
        _amount, ok := new(big.Int).SetString(amount, 10)
4✔
99

4✔
100
        if !ok {
5✔
101
                return nil, errors.New("SetString: error")
1✔
102
        }
1✔
103
        var amountInWei *big.Int
3✔
104
        if razorUtils.IsFlagPassed("weiRazor") {
5✔
105
                weiRazorPassed, err := flagSetUtils.GetBoolWeiRazor(flagSet)
2✔
106
                if err != nil {
3✔
107
                        log.Error("Error in getting weiRazorBool Value: ", err)
1✔
108
                        return nil, err
1✔
109
                }
1✔
110
                if weiRazorPassed {
2✔
111
                        log.Debug("weiRazor flag is passed as true, considering teh value input in wei")
1✔
112
                        amountInWei = _amount
1✔
113
                }
1✔
114
        } else {
1✔
115
                amountInWei = utils.GetAmountInWei(_amount)
1✔
116
        }
1✔
117
        return amountInWei, nil
2✔
118
}
119

120
//This function returns the states which are allowed
121
func GetFormattedStateNames(states []int) string {
7✔
122
        var statesAllowed string
7✔
123
        for i := 0; i < len(states); i++ {
14✔
124
                if i == len(states)-1 {
13✔
125
                        statesAllowed = statesAllowed + strconv.Itoa(states[i]) + ":" + utils.GetStateName(int64(states[i]))
6✔
126
                } else {
7✔
127
                        statesAllowed = statesAllowed + strconv.Itoa(states[i]) + ":" + utils.GetStateName(int64(states[i])) + ", "
1✔
128
                }
1✔
129
        }
130
        return statesAllowed
7✔
131
}
132

133
func InitializeCommandDependencies(flagSet *pflag.FlagSet) (types.Configurations, rpc.RPCParameters, *block.BlockMonitor, types.Account, error) {
142✔
134
        var (
142✔
135
                account       types.Account
142✔
136
                client        *ethclient.Client
142✔
137
                rpcParameters rpc.RPCParameters
142✔
138
                blockMonitor  *block.BlockMonitor
142✔
139
        )
142✔
140

142✔
141
        config, err := cmdUtils.GetConfigData()
142✔
142
        if err != nil {
162✔
143
                log.Error("Error in getting config: ", err)
20✔
144
                return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
20✔
145
        }
20✔
146
        log.Debugf("Config: %+v", config)
122✔
147

122✔
148
        if razorUtils.IsFlagPassed("address") {
229✔
149
                address, err := flagSetUtils.GetStringAddress(flagSet)
107✔
150
                if err != nil {
121✔
151
                        log.Error("Error in getting address: ", err)
14✔
152
                        return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
14✔
153
                }
14✔
154
                log.Debugf("Address: %v", address)
93✔
155

93✔
156
                log.Debug("Getting password...")
93✔
157
                password := razorUtils.AssignPassword(flagSet)
93✔
158

93✔
159
                accountManager, err := razorUtils.AccountManagerForKeystore()
93✔
160
                if err != nil {
93✔
161
                        log.Error("Error in getting accounts manager for keystore: ", err)
×
NEW
162
                        return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
×
163
                }
×
164

165
                account = accounts.InitAccountStruct(address, password, accountManager)
93✔
166
                err = razorUtils.CheckPassword(account)
93✔
167
                if err != nil {
93✔
168
                        log.Error("Error in fetching private key from given password: ", err)
×
NEW
169
                        return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
×
170
                }
×
171
        }
172

173
        rpcManager, err := rpc.InitializeRPCManager(config.Provider)
108✔
174
        if err != nil {
108✔
175
                log.Error("Error in initializing RPC Manager: ", err)
×
NEW
176
                return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
×
177
        }
×
178

179
        rpcParameters = rpc.RPCParameters{
108✔
180
                RPCManager: rpcManager,
108✔
181
                Ctx:        context.Background(),
108✔
182
        }
108✔
183

108✔
184
        client, err = rpcManager.GetBestRPCClient()
108✔
185
        if err != nil {
108✔
186
                log.Error("Error in getting best RPC client: ", err)
×
NEW
187
                return types.Configurations{}, rpc.RPCParameters{}, nil, types.Account{}, err
×
188
        }
×
189

190
        // Initialize BlockMonitor with RPCManager
191
        blockMonitor = block.NewBlockMonitor(client, rpcManager, core.BlockNumberInterval, core.StaleBlockNumberCheckInterval)
108✔
192
        blockMonitor.Start()
108✔
193
        log.Debug("Checking to assign log file...")
108✔
194
        fileUtils.AssignLogFile(flagSet, config)
108✔
195

108✔
196
        // Update Logger Instance
108✔
197
        logger.UpdateLogger(account.Address, client, blockMonitor)
108✔
198

108✔
199
        return config, rpcParameters, blockMonitor, account, nil
108✔
200
}
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