• 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

84.09
/utils/batch.go
1
package utils
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "github.com/avast/retry-go"
8
        "github.com/ethereum/go-ethereum/accounts/abi"
9
        "github.com/ethereum/go-ethereum/common"
10
        "github.com/ethereum/go-ethereum/ethclient"
11
        "github.com/ethereum/go-ethereum/rpc"
12
        "razor/core"
13
)
14

15
//Each batch call may require multiple arguments therefore defining args as [][]interface{}
16

17
// BatchCall performs a batch call to the Ethereum client, using the provided contract ABI, address, method name, and arguments.
18
func (c ClientStruct) BatchCall(client *ethclient.Client, contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([][]interface{}, error) {
6✔
19
        calls, err := ClientInterface.CreateBatchCalls(contractABI, contractAddress, methodName, args)
6✔
20
        if err != nil {
7✔
21
                log.Errorf("Error in creating batch calls: %v", err)
1✔
22
                return nil, err
1✔
23
        }
1✔
24

25
        err = performBatchCallWithRetry(client, calls)
5✔
26
        if err != nil {
6✔
27
                log.Errorf("Error in performing batch call: %v", err)
1✔
28
                return nil, err
1✔
29
        }
1✔
30

31
        results, err := processBatchResults(contractABI, methodName, calls)
4✔
32
        if err != nil {
7✔
33
                log.Errorf("Error in processing batch call result: %v", err)
3✔
34
                return nil, err
3✔
35
        }
3✔
36

37
        return results, nil
1✔
38
}
39

40
// CreateBatchCalls creates a slice of rpc.BatchElem, each representing an Ethereum call, using the provided ABI, contract address, method name, and arguments.
41
func (c ClientStruct) CreateBatchCalls(contractABI *abi.ABI, contractAddress, methodName string, args [][]interface{}) ([]rpc.BatchElem, error) {
7✔
42
        var calls []rpc.BatchElem
7✔
43

7✔
44
        for _, arg := range args {
26✔
45
                data, err := contractABI.Pack(methodName, arg...)
19✔
46
                if err != nil {
20✔
47
                        log.Errorf("Failed to pack data for method %s: %v", methodName, err)
1✔
48
                        return nil, err
1✔
49
                }
1✔
50

51
                calls = append(calls, rpc.BatchElem{
18✔
52
                        Method: "eth_call",
18✔
53
                        Args: []interface{}{
18✔
54
                                map[string]interface{}{
18✔
55
                                        "to":   contractAddress,
18✔
56
                                        "data": fmt.Sprintf("0x%x", data),
18✔
57
                                },
18✔
58
                                "latest",
18✔
59
                        },
18✔
60
                        Result: new(string),
18✔
61
                })
18✔
62
        }
63
        return calls, nil
6✔
64
}
65

NEW
66
func (c ClientStruct) PerformBatchCall(client *ethclient.Client, calls []rpc.BatchElem) error {
×
NEW
67
        err := client.Client().BatchCallContext(context.Background(), calls)
×
NEW
68
        if err != nil {
×
NEW
69
                return err
×
NEW
70
        }
×
NEW
71
        return nil
×
72
}
73

74
// performBatchCallWithRetry performs the batch call to the Ethereum client with retry logic.
75
func performBatchCallWithRetry(client *ethclient.Client, calls []rpc.BatchElem) error {
5✔
76
        err := retry.Do(func() error {
17✔
77
                err := ClientInterface.PerformBatchCall(client, calls)
12✔
78
                if err != nil {
12✔
NEW
79
                        log.Errorf("Error in performing batch call, retrying: %v", err)
×
NEW
80
                        return err
×
NEW
81
                }
×
82
                for _, call := range calls {
32✔
83
                        if call.Error != nil {
28✔
84
                                log.Errorf("Error in call result: %v", call.Error)
8✔
85
                                return call.Error
8✔
86
                        }
8✔
87
                }
88
                return nil
4✔
89
        }, retry.Attempts(core.MaxRetries))
90

91
        if err != nil {
6✔
92
                log.Errorf("All attempts failed to perform batch call: %v", err)
1✔
93
                return err
1✔
94
        }
1✔
95

96
        return nil
4✔
97
}
98

99
// processBatchResults processes the results of the batch call, unpacking the data using the provided ABI and method name.
100
func processBatchResults(contractABI *abi.ABI, methodName string, calls []rpc.BatchElem) ([][]interface{}, error) {
4✔
101
        var results [][]interface{}
4✔
102

4✔
103
        for _, call := range calls {
10✔
104
                if call.Error != nil {
6✔
NEW
105
                        log.Errorf("Error in call result: %v", call.Error)
×
NEW
106
                        return nil, call.Error
×
NEW
107
                }
×
108

109
                result, ok := call.Result.(*string)
6✔
110
                if !ok {
7✔
111
                        log.Error("Failed to type assert call result to *string")
1✔
112
                        return nil, errors.New("type asserting of batch call result error")
1✔
113
                }
1✔
114

115
                if result == nil || *result == "" {
6✔
116
                        return nil, errors.New("empty batch call result")
1✔
117
                }
1✔
118

119
                data := common.FromHex(*result)
4✔
120
                if len(data) == 0 {
5✔
121
                        return nil, errors.New("empty hex data")
1✔
122
                }
1✔
123

124
                unpackedData, err := contractABI.Unpack(methodName, data)
3✔
125
                if err != nil {
3✔
NEW
126
                        return nil, errors.New("unpacking data error")
×
NEW
127
                }
×
128

129
                results = append(results, unpackedData)
3✔
130
        }
131
        return results, nil
1✔
132
}
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