From c5815cb0d6177685da54b44c7a6f1426fdcaf01d Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 13 Dec 2023 15:23:03 +0100 Subject: [PATCH] proof: add MockProofCourier --- proof/mock.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/proof/mock.go b/proof/mock.go index 55c5d1ea6..60aa2681d 100644 --- a/proof/mock.go +++ b/proof/mock.go @@ -5,6 +5,7 @@ import ( "context" "encoding/hex" "io" + "sync" "testing" "time" @@ -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" ) @@ -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"`