Skip to content

Commit d81d3a9

Browse files
committed
supplyverifer: test FetchPreCommits and FetchDelegationKey
Add unit tests and supporting mock functionality.
1 parent 8b4756f commit d81d3a9

File tree

2 files changed

+855
-0
lines changed

2 files changed

+855
-0
lines changed

universe/supplyverifier/mock.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package supplyverifier
2+
3+
import (
4+
"context"
5+
6+
"github.com/btcsuite/btcd/wire"
7+
"github.com/lightninglabs/taproot-assets/asset"
8+
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
9+
lfn "github.com/lightningnetwork/lnd/fn/v2"
10+
"github.com/stretchr/testify/mock"
11+
)
12+
13+
// MockSupplyCommitView is a mock implementation of the SupplyCommitView
14+
// interface.
15+
type MockSupplyCommitView struct {
16+
mock.Mock
17+
}
18+
19+
func (m *MockSupplyCommitView) UnspentPrecommits(ctx context.Context,
20+
assetSpec asset.Specifier,
21+
localIssuerOnly bool) lfn.Result[supplycommit.PreCommits] {
22+
23+
args := m.Called(ctx, assetSpec, localIssuerOnly)
24+
return args.Get(0).(lfn.Result[supplycommit.PreCommits])
25+
}
26+
27+
func (m *MockSupplyCommitView) FetchStartingCommitment(ctx context.Context,
28+
assetSpec asset.Specifier) (*supplycommit.RootCommitment, error) {
29+
30+
args := m.Called(ctx, assetSpec)
31+
if args.Get(0) == nil {
32+
return nil, args.Error(1)
33+
}
34+
return args.Get(0).(*supplycommit.RootCommitment), args.Error(1)
35+
}
36+
37+
func (m *MockSupplyCommitView) FetchLatestCommitment(ctx context.Context,
38+
assetSpec asset.Specifier) (*supplycommit.RootCommitment, error) {
39+
40+
args := m.Called(ctx, assetSpec)
41+
if args.Get(0) == nil {
42+
return nil, args.Error(1)
43+
}
44+
return args.Get(0).(*supplycommit.RootCommitment), args.Error(1)
45+
}
46+
47+
func (m *MockSupplyCommitView) FetchCommitmentByOutpoint(ctx context.Context,
48+
assetSpec asset.Specifier,
49+
outpoint wire.OutPoint) (*supplycommit.RootCommitment, error) {
50+
51+
args := m.Called(ctx, assetSpec, outpoint)
52+
if args.Get(0) == nil {
53+
return nil, args.Error(1)
54+
}
55+
return args.Get(0).(*supplycommit.RootCommitment), args.Error(1)
56+
}
57+
58+
func (m *MockSupplyCommitView) FetchCommitmentBySpentOutpoint(
59+
ctx context.Context, assetSpec asset.Specifier,
60+
spentOutpoint wire.OutPoint) (*supplycommit.RootCommitment, error) {
61+
62+
args := m.Called(ctx, assetSpec, spentOutpoint)
63+
if args.Get(0) == nil {
64+
return nil, args.Error(1)
65+
}
66+
return args.Get(0).(*supplycommit.RootCommitment), args.Error(1)
67+
}
68+
69+
func (m *MockSupplyCommitView) InsertSupplyCommit(ctx context.Context,
70+
assetSpec asset.Specifier, commit supplycommit.RootCommitment,
71+
leaves supplycommit.SupplyLeaves,
72+
unspentPreCommits supplycommit.PreCommits) error {
73+
74+
args := m.Called(ctx, assetSpec, commit, leaves, unspentPreCommits)
75+
return args.Error(0)
76+
}

0 commit comments

Comments
 (0)