Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Jul 18, 2023
1 parent 06d7a97 commit 6b79025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions cmd/postcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions initialization/pos_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})
}

0 comments on commit 6b79025

Please sign in to comment.