Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch main branch into v1.0.6 #1076

Merged
merged 9 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,46 @@ jobs:
version: 20.10.7
docker_layer_caching: true
- run:
name: "Building docker image"
name: "Installing node and go"
command: |
docker build --file Dockerfile.test -t razor-test .

sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install npm ethereum
- run:
name: "Installing dependencies"
command: |
npm i
go get -d github.com/ethereum/[email protected] \
&& go install github.com/ethereum/go-ethereum/cmd/[email protected] \
&& go install github.com/mattn/[email protected] \
&& go install github.com/ory/[email protected] \
&& go install github.com/golangci/golangci-lint/cmd/[email protected]

- run:
name: "Make Setup"
command: |
make setup
- run:
name: "go-fmt"
command: |
docker run --rm -v $(pwd):/test --name go razor-test gofmt
gofmt
- run:
name: "go-lint"
command: |
docker run --rm -v $(pwd):/test --name go razor-test golangci-lint run -v --timeout 5m
golangci-lint run -v --timeout 5m
- run:
name: "Executing test cases"
command: |
docker run --rm -v $(pwd):/test --name go razor-test go-acc ./... --ignore razor/accounts/mocks --ignore razor/cmd/mocks --ignore razor/utils/mocks --ignore pkg --ignore razor/path/mocks --output /test/coverage.txt
go-acc ./... --ignore razor/accounts/mocks --ignore razor/cmd/mocks --ignore razor/utils/mocks --ignore pkg --ignore razor/path/mocks --output coverage.txt
- run:
name: "Executing benchmarks"
command: |
docker run --rm -v $(pwd):/test --name go razor-test go test ./... -bench=. -run=^#
go test ./... -bench=. -run=^#
- run:
name: "Publish Coverage to Coveralls.io"
command: |
docker run --rm -v $(pwd):/test --name go -e COVERALLS_TOKEN=$COVERALLS_TOKEN razor-test goveralls -coverprofile=/test/coverage.txt -service semaphore -repotoken $COVERALLS_TOKEN
goveralls -coverprofile=coverage.txt -service semaphore -repotoken $COVERALLS_TOKEN
- persist_to_workspace:
root: .
paths:
Expand Down
17 changes: 0 additions & 17 deletions Dockerfile.test

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ There are a set of parameters that are configurable. These include:
- Gas Price: The value of gas price if you want to set manually. If you don't provide any value or simply keep it to 1, the razor client will automatically calculate the optimum gas price and send it.
- Log Level: Normally debug logs are not logged into the log file. But if you want you can set `logLevel` to `debug` and fetch the debug logs.
- Gas Limit: The value with which the gas limit will be multiplied while sending every transaction.
- Gas Limit Override: This value would be used as a gas limit for all the transactions instead of estimating for each transaction.
- RPC Timeout: This is the threshold number of seconds after which any contract and client calls will time out.
- HTTP Timeout: This is the threshold number of seconds after which an HTTP request for a job will time out.
- Maximum size of log file: This is the maximum size of log file in MB
Expand Down
22 changes: 22 additions & 0 deletions cmd/config-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) {
if err != nil {
return config, err
}
gasLimitOverride, err := cmdUtils.GetGasLimitOverride()
if err != nil {
return config, err
}
rpcTimeout, err := cmdUtils.GetRPCTimeout()
if err != nil {
return config, err
Expand Down Expand Up @@ -81,6 +85,7 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) {
config.GasPrice = gasPrice
config.LogLevel = logLevel
config.GasLimitMultiplier = gasLimit
config.GasLimitOverride = gasLimitOverride
config.RPCTimeout = rpcTimeout
utils.RPCTimeout = rpcTimeout
config.HTTPTimeout = httpTimeout
Expand Down Expand Up @@ -215,6 +220,23 @@ func (*UtilsStruct) GetGasLimit() (float32, error) {
return gasLimit, nil
}

//This function returns the gas limit to override
func (*UtilsStruct) GetGasLimitOverride() (uint64, error) {
gasLimitOverride, err := flagSetUtils.GetRootUint64GasLimitOverride()
if err != nil {
return uint64(core.DefaultGasLimitOverride), err
}
if gasLimitOverride == 0 {
if viper.IsSet("gasLimitOverride") {
gasLimitOverride = viper.GetUint64("gasLimitOverride")
} else {
gasLimitOverride = uint64(core.DefaultGasLimitOverride)
log.Debug("GasLimitOverride is not set, taking its default value ", gasLimitOverride)
}
}
return gasLimitOverride, nil
}

//This function returns the RPC timeout
func (*UtilsStruct) GetRPCTimeout() (int64, error) {
rpcTimeout, err := flagSetUtils.GetRootInt64RPCTimeout()
Expand Down
66 changes: 66 additions & 0 deletions cmd/config-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestGetConfigData(t *testing.T) {
WaitTime: 1,
LogLevel: "debug",
GasLimitMultiplier: 3,
GasLimitOverride: 1000000,
RPCTimeout: 10,
HTTPTimeout: 10,
LogFileMaxSize: 5,
Expand All @@ -51,6 +52,8 @@ func TestGetConfigData(t *testing.T) {
logLevel string
logLevelErr error
gasLimit float32
gasLimitOverride uint64
gasLimitOverrideErr error
rpcTimeout int64
rpcTimeoutErr error
httpTimeout int64
Expand Down Expand Up @@ -78,6 +81,7 @@ func TestGetConfigData(t *testing.T) {
waitTime: 1,
logLevel: "debug",
gasLimit: 3,
gasLimitOverride: 1000000,
rpcTimeout: 10,
httpTimeout: 10,
logFileMaxSize: 5,
Expand Down Expand Up @@ -170,6 +174,7 @@ func TestGetConfigData(t *testing.T) {
cmdUtilsMock.On("GetGasPrice").Return(tt.args.gasPrice, tt.args.gasPriceErr)
cmdUtilsMock.On("GetLogLevel").Return(tt.args.logLevel, tt.args.logLevelErr)
cmdUtilsMock.On("GetGasLimit").Return(tt.args.gasLimit, tt.args.gasLimitErr)
cmdUtilsMock.On("GetGasLimitOverride").Return(tt.args.gasLimitOverride, tt.args.gasLimitOverrideErr)
cmdUtilsMock.On("GetBufferPercent").Return(tt.args.bufferPercent, tt.args.bufferPercentErr)
cmdUtilsMock.On("GetRPCTimeout").Return(tt.args.rpcTimeout, tt.args.rpcTimeoutErr)
cmdUtilsMock.On("GetHTTPTimeout").Return(tt.args.httpTimeout, tt.args.httpTimeoutErr)
Expand Down Expand Up @@ -315,6 +320,67 @@ func TestGetGasLimit(t *testing.T) {
}
}

func TestGetGasLimitOverride(t *testing.T) {
type args struct {
gasLimitOverride uint64
gasLimitOverrideErr error
}
tests := []struct {
name string
args args
want uint64
wantErr error
}{
{
name: "Test 1: When getGasLimitOverride function executes successfully",
args: args{
gasLimitOverride: 5000000,
},
want: 5000000,
wantErr: nil,
},
{
name: "Test 2: When gasLimitOverride is 0",
args: args{
gasLimitOverride: 0,
},
want: 0,
wantErr: nil,
},
{
name: "Test 3: When there is an error in getting gasLimitOverride",
args: args{
gasLimitOverrideErr: errors.New("gasLimitOverride error"),
},
want: 0,
wantErr: errors.New("gasLimitOverride error"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
flagSetUtilsMock := new(mocks.FlagSetInterface)
flagSetUtils = flagSetUtilsMock

flagSetUtilsMock.On("GetRootUint64GasLimitOverride").Return(tt.args.gasLimitOverride, tt.args.gasLimitOverrideErr)
utils := &UtilsStruct{}

got, err := utils.GetGasLimitOverride()
if got != tt.want {
t.Errorf("getGasLimitOverride() got = %v, want %v", got, tt.want)
}
if err == nil || tt.wantErr == nil {
if err != tt.wantErr {
t.Errorf("Error for getGasLimitOverride function, got = %v, want = %v", err, tt.wantErr)
}
} else {
if err.Error() != tt.wantErr.Error() {
t.Errorf("Error for getGasLimitOverride function, got = %v, want = %v", err, tt.wantErr)
}
}
})
}
}

func TestGetGasPrice(t *testing.T) {
type args struct {
gasPrice int32
Expand Down
3 changes: 3 additions & 0 deletions cmd/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type FlagSetInterface interface {
GetInt32Wait(flagSet *pflag.FlagSet) (int32, error)
GetInt32GasPrice(flagSet *pflag.FlagSet) (int32, error)
GetFloat32GasLimit(flagSet *pflag.FlagSet) (float32, error)
GetUint64GasLimitOverride(flagSet *pflag.FlagSet) (uint64, error)
GetStringLogLevel(flagSet *pflag.FlagSet) (string, error)
GetInt64RPCTimeout(flagSet *pflag.FlagSet) (int64, error)
GetInt64HTTPTimeout(flagSet *pflag.FlagSet) (int64, error)
Expand All @@ -127,6 +128,7 @@ type FlagSetInterface interface {
GetRootInt32GasPrice() (int32, error)
GetRootStringLogLevel() (string, error)
GetRootFloat32GasLimit() (float32, error)
GetRootUint64GasLimitOverride() (uint64, error)
GetRootInt64RPCTimeout() (int64, error)
GetRootInt64HTTPTimeout() (int64, error)
GetRootIntLogFileMaxSize() (int, error)
Expand Down Expand Up @@ -170,6 +172,7 @@ type UtilsCmdInterface interface {
GetGasPrice() (int32, error)
GetLogLevel() (string, error)
GetGasLimit() (float32, error)
GetGasLimitOverride() (uint64, error)
GetBufferPercent() (int32, error)
GetRPCTimeout() (int64, error)
GetHTTPTimeout() (int64, error)
Expand Down
42 changes: 42 additions & 0 deletions cmd/mocks/flag_set_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions cmd/mocks/utils_cmd_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading