Skip to content

Commit d7ff486

Browse files
committed
proof: export RandProof function
1 parent 4fa9f73 commit d7ff486

File tree

4 files changed

+132
-131
lines changed

4 files changed

+132
-131
lines changed

proof/archive_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,17 @@ func TestMigrateOldFileNames(t *testing.T) {
292292
scriptKey2 := test.RandPubKey(t)
293293

294294
// We create 4 different proofs with the old naming scheme.
295-
proof1 := randomProof(t, genesis1, scriptKey1, oddTxBlock, 0, 1)
295+
proof1 := RandProof(t, genesis1, scriptKey1, oddTxBlock, 0, 1)
296296
storeProofOldName(proof1)
297-
proof2 := randomProof(t, genesis1, scriptKey2, oddTxBlock, 0, 1)
297+
proof2 := RandProof(t, genesis1, scriptKey2, oddTxBlock, 0, 1)
298298
storeProofOldName(proof2)
299-
proof3 := randomProof(t, genesis2, scriptKey1, oddTxBlock, 1, 1)
299+
proof3 := RandProof(t, genesis2, scriptKey1, oddTxBlock, 1, 1)
300300
storeProofOldName(proof3)
301-
proof4 := randomProof(t, genesis2, scriptKey2, oddTxBlock, 1, 1)
301+
proof4 := RandProof(t, genesis2, scriptKey2, oddTxBlock, 1, 1)
302302
storeProofOldName(proof4)
303303

304304
// We also create a proof with the new naming scheme.
305-
proof5 := randomProof(t, genesis1, scriptKey1, oddTxBlock, 1, 1)
305+
proof5 := RandProof(t, genesis1, scriptKey1, oddTxBlock, 1, 1)
306306
storeProofNewName(proof5)
307307

308308
// We now create the file archive and expect the 4 proofs to be renamed.
@@ -322,7 +322,7 @@ func TestMigrateOldFileNames(t *testing.T) {
322322

323323
// We should be able to import a new proof, and it should be stored
324324
// under the new naming scheme.
325-
proof6 := randomProof(t, genesis2, scriptKey2, oddTxBlock, 2, 1)
325+
proof6 := RandProof(t, genesis2, scriptKey2, oddTxBlock, 2, 1)
326326
err = fileArchive.ImportProofs(nil, nil, nil, false, &AnnotatedProof{
327327
Locator: Locator{
328328
AssetID: fn.Ptr(proof6.Asset.ID()),

proof/courier_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestUniverseRpcCourierLocalArchiveShortCut(t *testing.T) {
6464

6565
genesis := asset.RandGenesis(t, asset.Collectible)
6666
scriptKey := test.RandPubKey(t)
67-
proof := randomProof(t, genesis, scriptKey, oddTxBlock, 0, 1)
67+
proof := RandProof(t, genesis, scriptKey, oddTxBlock, 0, 1)
6868

6969
file, err := NewFile(V0, proof, proof)
7070
require.NoError(t, err)

proof/mock.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,139 @@ import (
1111
"time"
1212

1313
"github.com/btcsuite/btcd/btcec/v2"
14+
"github.com/btcsuite/btcd/btcec/v2/schnorr"
1415
"github.com/btcsuite/btcd/chaincfg/chainhash"
16+
"github.com/btcsuite/btcd/txscript"
1517
"github.com/btcsuite/btcd/wire"
1618
"github.com/lightninglabs/taproot-assets/asset"
1719
"github.com/lightninglabs/taproot-assets/commitment"
1820
"github.com/lightninglabs/taproot-assets/fn"
1921
"github.com/lightninglabs/taproot-assets/internal/test"
22+
"github.com/lightningnetwork/lnd/keychain"
2023
"github.com/stretchr/testify/require"
2124
)
2225

26+
func RandProof(t testing.TB, genesis asset.Genesis,
27+
scriptKey *btcec.PublicKey, block wire.MsgBlock, txIndex int,
28+
outputIndex uint32) Proof {
29+
30+
txMerkleProof, err := NewTxMerkleProof(block.Transactions, txIndex)
31+
require.NoError(t, err)
32+
33+
tweakedScriptKey := asset.NewScriptKey(scriptKey)
34+
protoAsset := asset.NewAssetNoErr(
35+
t, genesis, 1, 0, 0, tweakedScriptKey, nil,
36+
)
37+
groupKey := asset.RandGroupKey(t, genesis, protoAsset)
38+
groupReveal := asset.GroupKeyReveal{
39+
RawKey: asset.ToSerialized(&groupKey.GroupPubKey),
40+
TapscriptRoot: test.RandBytes(32),
41+
}
42+
43+
amount := uint64(1)
44+
mintCommitment, assets, err := commitment.Mint(
45+
genesis, groupKey, &commitment.AssetDetails{
46+
Type: genesis.Type,
47+
ScriptKey: test.PubToKeyDesc(scriptKey),
48+
Amount: &amount,
49+
LockTime: 1337,
50+
RelativeLockTime: 6,
51+
},
52+
)
53+
require.NoError(t, err)
54+
proofAsset := assets[0]
55+
proofAsset.GroupKey.RawKey = keychain.KeyDescriptor{}
56+
57+
// Empty the group witness, since it will eventually be stored as the
58+
// asset's witness within the proof.
59+
// TODO(guggero): Actually store the witness in the proof.
60+
proofAsset.GroupKey.Witness = nil
61+
62+
// Empty the raw script key, since we only serialize the tweaked
63+
// pubkey. We'll also force the main script key to be an x-only key as
64+
// well.
65+
proofAsset.ScriptKey.PubKey, err = schnorr.ParsePubKey(
66+
schnorr.SerializePubKey(proofAsset.ScriptKey.PubKey),
67+
)
68+
require.NoError(t, err)
69+
70+
proofAsset.ScriptKey.TweakedScriptKey = nil
71+
72+
_, commitmentProof, err := mintCommitment.Proof(
73+
proofAsset.TapCommitmentKey(), proofAsset.AssetCommitmentKey(),
74+
)
75+
require.NoError(t, err)
76+
77+
leaf1 := txscript.NewBaseTapLeaf([]byte{1})
78+
leaf2 := txscript.NewBaseTapLeaf([]byte{2})
79+
testLeafPreimage := commitment.NewPreimageFromLeaf(leaf1)
80+
testLeafPreimage2 := commitment.NewPreimageFromLeaf(leaf2)
81+
testBranchPreimage := commitment.NewPreimageFromBranch(
82+
txscript.NewTapBranch(leaf1, leaf2),
83+
)
84+
return Proof{
85+
PrevOut: genesis.FirstPrevOut,
86+
BlockHeader: block.Header,
87+
BlockHeight: 42,
88+
AnchorTx: *block.Transactions[txIndex],
89+
TxMerkleProof: *txMerkleProof,
90+
Asset: *proofAsset,
91+
InclusionProof: TaprootProof{
92+
OutputIndex: outputIndex,
93+
InternalKey: test.RandPubKey(t),
94+
CommitmentProof: &CommitmentProof{
95+
Proof: *commitmentProof,
96+
TapSiblingPreimage: testLeafPreimage,
97+
},
98+
TapscriptProof: nil,
99+
},
100+
ExclusionProofs: []TaprootProof{
101+
{
102+
OutputIndex: 2,
103+
InternalKey: test.RandPubKey(t),
104+
CommitmentProof: &CommitmentProof{
105+
Proof: *commitmentProof,
106+
TapSiblingPreimage: testLeafPreimage,
107+
},
108+
TapscriptProof: nil,
109+
},
110+
{
111+
OutputIndex: 3,
112+
InternalKey: test.RandPubKey(t),
113+
CommitmentProof: nil,
114+
TapscriptProof: &TapscriptProof{
115+
TapPreimage1: testBranchPreimage,
116+
TapPreimage2: testLeafPreimage2,
117+
Bip86: true,
118+
},
119+
},
120+
{
121+
OutputIndex: 4,
122+
InternalKey: test.RandPubKey(t),
123+
CommitmentProof: nil,
124+
TapscriptProof: &TapscriptProof{
125+
Bip86: true,
126+
},
127+
},
128+
},
129+
SplitRootProof: &TaprootProof{
130+
OutputIndex: 4,
131+
InternalKey: test.RandPubKey(t),
132+
CommitmentProof: &CommitmentProof{
133+
Proof: *commitmentProof,
134+
TapSiblingPreimage: nil,
135+
},
136+
},
137+
MetaReveal: &MetaReveal{
138+
Data: []byte("quoth the raven nevermore"),
139+
Type: MetaOpaque,
140+
},
141+
ChallengeWitness: wire.TxWitness{[]byte("foo"), []byte("bar")},
142+
GenesisReveal: &genesis,
143+
GroupKeyReveal: &groupReveal,
144+
}
145+
}
146+
23147
type MockVerifier struct {
24148
t *testing.T
25149
}

proof/proof_test.go

Lines changed: 1 addition & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/btcsuite/btcd/blockchain"
1616
"github.com/btcsuite/btcd/btcec/v2"
17-
"github.com/btcsuite/btcd/btcec/v2/schnorr"
1817
"github.com/btcsuite/btcd/btcutil"
1918
"github.com/btcsuite/btcd/chaincfg"
2019
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -26,7 +25,6 @@ import (
2625
"github.com/lightninglabs/taproot-assets/commitment"
2726
"github.com/lightninglabs/taproot-assets/internal/test"
2827
"github.com/lightningnetwork/lnd/build"
29-
"github.com/lightningnetwork/lnd/keychain"
3028
"github.com/stretchr/testify/require"
3129
)
3230

@@ -138,127 +136,6 @@ func assertEqualProof(t *testing.T, expected, actual *Proof) {
138136
require.Equal(t, expected.ChallengeWitness, actual.ChallengeWitness)
139137
}
140138

141-
func randomProof(t *testing.T, genesis asset.Genesis,
142-
scriptKey *btcec.PublicKey, block wire.MsgBlock, txIndex int,
143-
outputIndex uint32) Proof {
144-
145-
txMerkleProof, err := NewTxMerkleProof(block.Transactions, txIndex)
146-
require.NoError(t, err)
147-
148-
tweakedScriptKey := asset.NewScriptKey(scriptKey)
149-
protoAsset := asset.NewAssetNoErr(
150-
t, genesis, 1, 0, 0, tweakedScriptKey, nil,
151-
)
152-
groupKey := asset.RandGroupKey(t, genesis, protoAsset)
153-
groupReveal := asset.GroupKeyReveal{
154-
RawKey: asset.ToSerialized(&groupKey.GroupPubKey),
155-
TapscriptRoot: test.RandBytes(32),
156-
}
157-
158-
mintCommitment, assets, err := commitment.Mint(
159-
genesis, groupKey, &commitment.AssetDetails{
160-
Type: asset.Collectible,
161-
ScriptKey: test.PubToKeyDesc(scriptKey),
162-
Amount: nil,
163-
LockTime: 1337,
164-
RelativeLockTime: 6,
165-
},
166-
)
167-
require.NoError(t, err)
168-
proofAsset := assets[0]
169-
proofAsset.GroupKey.RawKey = keychain.KeyDescriptor{}
170-
171-
// Empty the group witness, since it will eventually be stored as the
172-
// asset's witness within the proof.
173-
// TODO(guggero): Actually store the witness in the proof.
174-
proofAsset.GroupKey.Witness = nil
175-
176-
// Empty the raw script key, since we only serialize the tweaked
177-
// pubkey. We'll also force the main script key to be an x-only key as
178-
// well.
179-
proofAsset.ScriptKey.PubKey, err = schnorr.ParsePubKey(
180-
schnorr.SerializePubKey(proofAsset.ScriptKey.PubKey),
181-
)
182-
require.NoError(t, err)
183-
184-
proofAsset.ScriptKey.TweakedScriptKey = nil
185-
186-
_, commitmentProof, err := mintCommitment.Proof(
187-
proofAsset.TapCommitmentKey(), proofAsset.AssetCommitmentKey(),
188-
)
189-
require.NoError(t, err)
190-
191-
leaf1 := txscript.NewBaseTapLeaf([]byte{1})
192-
leaf2 := txscript.NewBaseTapLeaf([]byte{2})
193-
testLeafPreimage := commitment.NewPreimageFromLeaf(leaf1)
194-
testLeafPreimage2 := commitment.NewPreimageFromLeaf(leaf2)
195-
testBranchPreimage := commitment.NewPreimageFromBranch(
196-
txscript.NewTapBranch(leaf1, leaf2),
197-
)
198-
return Proof{
199-
PrevOut: genesis.FirstPrevOut,
200-
BlockHeader: block.Header,
201-
BlockHeight: 42,
202-
AnchorTx: *block.Transactions[txIndex],
203-
TxMerkleProof: *txMerkleProof,
204-
Asset: *proofAsset,
205-
InclusionProof: TaprootProof{
206-
OutputIndex: outputIndex,
207-
InternalKey: test.RandPubKey(t),
208-
CommitmentProof: &CommitmentProof{
209-
Proof: *commitmentProof,
210-
TapSiblingPreimage: testLeafPreimage,
211-
},
212-
TapscriptProof: nil,
213-
},
214-
ExclusionProofs: []TaprootProof{
215-
{
216-
OutputIndex: 2,
217-
InternalKey: test.RandPubKey(t),
218-
CommitmentProof: &CommitmentProof{
219-
Proof: *commitmentProof,
220-
TapSiblingPreimage: testLeafPreimage,
221-
},
222-
TapscriptProof: nil,
223-
},
224-
{
225-
OutputIndex: 3,
226-
InternalKey: test.RandPubKey(t),
227-
CommitmentProof: nil,
228-
TapscriptProof: &TapscriptProof{
229-
TapPreimage1: testBranchPreimage,
230-
TapPreimage2: testLeafPreimage2,
231-
Bip86: true,
232-
},
233-
},
234-
{
235-
OutputIndex: 4,
236-
InternalKey: test.RandPubKey(t),
237-
CommitmentProof: nil,
238-
TapscriptProof: &TapscriptProof{
239-
Bip86: true,
240-
},
241-
},
242-
},
243-
SplitRootProof: &TaprootProof{
244-
OutputIndex: 4,
245-
InternalKey: test.RandPubKey(t),
246-
CommitmentProof: &CommitmentProof{
247-
Proof: *commitmentProof,
248-
TapSiblingPreimage: nil,
249-
},
250-
},
251-
MetaReveal: &MetaReveal{
252-
Data: []byte("quoth the raven nevermore"),
253-
Type: MetaOpaque,
254-
},
255-
AdditionalInputs: []File{},
256-
ChallengeWitness: wire.TxWitness{[]byte("foo"), []byte("bar")},
257-
GenesisReveal: &genesis,
258-
GroupKeyReveal: &groupReveal,
259-
}
260-
}
261-
262139
func TestProofEncoding(t *testing.T) {
263140
t.Parallel()
264141

@@ -267,7 +144,7 @@ func TestProofEncoding(t *testing.T) {
267144

268145
genesis := asset.RandGenesis(t, asset.Collectible)
269146
scriptKey := test.RandPubKey(t)
270-
proof := randomProof(t, genesis, scriptKey, oddTxBlock, 0, 1)
147+
proof := RandProof(t, genesis, scriptKey, oddTxBlock, 0, 1)
271148

272149
file, err := NewFile(V0, proof, proof)
273150
require.NoError(t, err)

0 commit comments

Comments
 (0)