Skip to content

Commit 3fbacbb

Browse files
committed
itest: rename transfer helpers to make use more clear
There are several ways to transfer a proof from one node to another. We make the actual purpose of two of these helper functions more clear by refactoring and renaming them.
1 parent 80af8ad commit 3fbacbb

File tree

5 files changed

+220
-194
lines changed

5 files changed

+220
-194
lines changed

itest/addrs_test.go

Lines changed: 22 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66

7-
"github.com/btcsuite/btcd/btcec/v2"
87
"github.com/btcsuite/btcd/btcec/v2/schnorr"
98
"github.com/btcsuite/btcd/wire"
109
tap "github.com/lightninglabs/taproot-assets"
@@ -776,7 +775,7 @@ func testUnknownTlvType(t *harnessTest) {
776775
require.NoError(t.t, charlie.stop(!*noDelete))
777776
}()
778777

779-
importProof(t, charlie, modifiedBlob, genInfo.GenesisPoint)
778+
ImportProofFile(t, charlie, modifiedBlob, genInfo.GenesisPoint)
780779

781780
// When we export it again, it should have the same TLV types.
782781
transferProof2 := exportProof(
@@ -847,7 +846,9 @@ func sendProof(t *harnessTest, src, dst *tapdHarness,
847846
genInfo *taprpc.GenesisInfo) *tapdevrpc.ImportProofResponse {
848847

849848
proofResp := exportProof(t, src, sendResp, scriptKey, genInfo)
850-
return importProof(t, dst, proofResp.RawProofFile, genInfo.GenesisPoint)
849+
return ImportProofFile(
850+
t, dst, proofResp.RawProofFile, genInfo.GenesisPoint,
851+
)
851852
}
852853

853854
// exportProof manually exports a proof from the given source node for a
@@ -856,8 +857,6 @@ func exportProof(t *harnessTest, src *tapdHarness,
856857
sendResp *taprpc.SendAssetResponse, scriptKey []byte,
857858
genInfo *taprpc.GenesisInfo) *taprpc.ProofFile {
858859

859-
ctxb := context.Background()
860-
861860
// We need to find the outpoint of the asset we sent to the address.
862861
var outpoint *taprpc.OutPoint
863862
for _, out := range sendResp.Transfer.Outputs {
@@ -874,157 +873,33 @@ func exportProof(t *harnessTest, src *tapdHarness,
874873
}
875874
}
876875

877-
var proofResp *taprpc.ProofFile
878-
waitErr := wait.NoError(func() error {
879-
resp, err := src.ExportProof(ctxb, &taprpc.ExportProofRequest{
880-
AssetId: genInfo.AssetId,
881-
ScriptKey: scriptKey,
882-
Outpoint: outpoint,
883-
})
884-
if err != nil {
885-
return err
886-
}
887-
888-
proofResp = resp
889-
return nil
890-
}, defaultWaitTimeout)
891-
require.NoError(t.t, waitErr)
892-
893-
return proofResp
876+
return ExportProofFile(t.t, src, genInfo.AssetId, scriptKey, outpoint)
894877
}
895878

896-
// importProof manually imports a proof using the development only ImportProof
897-
// RPC.
898-
func importProof(t *harnessTest, dst *tapdHarness, rawFile []byte,
899-
genesisPoint string) *tapdevrpc.ImportProofResponse {
900-
901-
t.Logf("Importing proof %x", rawFile)
902-
903-
ctxb := context.Background()
904-
importResp, err := dst.ImportProof(ctxb, &tapdevrpc.ImportProofRequest{
905-
ProofFile: rawFile,
906-
GenesisPoint: genesisPoint,
907-
})
908-
require.NoError(t.t, err)
909-
910-
return importResp
911-
}
912-
913-
// sendUniProof manually exports a proof from the given source using the
914-
// universe RPCs and then imports it into the destination node.
915-
func sendUniProof(t *harnessTest, src, dst *tapdHarness, scriptKey []byte,
916-
genInfo *taprpc.GenesisInfo, group *taprpc.AssetGroup,
917-
outpoint string) *tapdevrpc.ImportProofResponse {
918-
919-
ctxb := context.Background()
920-
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
921-
defer cancel()
922-
923-
fetchUniProof := func(ctx context.Context,
924-
loc proof.Locator) (proof.Blob, error) {
925-
926-
uniID := universe.Identifier{
927-
AssetID: *loc.AssetID,
928-
}
929-
if loc.GroupKey != nil {
930-
uniID.GroupKey = loc.GroupKey
931-
}
932-
933-
rpcUniID, err := tap.MarshalUniID(uniID)
934-
require.NoError(t.t, err)
935-
936-
op := &unirpc.Outpoint{
937-
HashStr: loc.OutPoint.Hash.String(),
938-
Index: int32(loc.OutPoint.Index),
939-
}
940-
scriptKeyBytes := loc.ScriptKey.SerializeCompressed()
941-
942-
uniProof, err := src.QueryProof(ctx, &unirpc.UniverseKey{
943-
Id: rpcUniID,
944-
LeafKey: &unirpc.AssetKey{
945-
Outpoint: &unirpc.AssetKey_Op{
946-
Op: op,
947-
},
948-
ScriptKey: &unirpc.AssetKey_ScriptKeyBytes{
949-
ScriptKeyBytes: scriptKeyBytes,
950-
},
951-
},
952-
})
953-
if err != nil {
954-
return nil, err
955-
}
956-
957-
return uniProof.AssetLeaf.Proof, nil
958-
}
959-
960-
var assetID asset.ID
961-
copy(assetID[:], genInfo.AssetId)
962-
963-
scriptPubKey, err := btcec.ParsePubKey(scriptKey)
964-
require.NoError(t.t, err)
965-
966-
op, err := wire.NewOutPointFromString(outpoint)
967-
require.NoError(t.t, err)
968-
969-
loc := proof.Locator{
970-
AssetID: &assetID,
971-
ScriptKey: *scriptPubKey,
972-
OutPoint: op,
973-
}
974-
975-
if group != nil {
976-
groupKey, err := btcec.ParsePubKey(group.TweakedGroupKey)
977-
require.NoError(t.t, err)
978-
979-
loc.GroupKey = groupKey
980-
}
879+
// transferProofUniRPC manually exports a proof from the given source using the
880+
// universe RPCs and then inserts it into the destination node's universe.
881+
func transferProofUniRPC(t *harnessTest, src, dst *tapdHarness,
882+
scriptKey []byte, genInfo *taprpc.GenesisInfo, group *taprpc.AssetGroup,
883+
outpoint string) *unirpc.AssetProofResponse {
981884

982-
var proofFile *proof.File
983-
err = wait.NoError(func() error {
984-
proofFile, err = proof.FetchProofProvenance(
985-
ctxt, nil, loc, fetchUniProof,
986-
)
987-
return err
988-
}, defaultWaitTimeout)
989-
require.NoError(t.t, err)
990-
991-
var buf bytes.Buffer
992-
err = proofFile.Encode(&buf)
993-
require.NoError(t.t, err)
994-
995-
t.Logf("Importing proof %x", buf.Bytes())
885+
proofFile := ExportProofFileFromUniverse(
886+
t.t, src, genInfo.AssetId, scriptKey, outpoint, group,
887+
)
996888

997-
importResp, err := dst.ImportProof(ctxb, &tapdevrpc.ImportProofRequest{
998-
ProofFile: buf.Bytes(),
999-
GenesisPoint: genInfo.GenesisPoint,
1000-
})
889+
lastProof, err := proofFile.LastProof()
1001890
require.NoError(t.t, err)
1002891

1003-
return importResp
892+
return InsertProofIntoUniverse(t.t, dst, lastProof)
1004893
}
1005894

1006-
// sendProofUniRPC manually exports a proof from the given source node and
1007-
// imports it using the universe related InsertProof RPC on the destination
1008-
// node.
1009-
func sendProofUniRPC(t *harnessTest, src, dst *tapdHarness, scriptKey []byte,
895+
// transferProofNormalExportUniInsert manually exports a proof from the given
896+
// source node and imports it using the universe related InsertProof RPC on the
897+
// destination node.
898+
func transferProofNormalExportUniInsert(t *harnessTest, src, dst *tapdHarness,
899+
scriptKey []byte,
1010900
genInfo *taprpc.GenesisInfo) *unirpc.AssetProofResponse {
1011901

1012-
ctxb := context.Background()
1013-
1014-
var proofResp *taprpc.ProofFile
1015-
waitErr := wait.NoError(func() error {
1016-
resp, err := src.ExportProof(ctxb, &taprpc.ExportProofRequest{
1017-
AssetId: genInfo.AssetId,
1018-
ScriptKey: scriptKey,
1019-
})
1020-
if err != nil {
1021-
return err
1022-
}
1023-
1024-
proofResp = resp
1025-
return nil
1026-
}, defaultWaitTimeout)
1027-
require.NoError(t.t, waitErr)
902+
proofResp := ExportProofFile(t.t, src, genInfo.AssetId, scriptKey, nil)
1028903

1029904
t.Logf("Importing proof %x using InsertProof", proofResp.RawProofFile)
1030905

@@ -1035,51 +910,7 @@ func sendProofUniRPC(t *harnessTest, src, dst *tapdHarness, scriptKey []byte,
1035910
lastProof, err := f.LastProof()
1036911
require.NoError(t.t, err)
1037912

1038-
var lastProofBytes bytes.Buffer
1039-
err = lastProof.Encode(&lastProofBytes)
1040-
require.NoError(t.t, err)
1041-
asset := lastProof.Asset
1042-
1043-
proofType := universe.ProofTypeTransfer
1044-
if asset.IsGenesisAsset() {
1045-
proofType = universe.ProofTypeIssuance
1046-
}
1047-
1048-
uniID := universe.Identifier{
1049-
AssetID: asset.ID(),
1050-
ProofType: proofType,
1051-
}
1052-
if asset.GroupKey != nil {
1053-
uniID.GroupKey = &asset.GroupKey.GroupPubKey
1054-
}
1055-
1056-
rpcUniID, err := tap.MarshalUniID(uniID)
1057-
require.NoError(t.t, err)
1058-
1059-
outpoint := &unirpc.Outpoint{
1060-
HashStr: lastProof.AnchorTx.TxHash().String(),
1061-
Index: int32(lastProof.InclusionProof.OutputIndex),
1062-
}
1063-
1064-
importResp, err := dst.InsertProof(ctxb, &unirpc.AssetProof{
1065-
Key: &unirpc.UniverseKey{
1066-
Id: rpcUniID,
1067-
LeafKey: &unirpc.AssetKey{
1068-
Outpoint: &unirpc.AssetKey_Op{
1069-
Op: outpoint,
1070-
},
1071-
ScriptKey: &unirpc.AssetKey_ScriptKeyBytes{
1072-
ScriptKeyBytes: scriptKey,
1073-
},
1074-
},
1075-
},
1076-
AssetLeaf: &unirpc.AssetLeaf{
1077-
Proof: lastProofBytes.Bytes(),
1078-
},
1079-
})
1080-
require.NoError(t.t, err)
1081-
1082-
return importResp
913+
return InsertProofIntoUniverse(t.t, dst, lastProof)
1083914
}
1084915

1085916
// sendOptions is a struct that holds a SendAssetRequest and an

itest/psbt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ func testPsbtTrustlessSwap(t *harnessTest) {
24242424
// We also need to push the proof for this transfer to the universe
24252425
// server.
24262426
bobScriptKeyBytes := bobScriptKey.PubKey.SerializeCompressed()
2427-
sendUniProof(
2427+
transferProofUniRPC(
24282428
t, t.universeServer.service, bob, bobScriptKeyBytes, genInfo,
24292429
mintedAsset.AssetGroup,
24302430
logResp.Transfer.Outputs[0].Anchor.Outpoint,

itest/send_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,9 @@ func testSendNoCourierUniverseImport(t *harnessTest) {
19551955
// Since we disabled proof couriers, we need to manually transfer the
19561956
// proof from the sender to the receiver now. We use the universe RPC
19571957
// InsertProof method to do this.
1958-
sendProofUniRPC(t, t.tapd, secondTapd, receiveAddr.ScriptKey, genInfo)
1958+
transferProofNormalExportUniInsert(
1959+
t, t.tapd, secondTapd, receiveAddr.ScriptKey, genInfo,
1960+
)
19591961

19601962
// And now, the transfer should be completed on the receiver side too.
19611963
AssertNonInteractiveRecvComplete(t.t, secondTapd, 1)

itest/universe_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ func testUniverseManualSync(t *harnessTest) {
323323
// universe.
324324
firstAsset := rpcIssuableAssets[0]
325325
firstAssetGen := firstAsset.AssetGenesis
326-
sendProofUniRPC(t, t.tapd, bob, firstAsset.ScriptKey, firstAssetGen)
326+
transferProofNormalExportUniInsert(
327+
t, t.tapd, bob, firstAsset.ScriptKey, firstAssetGen,
328+
)
327329

328330
// We should also be able to fetch an asset from Bob's Universe, and
329331
// query for that asset with the compressed script key.

0 commit comments

Comments
 (0)