Skip to content

Commit 7113c3c

Browse files
committed
itest: minimize use of deprecated ImportProof RPC
With this commit we reduce the number of places we use the old deprecated ImportProof RPC and also make it very clear that we're using something deprecated. Because some very old tests still depend on the proof being inserted (even if the destination node doesn't have the script key to spend the assets), completely removing the use of this method will require a bigger refactor.
1 parent 0f81e47 commit 7113c3c

File tree

4 files changed

+128
-49
lines changed

4 files changed

+128
-49
lines changed

itest/addrs_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func testAddresses(t *harnessTest) {
182182
},
183183
Amount: 22,
184184
}
185-
manualAsset, mintProof := ManualMintSimpleAsset(
185+
manualAsset, mintProofBlob, mintOP := ManualMintSimpleAsset(
186186
t, t.lndHarness.Alice, t.tapd, commitment.TapCommitmentV0, &req,
187187
)
188188

@@ -191,12 +191,11 @@ func testAddresses(t *harnessTest) {
191191
respJSON, err := formatProtoJSON(manualAsset)
192192
require.NoError(t.t, err)
193193

194-
t.Logf("manually minted asset: %s", respJSON)
194+
t.Logf("Manually minted asset: %s", respJSON)
195195

196196
// Import the issuance proof to the second node so we can try to receive
197197
// it.
198-
_, err = secondTapd.ImportProof(ctxb, mintProof)
199-
require.NoError(t.t, err)
198+
ImportProofFileDeprecated(t, secondTapd, mintProofBlob, mintOP)
200199

201200
// Trying to receive the new asset to a version 0 address should
202201
// succeed.
@@ -774,7 +773,9 @@ func testUnknownTlvType(t *harnessTest) {
774773
require.NoError(t.t, charlie.stop(!*noDelete))
775774
}()
776775

777-
ImportProofFile(t, charlie, modifiedBlob, genInfo.GenesisPoint)
776+
ImportProofFileDeprecated(
777+
t, charlie, modifiedBlob, genInfo.GenesisPoint,
778+
)
778779

779780
// When we export it again, it should have the same TLV types.
780781
transferProof2 := exportProof(
@@ -845,7 +846,7 @@ func sendProof(t *harnessTest, src, dst *tapdHarness,
845846
genInfo *taprpc.GenesisInfo) {
846847

847848
proofResp := exportProof(t, src, sendResp, scriptKey, genInfo)
848-
ImportProofFile(t, dst, proofResp.RawProofFile, genInfo.GenesisPoint)
849+
ImportProofFile(t, dst, proofResp.RawProofFile)
849850
}
850851

851852
// exportProof manually exports a proof from the given source node for a
@@ -883,7 +884,7 @@ func transferProofUniRPC(t *harnessTest, src, dst *tapdHarness,
883884
t.t, src, genInfo.AssetId, scriptKey, outpoint, group,
884885
)
885886

886-
lastProof, err := proofFile.LastProof()
887+
lastProof, err := proofFile.RawLastProof()
887888
require.NoError(t.t, err)
888889

889890
return InsertProofIntoUniverse(t.t, dst, lastProof)
@@ -904,7 +905,7 @@ func transferProofNormalExportUniInsert(t *harnessTest, src, dst *tapdHarness,
904905
err := f.Decode(bytes.NewReader(proofResp.RawProofFile))
905906
require.NoError(t.t, err)
906907

907-
lastProof, err := f.LastProof()
908+
lastProof, err := f.RawLastProof()
908909
require.NoError(t.t, err)
909910

910911
return InsertProofIntoUniverse(t.t, dst, lastProof)

itest/assets_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/lightninglabs/taproot-assets/taprpc"
2222
wrpc "github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
2323
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
24-
"github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
2524
"github.com/lightningnetwork/lnd/lnrpc"
2625
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2726
"github.com/stretchr/testify/require"
@@ -238,11 +237,7 @@ func transferAssetProofs(t *harnessTest, src, dst *tapdHarness,
238237
proofFile := AssertAssetProofs(
239238
t.t, src, chainClient, existingAsset,
240239
)
241-
_, err := dst.ImportProof(ctxt, &tapdevrpc.ImportProofRequest{
242-
ProofFile: proofFile,
243-
GenesisPoint: gen.GenesisPoint,
244-
})
245-
require.NoError(t.t, err)
240+
ImportProofFileDeprecated(t, dst, proofFile, gen.GenesisPoint)
246241
}
247242

248243
listResp, err := dst.ListAssets(

itest/psbt_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,14 @@ func testPsbtMultiVersionSend(t *harnessTest) {
424424

425425
numAssets := 1
426426
AssertNumAssets(t.t, ctxb, sender, numAssets)
427-
firstAsset, _ = ManualMintSimpleAsset(
427+
firstAsset, _, _ = ManualMintSimpleAsset(
428428
t, t.lndHarness.Bob, sender, commitment.TapCommitmentV0,
429429
&firstReq,
430430
)
431431

432432
numAssets += 1
433433
AssertNumAssets(t.t, ctxb, sender, numAssets)
434-
secondAsset, _ = ManualMintSimpleAsset(
434+
secondAsset, _, _ = ManualMintSimpleAsset(
435435
t, t.lndHarness.Bob, sender, commitment.TapCommitmentV1,
436436
&secondReq,
437437
)
@@ -2681,6 +2681,13 @@ func testPsbtLockTimeSend(t *harnessTest) {
26812681
},
26822682
}
26832683

2684+
// We need to let the wallet of Bob know that we're going to use a
2685+
// script key with a custom root.
2686+
_, err = bob.DeclareScriptKey(ctxt, &wrpc.DeclareScriptKeyRequest{
2687+
ScriptKey: taprpc.MarshalScriptKey(bobAssetScriptKey),
2688+
})
2689+
require.NoError(t.t, err)
2690+
26842691
fundRespLock := fundPacket(t, alice, tappsbt.ForInteractiveSend(
26852692
id, fullAmt, bobAssetScriptKey, 0, 0, 0, bobInternalKey,
26862693
asset.V0, chainParams,
@@ -2889,6 +2896,13 @@ func testPsbtRelativeLockTimeSend(t *harnessTest) {
28892896
},
28902897
}
28912898

2899+
// We need to let the wallet of Bob know that we're going to use a
2900+
// script key with a custom root.
2901+
_, err = bob.DeclareScriptKey(ctxt, &wrpc.DeclareScriptKeyRequest{
2902+
ScriptKey: taprpc.MarshalScriptKey(bobAssetScriptKey),
2903+
})
2904+
require.NoError(t.t, err)
2905+
28922906
fundRespLock := fundPacket(t, alice, tappsbt.ForInteractiveSend(
28932907
id, fullAmt, bobAssetScriptKey, 0, 0, 0, bobInternalKey,
28942908
asset.V0, chainParams,
@@ -3098,6 +3112,13 @@ func testPsbtRelativeLockTimeSendProofFail(t *harnessTest) {
30983112
},
30993113
}
31003114

3115+
// We need to let the wallet of Bob know that we're going to use a
3116+
// script key with a custom root.
3117+
_, err = bob.DeclareScriptKey(ctxt, &wrpc.DeclareScriptKeyRequest{
3118+
ScriptKey: taprpc.MarshalScriptKey(bobAssetScriptKey),
3119+
})
3120+
require.NoError(t.t, err)
3121+
31013122
fundRespLock := fundPacket(t, alice, tappsbt.ForInteractiveSend(
31023123
id, fullAmt, bobAssetScriptKey, 0, 0, 0, bobInternalKey,
31033124
asset.V0, chainParams,

itest/utils.go

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ func ConfirmBatch(t *testing.T, minerClient *rpcclient.Client,
564564

565565
func ManualMintSimpleAsset(t *harnessTest, lndNode *node.HarnessNode,
566566
tapClient *tapdHarness, commitVersion commitment.TapCommitmentVersion,
567-
req *mintrpc.MintAsset) (*taprpc.Asset, *tapdevrpc.ImportProofRequest) {
567+
req *mintrpc.MintAsset) (*taprpc.Asset, proof.Blob, string) {
568568

569569
ctxb := context.Background()
570570
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
@@ -725,12 +725,9 @@ func ManualMintSimpleAsset(t *harnessTest, lndNode *node.HarnessNode,
725725
require.NoError(t.t, err)
726726
require.True(t.t, proof.IsProofFile(proofBlob))
727727

728-
importReq := tapdevrpc.ImportProofRequest{
729-
ProofFile: proofBlob,
730-
GenesisPoint: genesisOutpoint.String(),
731-
}
732-
_, err = tapClient.ImportProof(ctxb, &importReq)
733-
require.NoError(t.t, err)
728+
ImportProofFileDeprecated(
729+
t, tapClient, proofBlob, genesisOutpoint.String(),
730+
)
734731

735732
// After proof import, the minted assets should appear in the output of
736733
// ListAssets.
@@ -743,7 +740,7 @@ func ManualMintSimpleAsset(t *harnessTest, lndNode *node.HarnessNode,
743740
confEvent.Block.BlockHash(),
744741
)
745742

746-
return mintedAsset[0], &importReq
743+
return mintedAsset[0], proofBlob, genesisOutpoint.String()
747744
}
748745

749746
// ExternalSigRes is a helper struct that holds the signed PSBT and the
@@ -1009,9 +1006,73 @@ func ExportProofFile(t *testing.T, src *tapdHarness, assetID, scriptKey []byte,
10091006
return proofResp
10101007
}
10111008

1012-
// ImportProofFile manually imports a proof file using the development only
1013-
// ImportProof RPC.
1009+
// ImportProofFile manually imports a proof file into the given node's universe,
1010+
// then registers the inbound transfer to make the wallet aware of the new asset
1011+
// it received.
10141012
func ImportProofFile(t *harnessTest, dst commands.RpcClientsBundle,
1013+
rawFile proof.Blob) {
1014+
1015+
t.Logf("Importing proof %x", rawFile)
1016+
1017+
ctxb := context.Background()
1018+
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
1019+
defer cancel()
1020+
1021+
resp, err := dst.UnpackProofFile(ctxt, &taprpc.UnpackProofFileRequest{
1022+
RawProofFile: rawFile,
1023+
})
1024+
require.NoError(t.t, err)
1025+
1026+
// Import the proof into the universe.
1027+
var lastProof *unirpc.AssetProofResponse
1028+
for _, rawProof := range resp.RawProofs {
1029+
lastProof = InsertProofIntoUniverse(t.t, dst, rawProof)
1030+
}
1031+
require.NotNil(t.t, lastProof)
1032+
require.NotNil(t.t, lastProof.AssetLeaf)
1033+
require.NotNil(t.t, lastProof.AssetLeaf.Proof)
1034+
1035+
// The proof leaf only contains the actual asset and none of the
1036+
// taprpc.ChainAsset fields. So for anything related to the actual chain
1037+
// output, we need to decode the proof in the leaf.
1038+
decodeResp, err := dst.DecodeProof(ctxt, &taprpc.DecodeProofRequest{
1039+
RawProof: lastProof.AssetLeaf.Proof,
1040+
})
1041+
require.NoError(t.t, err)
1042+
1043+
proofAsset := lastProof.AssetLeaf.Asset
1044+
chainAnchor := decodeResp.DecodedProof.Asset.ChainAnchor
1045+
op, err := wire.NewOutPointFromString(chainAnchor.AnchorOutpoint)
1046+
require.NoError(t.t, err)
1047+
1048+
var groupKey []byte
1049+
if proofAsset.AssetGroup != nil {
1050+
groupKey = proofAsset.AssetGroup.TweakedGroupKey
1051+
}
1052+
1053+
// In order for Bob to expect this incoming transfer, we need to
1054+
// register it with the internal wallet of Bob.
1055+
registerResp, err := dst.RegisterTransfer(
1056+
ctxb, &taprpc.RegisterTransferRequest{
1057+
AssetId: proofAsset.AssetGenesis.AssetId,
1058+
GroupKey: groupKey,
1059+
ScriptKey: proofAsset.ScriptKey,
1060+
Outpoint: &taprpc.OutPoint{
1061+
Txid: op.Hash[:],
1062+
OutputIndex: op.Index,
1063+
},
1064+
},
1065+
)
1066+
require.NoError(t.t, err)
1067+
require.Equal(
1068+
t.t, proofAsset.ScriptKey,
1069+
registerResp.RegisteredAsset.ScriptKey,
1070+
)
1071+
}
1072+
1073+
// ImportProofFileDeprecated manually imports a proof file using the development
1074+
// only ImportProof RPC.
1075+
func ImportProofFileDeprecated(t *harnessTest, dst commands.RpcClientsBundle,
10151076
rawFile proof.Blob,
10161077
genesisPoint string) *tapdevrpc.ImportProofResponse {
10171078

@@ -1114,54 +1175,55 @@ func ExportProofFileFromUniverse(t *testing.T, src commands.RpcClientsBundle,
11141175
// InsertProofIntoUniverse manually inserts a proof into the given node using
11151176
// the universe related InsertProof RPC.
11161177
func InsertProofIntoUniverse(t *testing.T, dst commands.RpcClientsBundle,
1117-
proof *proof.Proof) *unirpc.AssetProofResponse {
1178+
proofBytes proof.Blob) *unirpc.AssetProofResponse {
11181179

11191180
ctxb := context.Background()
11201181
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
11211182
defer cancel()
11221183

1123-
var lastProofBytes bytes.Buffer
1124-
err := proof.Encode(&lastProofBytes)
1184+
resp, err := dst.DecodeProof(ctxt, &taprpc.DecodeProofRequest{
1185+
RawProof: proofBytes,
1186+
WithMetaReveal: true,
1187+
WithPrevWitnesses: true,
1188+
})
11251189
require.NoError(t, err)
11261190

1127-
proofAsset := proof.Asset
1128-
1129-
proofType := universe.ProofTypeTransfer
1130-
if proofAsset.IsGenesisAsset() {
1131-
proofType = universe.ProofTypeIssuance
1132-
}
1191+
rpcProof := resp.DecodedProof
1192+
rpcAsset := rpcProof.Asset
1193+
rpcAnchor := rpcAsset.ChainAnchor
11331194

11341195
uniID := universe.Identifier{
1135-
AssetID: proofAsset.ID(),
1136-
ProofType: proofType,
1196+
ProofType: universe.ProofTypeTransfer,
1197+
}
1198+
if rpcProof.GenesisReveal != nil {
1199+
uniID.ProofType = universe.ProofTypeIssuance
11371200
}
1138-
if proofAsset.GroupKey != nil {
1139-
uniID.GroupKey = &proofAsset.GroupKey.GroupPubKey
1201+
1202+
copy(uniID.AssetID[:], rpcAsset.AssetGenesis.AssetId)
1203+
if rpcAsset.AssetGroup != nil {
1204+
uniID.GroupKey, err = btcec.ParsePubKey(
1205+
rpcAsset.AssetGroup.TweakedGroupKey,
1206+
)
1207+
require.NoError(t, err)
11401208
}
11411209

11421210
rpcUniID, err := taprootassets.MarshalUniID(uniID)
11431211
require.NoError(t, err)
11441212

1145-
rpcOutPoint := &unirpc.Outpoint{
1146-
HashStr: proof.AnchorTx.TxHash().String(),
1147-
Index: int32(proof.InclusionProof.OutputIndex),
1148-
}
1149-
1150-
scriptKeyBytes := proofAsset.ScriptKey.PubKey.SerializeCompressed()
11511213
importResp, err := dst.InsertProof(ctxt, &unirpc.AssetProof{
11521214
Key: &unirpc.UniverseKey{
11531215
Id: rpcUniID,
11541216
LeafKey: &unirpc.AssetKey{
1155-
Outpoint: &unirpc.AssetKey_Op{
1156-
Op: rpcOutPoint,
1217+
Outpoint: &unirpc.AssetKey_OpStr{
1218+
OpStr: rpcAnchor.AnchorOutpoint,
11571219
},
11581220
ScriptKey: &unirpc.AssetKey_ScriptKeyBytes{
1159-
ScriptKeyBytes: scriptKeyBytes,
1221+
ScriptKeyBytes: rpcAsset.ScriptKey,
11601222
},
11611223
},
11621224
},
11631225
AssetLeaf: &unirpc.AssetLeaf{
1164-
Proof: lastProofBytes.Bytes(),
1226+
Proof: proofBytes,
11651227
},
11661228
})
11671229
require.NoError(t, err)

0 commit comments

Comments
 (0)