Skip to content

Commit

Permalink
Merge branch 'develop' into feat/fix-ci-builder-gcr
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 18, 2023
2 parents 46e35c7 + 0c0d452 commit 572c990
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions op-program/preimage/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (hr *HintReader) NextHint(router func(hint string) error) error {
}
}
if err := router(string(payload)); err != nil {
// stream recovery
_, _ = hr.r.Read([]byte{0})
return fmt.Errorf("failed to handle hint: %w", err)
}
if _, err := hr.r.Read([]byte{0}); err != nil {
Expand Down
18 changes: 18 additions & 0 deletions op-program/preimage/hints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package preimage
import (
"bytes"
"crypto/rand"
"errors"
"io"
"testing"

Expand Down Expand Up @@ -71,4 +72,21 @@ func TestHints(t *testing.T) {
err := hr.NextHint(func(hint string) error { return nil })
require.ErrorIs(t, err, io.ErrUnexpectedEOF)
})
t.Run("cb error", func(t *testing.T) {
var buf bytes.Buffer
hw := NewHintWriter(&buf)
hw.Hint(rawHint("one"))
hw.Hint(rawHint("two"))
hr := NewHintReader(&buf)
cbErr := errors.New("fail")
err := hr.NextHint(func(hint string) error { return cbErr })
require.ErrorIs(t, err, cbErr)
var readHint string
err = hr.NextHint(func(hint string) error {
readHint = hint
return nil
})
require.NoError(t, err)
require.Equal(t, readHint, "two")
})
}

0 comments on commit 572c990

Please sign in to comment.