diff --git a/cmd/postcli/main.go b/cmd/postcli/main.go index 19cc44bda..94e46defe 100644 --- a/cmd/postcli/main.go +++ b/cmd/postcli/main.go @@ -135,8 +135,10 @@ func main() { postrs.SetLogCallback(zapLog) if verifyPos { - ec := cmdVerifyPos(opts, fraction) - os.Exit(ec) + if cmdVerifyPos(opts, fraction) != nil { + os.Exit(1) + } + os.Exit(0) } if err := processFlags(); err != nil { @@ -212,7 +214,7 @@ func saveKey(key ed25519.PrivateKey) error { return nil } -func cmdVerifyPos(opts config.InitOpts, fraction float64) int { +func cmdVerifyPos(opts config.InitOpts, fraction float64) error { params := postrs.TranslateScryptParams(opts.Scrypt.N, opts.Scrypt.R, opts.Scrypt.P) verifyOpts := []postrs.VerifyPosOptionsFunc{ postrs.WithFraction(fraction), @@ -226,12 +228,10 @@ func cmdVerifyPos(opts config.InitOpts, fraction float64) int { switch { case err == nil: log.Println("cli: POS data is valid") - return 0 case errors.Is(err, postrs.ErrInvalidPos): - log.Println(err) - return 1 + log.Printf("cli: %v\n", err) default: log.Printf("cli: failed (%v)\n", err) - return 2 } + return err } diff --git a/initialization/pos_verification_test.go b/initialization/pos_verification_test.go index 355041536..a144e8a82 100644 --- a/initialization/pos_verification_test.go +++ b/initialization/pos_verification_test.go @@ -45,7 +45,7 @@ func TestVerifyPos(t *testing.T) { t.Run("invalid N", func(t *testing.T) { wrongScrypt := postrs.TranslateScryptParams(4, opts.Scrypt.R, opts.Scrypt.P) err := postrs.VerifyPos(opts.DataDir, wrongScrypt, postrs.WithFraction(100.0)) - require.ErrorContains(t, err, "invalid POS") + require.ErrorIs(t, err, postrs.ErrInvalidPos) }) t.Run("corrupted data", func(t *testing.T) { file, err := os.OpenFile(opts.DataDir+"/postdata_0.bin", os.O_WRONLY, 0) @@ -55,6 +55,6 @@ func TestVerifyPos(t *testing.T) { require.NoError(t, err) err = postrs.VerifyPos(opts.DataDir, scryptParams, postrs.WithFraction(100.0)) - require.ErrorContains(t, err, "invalid POS") + require.ErrorIs(t, err, postrs.ErrInvalidPos) }) }