Skip to content

Commit

Permalink
proof: add MockProofCourier
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Dec 13, 2023
1 parent a0b3b09 commit c5815cb
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions proof/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/hex"
"io"
"sync"
"testing"
"time"

Expand All @@ -13,6 +14,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/commitment"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/internal/test"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -74,6 +76,61 @@ func MockGroupAnchorVerifier(gen *asset.Genesis,
return nil
}

// MockProofCourier is a mock proof courier which stores the last proof it
// received.
type MockProofCourier struct {
sync.Mutex

currentProof *AnnotatedProof

subscribers map[uint64]*fn.EventReceiver[fn.Event]
}

// Start starts the proof courier service.
func (m *MockProofCourier) Start(chan error) error {
return nil
}

// Stop stops the proof courier service.
func (m *MockProofCourier) Stop() error {
return nil
}

// DeliverProof attempts to delivery a proof to the receiver, using the
// information in the Addr type.
func (m *MockProofCourier) DeliverProof(_ context.Context,
proof *AnnotatedProof) error {

m.Lock()
defer m.Unlock()

m.currentProof = proof

return nil
}

// ReceiveProof attempts to obtain a proof as identified by the passed
// locator from the source encapsulated within the specified address.
func (m *MockProofCourier) ReceiveProof(context.Context,
Locator) (*AnnotatedProof, error) {

m.Lock()
defer m.Unlock()

return m.currentProof, nil
}

// SetSubscribers sets the set of subscribers that will be notified
// of proof courier related events.
func (m *MockProofCourier) SetSubscribers(
subscribers map[uint64]*fn.EventReceiver[fn.Event]) {

m.Lock()
defer m.Unlock()

m.subscribers = subscribers
}

type ValidTestCase struct {
Proof *TestProof `json:"proof"`
Expected string `json:"expected"`
Expand Down

0 comments on commit c5815cb

Please sign in to comment.