Skip to content

Commit

Permalink
fix(reshare): fix check of proof path (#167)
Browse files Browse the repository at this point in the history
* fix(reshare): fix check of proof path

* fix: local path for resign

* fix default output path

* fix the tests

* fix default value

* remove debug print
  • Loading branch information
MatusKysel authored Jan 23, 2025
1 parent 08425ce commit 7f5f515
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 161 deletions.
2 changes: 1 addition & 1 deletion cli/flags/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ func ConfigPathFlag(c *cobra.Command) {

// OutputPathFlag sets the path to store resulting files
func OutputPathFlag(c *cobra.Command) {
AddPersistentStringFlag(c, outputPath, "./output", "Path to store results", false)
AddPersistentStringFlag(c, outputPath, "./data/output", "Path to store results", false)
}
22 changes: 11 additions & 11 deletions cli/flags/reshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,46 +107,46 @@ func BindGenerateReshareMsgFlags(cmd *cobra.Command) error {
}
OperatorIDs = viper.GetStringSlice("operatorIDs")
if len(OperatorIDs) == 0 {
return fmt.Errorf("😥 Old operator IDs flag cannot be empty")
return fmt.Errorf("😥 old operator IDs flag cannot be empty")
}
NewOperatorIDs = viper.GetStringSlice("newOperatorIDs")
if len(NewOperatorIDs) == 0 {
return fmt.Errorf("😥 New operator IDs flag cannot be empty")
return fmt.Errorf("😥 new operator IDs flag cannot be empty")
}
ProofsFilePath = viper.GetString("proofsFilePath")
if ProofsFilePath != "" {
ProofsFilePath = filepath.Clean(ProofsFilePath)
}
ProofsString = viper.GetString("proofsString")
if ProofsFilePath == "" && ProofsString == "" {
return fmt.Errorf("😥 Failed to get proofs from proofs string or path to proofs flag value")
return fmt.Errorf("😥 failed to get proofs from proofs string or path to proofs flag value")
}
if ProofsFilePath != "" && ProofsString != "" {
return fmt.Errorf("😥 proofs can be provided either as a string, or path to a file, not both")
}
if !filepath.IsLocal(ProofsFilePath) {
if ProofsFilePath != "" && !filepath.IsLocal(ProofsFilePath) {
return fmt.Errorf("😥 wrong proofsFilePath flag, should be local")
}
withdrawAddr := viper.GetString("withdrawAddress")
if withdrawAddr == "" {
return fmt.Errorf("😥 Failed to get withdrawal address flag value")
return fmt.Errorf("😥 failed to get withdrawal address flag value")
}
var err error
WithdrawAddress, err = utils.HexToAddress(withdrawAddr)
if err != nil {
return fmt.Errorf("😥 Failed to parse withdraw address: %s", err.Error())
return fmt.Errorf("😥 failed to parse withdraw address: %s", err.Error())
}
Network = viper.GetString("network")
if Network == "" {
return fmt.Errorf("😥 Failed to get fork version flag value")
return fmt.Errorf("😥 failed to get fork version flag value")
}
owner := viper.GetString("owner")
if owner == "" {
return fmt.Errorf("😥 Failed to get owner address flag value")
return fmt.Errorf("😥 failed to get owner address flag value")
}
OwnerAddress, err = utils.HexToAddress(owner)
if err != nil {
return fmt.Errorf("😥 Failed to parse owner address: %s", err)
return fmt.Errorf("😥 failed to parse owner address: %s", err)
}
Nonce = viper.GetUint64("nonce")
Amount = viper.GetUint64("amount")
Expand All @@ -166,7 +166,7 @@ func BindReshareFlags(cmd *cobra.Command) error {
}
Signatures = viper.GetString("signatures")
if Signatures == "" {
return fmt.Errorf("😥 Failed to get --signatures flag value")
return fmt.Errorf("😥 failed to get --signatures flag value")
}
if err := viper.BindPFlag("clientCACertPath", cmd.PersistentFlags().Lookup("clientCACertPath")); err != nil {
return err
Expand Down Expand Up @@ -194,7 +194,7 @@ func BindReshareFlags(cmd *cobra.Command) error {

// newOperatorIDsFlag adds new operators IDs flag to the command
func NewOperatorIDsFlag(c *cobra.Command) {
AddPersistentStringSliceFlag(c, newOperatorIDs, []string{"1", "2", "3"}, "New operator IDs for resharing ceremony", false)
AddPersistentStringSliceFlag(c, newOperatorIDs, []string{}, "New operator IDs for resharing ceremony", false)
}

// ProofsFilePath add file path to proofs flag to the command
Expand Down
18 changes: 9 additions & 9 deletions cli/flags/resign.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func BindGenerateResignMsgFlags(cmd *cobra.Command) error {
}
OperatorIDs = viper.GetStringSlice("operatorIDs")
if len(OperatorIDs) == 0 {
return fmt.Errorf("😥 Operator IDs flag cant be empty")
return fmt.Errorf("😥 operator IDs flag cant be empty")
}
OperatorsInfoPath = viper.GetString("operatorsInfoPath")
if OperatorsInfoPath != "" {
Expand All @@ -91,43 +91,43 @@ func BindGenerateResignMsgFlags(cmd *cobra.Command) error {
}
owner := viper.GetString("owner")
if owner == "" {
return fmt.Errorf("😥 Failed to get owner address flag value")
return fmt.Errorf("😥 failed to get owner address flag value")
}
Nonce = viper.GetUint64("nonce")
Amount = viper.GetUint64("amount")
if !spec.ValidAmountSet(phase0.Gwei(Amount)) {
return fmt.Errorf("🚨 Amount should be in range between 32 ETH and 2048 ETH")
return fmt.Errorf("🚨 amount should be in range between 32 ETH and 2048 ETH")
}
ProofsFilePath = viper.GetString("proofsFilePath")
if ProofsFilePath != "" {
ProofsFilePath = filepath.Clean(ProofsFilePath)
}
ProofsString = viper.GetString("proofsString")
if ProofsFilePath == "" && ProofsString == "" {
return fmt.Errorf("😥 Failed to get proofs from proofs string or path to proofs flag value")
return fmt.Errorf("😥 failed to get proofs from proofs string or path to proofs flag value")
}
if ProofsFilePath != "" && ProofsString != "" {
return fmt.Errorf("😥 proofs can be provided either as a string, or path to a file, not both")
}
if !filepath.IsLocal(ProofsFilePath) {
if ProofsFilePath != "" && !filepath.IsLocal(ProofsFilePath) {
return fmt.Errorf("😥 wrong proofsFilePath flag, should be local")
}
withdrawAddr := viper.GetString("withdrawAddress")
if withdrawAddr == "" {
return fmt.Errorf("😥 Failed to get withdrawal address flag value")
return fmt.Errorf("😥 failed to get withdrawal address flag value")
}
var err error
WithdrawAddress, err = utils.HexToAddress(withdrawAddr)
if err != nil {
return fmt.Errorf("😥 Failed to parse withdraw address: %s", err.Error())
return fmt.Errorf("😥 failed to parse withdraw address: %s", err.Error())
}
Network = viper.GetString("network")
if Network == "" {
return fmt.Errorf("😥 Failed to get fork version flag value")
return fmt.Errorf("😥 failed to get fork version flag value")
}
OwnerAddress, err = utils.HexToAddress(owner)
if err != nil {
return fmt.Errorf("😥 Failed to parse owner address: %s", err)
return fmt.Errorf("😥 failed to parse owner address: %s", err)
}
return nil
}
Expand Down
32 changes: 16 additions & 16 deletions integration_test/init_bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestBulkHappyFlows4Ops(t *testing.T) {
err := os.RemoveAll("./output/")
err := os.RemoveAll("./data/output/")
require.NoError(t, err)
err = logging.SetGlobalLogger("info", "capital", "console", nil)
require.NoError(t, err)
Expand Down Expand Up @@ -89,12 +89,12 @@ func TestBulkHappyFlows4Ops(t *testing.T) {
resetFlags(RootCmd)
})
// validate results
initCeremonies, err := os.ReadDir("./output")
initCeremonies, err := os.ReadDir("./data/output")
require.NoError(t, err)
validators := []int{1, 10, 100}
for i, c := range initCeremonies {
args := []string{"verify",
"--ceremonyDir", "./output/" + c.Name(),
"--ceremonyDir", "./data/output/" + c.Name(),
"--validators", strconv.Itoa(validators[i]),
"--withdrawAddress", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
"--owner", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
Expand All @@ -105,15 +105,15 @@ func TestBulkHappyFlows4Ops(t *testing.T) {
require.NoError(t, err)
resetFlags(RootCmd)
}
err = os.RemoveAll("./output/")
err = os.RemoveAll("./data/output/")
require.NoError(t, err)
for _, srv := range servers {
srv.HttpSrv.Close()
}
}

func TestBulkHappyFlows7Ops(t *testing.T) {
err := os.RemoveAll("./output/")
err := os.RemoveAll("./data/output/")
require.NoError(t, err)
err = logging.SetGlobalLogger("info", "capital", "console", nil)
require.NoError(t, err)
Expand Down Expand Up @@ -184,12 +184,12 @@ func TestBulkHappyFlows7Ops(t *testing.T) {
resetFlags(RootCmd)
})
// validate results
initCeremonies, err := os.ReadDir("./output")
initCeremonies, err := os.ReadDir("./data/output")
require.NoError(t, err)
validators := []int{1, 10, 100}
for i, c := range initCeremonies {
args := []string{"verify",
"--ceremonyDir", "./output/" + c.Name(),
"--ceremonyDir", "./data/output/" + c.Name(),
"--validators", strconv.Itoa(validators[i]),
"--withdrawAddress", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
"--owner", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
Expand All @@ -200,15 +200,15 @@ func TestBulkHappyFlows7Ops(t *testing.T) {
require.NoError(t, err)
resetFlags(RootCmd)
}
err = os.RemoveAll("./output/")
err = os.RemoveAll("./data/output/")
require.NoError(t, err)
for _, srv := range servers {
srv.HttpSrv.Close()
}
}

func TestBulkHappyFlows10Ops(t *testing.T) {
err := os.RemoveAll("./output/")
err := os.RemoveAll("./data/output/")
require.NoError(t, err)
err = logging.SetGlobalLogger("info", "capital", "console", nil)
require.NoError(t, err)
Expand Down Expand Up @@ -279,12 +279,12 @@ func TestBulkHappyFlows10Ops(t *testing.T) {
resetFlags(RootCmd)
})
// validate results
initCeremonies, err := os.ReadDir("./output")
initCeremonies, err := os.ReadDir("./data/output")
require.NoError(t, err)
validators := []int{1, 10, 100}
for i, c := range initCeremonies {
args := []string{"verify",
"--ceremonyDir", "./output/" + c.Name(),
"--ceremonyDir", "./data/output/" + c.Name(),
"--validators", strconv.Itoa(validators[i]),
"--withdrawAddress", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
"--owner", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
Expand All @@ -295,15 +295,15 @@ func TestBulkHappyFlows10Ops(t *testing.T) {
require.NoError(t, err)
resetFlags(RootCmd)
}
err = os.RemoveAll("./output/")
err = os.RemoveAll("./data/output/")
require.NoError(t, err)
for _, srv := range servers {
srv.HttpSrv.Close()
}
}

func TestBulkHappyFlows13Ops(t *testing.T) {
err := os.RemoveAll("./output/")
err := os.RemoveAll("./data/output/")
require.NoError(t, err)
err = logging.SetGlobalLogger("info", "capital", "console", nil)
require.NoError(t, err)
Expand Down Expand Up @@ -374,12 +374,12 @@ func TestBulkHappyFlows13Ops(t *testing.T) {
resetFlags(RootCmd)
})
// validate results
initCeremonies, err := os.ReadDir("./output")
initCeremonies, err := os.ReadDir("./data/output")
require.NoError(t, err)
validators := []int{1, 10, 100}
for i, c := range initCeremonies {
args := []string{"verify",
"--ceremonyDir", "./output/" + c.Name(),
"--ceremonyDir", "./data/output/" + c.Name(),
"--validators", strconv.Itoa(validators[i]),
"--withdrawAddress", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
"--owner", "0x81592c3de184a3e2c0dcb5a261bc107bfa91f494",
Expand All @@ -390,7 +390,7 @@ func TestBulkHappyFlows13Ops(t *testing.T) {
require.NoError(t, err)
resetFlags(RootCmd)
}
err = os.RemoveAll("./output/")
err = os.RemoveAll("./data/output/")
require.NoError(t, err)
for _, srv := range servers {
srv.HttpSrv.Close()
Expand Down
Loading

0 comments on commit 7f5f515

Please sign in to comment.