Skip to content

Commit

Permalink
refactor: removed alternateProvider functions and flag as its not req…
Browse files Browse the repository at this point in the history
…uired now
  • Loading branch information
Yashk767 committed Nov 25, 2024
1 parent 2aa58b2 commit 7fa4863
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 227 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ $ ./razor setConfig --provider <rpc_provider> --gasmultiplier <multiplier_value>
docker

```
docker exec -it razor-go razor setConfig --provider <rpc_provider> --alternateProvider <alternate_rpc_provider> --gasmultiplier <multiplier_value> --buffer <buffer_percentage> --wait <wait_for_n_blocks> --gasprice <gas_price> --logLevel <debug_or_info> --gasLimit <gas_limit_multiplier> --rpcTimeout <rpc_timeout> --httpTimeout <http_timeout> --logFileMaxSize <file_max_size> --logFileMaxBackups <file_max_backups> --logFileMaxAge <file_max_age>
docker exec -it razor-go razor setConfig --provider <rpc_provider> --gasmultiplier <multiplier_value> --buffer <buffer_percentage> --wait <wait_for_n_blocks> --gasprice <gas_price> --logLevel <debug_or_info> --gasLimit <gas_limit_multiplier> --rpcTimeout <rpc_timeout> --httpTimeout <http_timeout> --logFileMaxSize <file_max_size> --logFileMaxBackups <file_max_backups> --logFileMaxAge <file_max_age>
```

Example:
Expand Down
63 changes: 0 additions & 63 deletions client/alternateClient.go

This file was deleted.

