55 "context"
66 "encoding/hex"
77 "io"
8+ "sync"
89 "testing"
910 "time"
1011
@@ -13,6 +14,7 @@ import (
1314 "github.com/btcsuite/btcd/wire"
1415 "github.com/lightninglabs/taproot-assets/asset"
1516 "github.com/lightninglabs/taproot-assets/commitment"
17+ "github.com/lightninglabs/taproot-assets/fn"
1618 "github.com/lightninglabs/taproot-assets/internal/test"
1719 "github.com/stretchr/testify/require"
1820)
@@ -74,6 +76,80 @@ func MockGroupAnchorVerifier(gen *asset.Genesis,
7476 return nil
7577}
7678
79+ // MockProofCourier is a mock proof courier which stores the last proof it
80+ // received.
81+ type MockProofCourier struct {
82+ sync.Mutex
83+
84+ currentProofs map [asset.SerializedKey ]* AnnotatedProof
85+
86+ subscribers map [uint64 ]* fn.EventReceiver [fn.Event ]
87+ }
88+
89+ // NewMockProofCourier returns a new mock proof courier.
90+ func NewMockProofCourier () * MockProofCourier {
91+ return & MockProofCourier {
92+ currentProofs : make (map [asset.SerializedKey ]* AnnotatedProof ),
93+ }
94+ }
95+
96+ // Start starts the proof courier service.
97+ func (m * MockProofCourier ) Start (chan error ) error {
98+ return nil
99+ }
100+
101+ // Stop stops the proof courier service.
102+ func (m * MockProofCourier ) Stop () error {
103+ return nil
104+ }
105+
106+ // DeliverProof attempts to delivery a proof to the receiver, using the
107+ // information in the Addr type.
108+ func (m * MockProofCourier ) DeliverProof (_ context.Context ,
109+ proof * AnnotatedProof ) error {
110+
111+ m .Lock ()
112+ defer m .Unlock ()
113+
114+ m .currentProofs [asset .ToSerialized (& proof .ScriptKey )] = proof
115+
116+ return nil
117+ }
118+
119+ // ReceiveProof attempts to obtain a proof as identified by the passed
120+ // locator from the source encapsulated within the specified address.
121+ func (m * MockProofCourier ) ReceiveProof (_ context.Context ,
122+ loc Locator ) (* AnnotatedProof , error ) {
123+
124+ m .Lock ()
125+ defer m .Unlock ()
126+
127+ proof , ok := m .currentProofs [asset .ToSerialized (& loc .ScriptKey )]
128+ if ! ok {
129+ return nil , ErrProofNotFound
130+ }
131+
132+ return proof , nil
133+ }
134+
135+ // SetSubscribers sets the set of subscribers that will be notified
136+ // of proof courier related events.
137+ func (m * MockProofCourier ) SetSubscribers (
138+ subscribers map [uint64 ]* fn.EventReceiver [fn.Event ]) {
139+
140+ m .Lock ()
141+ defer m .Unlock ()
142+
143+ m .subscribers = subscribers
144+ }
145+
146+ // Close stops the courier instance.
147+ func (m * MockProofCourier ) Close () error {
148+ return nil
149+ }
150+
151+ var _ Courier = (* MockProofCourier )(nil )
152+
77153type ValidTestCase struct {
78154 Proof * TestProof `json:"proof"`
79155 Expected string `json:"expected"`
0 commit comments