21 changes: 0 additions & 21 deletions cmd/config-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cmd
import (
"errors"
"razor/RPC"
"razor/client"
"razor/core"
"razor/core/types"
"razor/utils"
Expand All @@ -19,7 +18,6 @@ import (
func (*UtilsStruct) GetConfigData() (types.Configurations, error) {
config := types.Configurations{
Provider: "",
AlternateProvider: "",
GasMultiplier: 0,
BufferPercent: 0,
WaitTime: 0,
Expand All @@ -36,10 +34,6 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) {
if err != nil {
return config, err
}
alternateProvider, err := cmdUtils.GetAlternateProvider()
if err != nil {
return config, err
}
gasMultiplier, err := cmdUtils.GetMultiplier()
if err != nil {
return config, err
Expand Down Expand Up @@ -89,8 +83,6 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) {
return config, err
}
config.Provider = provider
config.AlternateProvider = alternateProvider
client.SetAlternateProvider(alternateProvider)
config.GasMultiplier = gasMultiplier
config.BufferPercent = bufferPercent
config.WaitTime = waitTime
Expand Down Expand Up @@ -171,19 +163,6 @@ func (*UtilsStruct) GetProvider() (string, error) {
return providerString, nil
}

//This function returns the alternate provider
func (*UtilsStruct) GetAlternateProvider() (string, error) {
alternateProvider, err := getConfigValue("alternateProvider", "string", "", "alternateProvider")
if err != nil {
return "", err
}
alternateProviderString := alternateProvider.(string)
if !strings.HasPrefix(alternateProviderString, "https") {
log.Warn("You are not using a secure RPC URL. Switch to an https URL instead to be safe.")
}
return alternateProviderString, nil
}

//This function returns the multiplier
func (*UtilsStruct) GetMultiplier() (float32, error) {
const (
Expand Down
102 changes: 0 additions & 102 deletions cmd/config-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func removeTestConfig(path string) {
func TestGetConfigData(t *testing.T) {
nilConfig := types.Configurations{
Provider: "",
AlternateProvider: "",
GasMultiplier: 0,
BufferPercent: 0,
WaitTime: 0,
Expand All @@ -52,7 +51,6 @@ func TestGetConfigData(t *testing.T) {

configData := types.Configurations{
Provider: "",
AlternateProvider: "",
GasMultiplier: 1,
BufferPercent: 20,
WaitTime: 1,
Expand All @@ -69,8 +67,6 @@ func TestGetConfigData(t *testing.T) {
type args struct {
provider string
providerErr error
alternateProvider string
alternateProviderErr error
gasMultiplier float32
gasMultiplierErr error
bufferPercent int32
Expand Down Expand Up @@ -106,7 +102,6 @@ func TestGetConfigData(t *testing.T) {
name: "Test 1: When GetConfigData function executes successfully",
args: args{
provider: "",
alternateProvider: "",
gasMultiplier: 1,
bufferPercent: 20,
waitTime: 1,
Expand Down Expand Up @@ -194,21 +189,12 @@ func TestGetConfigData(t *testing.T) {
want: nilConfig,
wantErr: errors.New("httpTimeout error"),
},
{
name: "Test 11: When there is an error in getting alternate provider",
args: args{
alternateProviderErr: errors.New("alternate provider error"),
},
want: nilConfig,
wantErr: errors.New("alternate provider error"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
SetUpMockInterfaces()

cmdUtilsMock.On("GetProvider").Return(tt.args.provider, tt.args.providerErr)
cmdUtilsMock.On("GetAlternateProvider").Return(tt.args.alternateProvider, tt.args.alternateProviderErr)
cmdUtilsMock.On("GetMultiplier").Return(tt.args.gasMultiplier, tt.args.gasMultiplierErr)
cmdUtilsMock.On("GetWaitTime").Return(tt.args.waitTime, tt.args.waitTimeErr)
cmdUtilsMock.On("GetGasPrice").Return(tt.args.gasPrice, tt.args.gasPriceErr)
Expand Down Expand Up @@ -848,94 +834,6 @@ func TestGetProvider(t *testing.T) {
}
}

func TestGetAlternateProvider(t *testing.T) {
type args struct {
isFlagSet bool
alternateProvider string
alternateProviderErr error
alternateProviderInConfig string
}
tests := []struct {
name string
useDummyConfigFile bool
args args
want string
wantErr error
}{
{
name: "Test 1: When alternateProvider is fetched from root flag",
args: args{
isFlagSet: true,
alternateProvider: "https://polygon-mumbai.g.alchemy.com/v2/-Re1lE3oDIVTWchuKMfRIECn0I",
},
want: "https://polygon-mumbai.g.alchemy.com/v2/-Re1lE3oDIVTWchuKMfRIECn0I",
wantErr: nil,
},
{
name: "Test 2: When alternateProvider from root flag has prefix https",
args: args{
isFlagSet: true,
alternateProvider: "127.0.0.1:8545",
},
want: "127.0.0.1:8545",
wantErr: nil,
},
{
name: "Test 3: When there is an error in fetching alternateProvider from root flag",
args: args{
isFlagSet: true,
alternateProviderErr: errors.New("alternateProvider error"),
},
want: "",
wantErr: errors.New("alternateProvider error"),
},
{
name: "Test 4: When alternateProvider value is fetched from config",
useDummyConfigFile: true,
args: args{
alternateProviderInConfig: "https://some-config-provider.com",
},
want: "https://some-config-provider.com",
wantErr: nil,
},
{
name: "Test 5: When alternateProvider is not passed in root nor set in config",
want: "",
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viper.Reset() // Reset viper state

if tt.useDummyConfigFile {
createTestConfig(t, "alternateProvider", tt.args.alternateProviderInConfig)
defer removeTestConfig(tempConfigPath)
}

SetUpMockInterfaces()

flagSetMock.On("FetchRootFlagInput", mock.Anything, mock.Anything).Return(tt.args.alternateProvider, tt.args.alternateProviderErr)
flagSetMock.On("Changed", mock.Anything, mock.Anything).Return(tt.args.isFlagSet)

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

func TestGetRPCTimeout(t *testing.T) {
type args struct {
isFlagSet bool
Expand Down
1 change: 0 additions & 1 deletion cmd/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ type FlagSetInterface interface {
type UtilsCmdInterface interface {
SetConfig(flagSet *pflag.FlagSet) error
GetProvider() (string, error)
GetAlternateProvider() (string, error)
GetMultiplier() (float32, error)
GetWaitTime() (int32, error)
GetGasPrice() (int32, error)
Expand Down
24 changes: 0 additions & 24 deletions cmd/mocks/utils_cmd_interface.go

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

2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

var (
Provider string
AlternateProvider string
GasMultiplier float32
BufferPercent int32
WaitTime int32
Expand Down Expand Up @@ -61,7 +60,6 @@ func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVarP(&Provider, "provider", "p", "", "provider name")
rootCmd.PersistentFlags().StringVarP(&AlternateProvider, "alternateProvider", "", "", "alternate provider name")
rootCmd.PersistentFlags().Float32VarP(&GasMultiplier, "gasmultiplier", "g", -1, "gas multiplier value")
rootCmd.PersistentFlags().Int32VarP(&BufferPercent, "buffer", "b", 0, "buffer percent")
rootCmd.PersistentFlags().Int32VarP(&WaitTime, "wait", "w", -1, "wait time")
Expand Down
4 changes: 0 additions & 4 deletions cmd/setConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (*UtilsStruct) SetConfig(flagSet *pflag.FlagSet) error {

flagDetails := []types.FlagDetail{
{Name: "provider", Type: "string"},
{Name: "alternateProvider", Type: "string"},
{Name: "gasmultiplier", Type: "float32"},
{Name: "buffer", Type: "int32"},
{Name: "wait", Type: "int32"},
Expand Down Expand Up @@ -62,7 +61,6 @@ func (*UtilsStruct) SetConfig(flagSet *pflag.FlagSet) error {

configDetails := []types.ConfigDetail{
{FlagName: "provider", Key: "provider", DefaultValue: ""},
{FlagName: "alternateProvider", Key: "alternateProvider", DefaultValue: ""},
{FlagName: "gasmultiplier", Key: "gasmultiplier", DefaultValue: core.DefaultGasMultiplier},
{FlagName: "buffer", Key: "buffer", DefaultValue: core.DefaultBufferPercent},
{FlagName: "wait", Key: "wait", DefaultValue: core.DefaultWaitTime},
Expand Down Expand Up @@ -152,7 +150,6 @@ func init() {

var (
Provider string
AlternateProvider string
GasMultiplier float32
BufferPercent int32
WaitTime int32
Expand All @@ -170,7 +167,6 @@ func init() {
LogFileMaxAge int
)
setConfig.Flags().StringVarP(&Provider, "provider", "p", "", "provider name")
setConfig.Flags().StringVarP(&AlternateProvider, "alternateProvider", "", "", "alternate provider name")
setConfig.Flags().Float32VarP(&GasMultiplier, "gasmultiplier", "g", -1, "gas multiplier value")
setConfig.Flags().Int32VarP(&BufferPercent, "buffer", "b", 0, "buffer percent")
setConfig.Flags().Int32VarP(&WaitTime, "wait", "w", 0, "wait time (in secs)")
Expand Down
9 changes: 1 addition & 8 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ then
PROVIDER="http://127.0.0.1:8545"
fi

read -rp "Alternate Provider: " ALTERNATE_PROVIDER

read -rp "Gas Multiplier: (1.0) " GAS_MULTIPLIER
if [ -z "$GAS_MULTIPLIER" ];
then
Expand Down Expand Up @@ -55,9 +53,4 @@ if [ -z "$MAX_AGE" ]; then
MAX_AGE=60
fi

ALT_PROVIDER_OPTION=""
if [ -n "$ALTERNATE_PROVIDER" ]; then
ALT_PROVIDER_OPTION="--alternateProvider $ALTERNATE_PROVIDER"
fi

$RAZOR setConfig -p $PROVIDER $ALT_PROVIDER_OPTION -b $BUFFER -g $GAS_MULTIPLIER -w $WAIT_TIME --gasprice $GAS_PRICE --gasLimit $GAS_LIMIT --rpcTimeout 5 --httpTimeout 5 --logFileMaxSize $MAX_SIZE --logFileMaxBackups $MAX_BACKUPS --logFileMaxAge $MAX_AGE
$RAZOR setConfig -p $PROVIDER -b $BUFFER -g $GAS_MULTIPLIER -w $WAIT_TIME --gasprice $GAS_PRICE --gasLimit $GAS_LIMIT --rpcTimeout 5 --httpTimeout 5 --logFileMaxSize $MAX_SIZE --logFileMaxBackups $MAX_BACKUPS --logFileMaxAge $MAX_AGE
1 change: 0 additions & 1 deletion core/types/configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

type Configurations struct {
Provider string
AlternateProvider string
GasMultiplier float32
BufferPercent int32
WaitTime int32
Expand Down

0 comments on commit 7fa4863

Please sign in to comment.