From 3a32d59206139b4e88bef632a3119a1a004b4ce5 Mon Sep 17 00:00:00 2001 From: Jonathan Harvey-Buschel Date: Tue, 19 Sep 2023 12:33:13 +0100 Subject: [PATCH] address+tapscript+vm: Update test setup + helpers --- address/address_test.go | 12 ++++++++---- address/mock.go | 20 +++++++++++--------- rpcserver.go | 8 ++++---- tapscript/send_test.go | 12 ++++++++++-- vm/vm_test.go | 7 +++++-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/address/address_test.go b/address/address_test.go index 99379684f..1b7b88b05 100644 --- a/address/address_test.go +++ b/address/address_test.go @@ -53,8 +53,8 @@ func randAddress(t *testing.T, net *ChainParams, groupPubKey, sibling bool, ) } - pubKeyCopy1 := *pubKey - pubKeyCopy2 := *pubKey + scriptKey := *pubKey + internalKey := *pubKey genesis := asset.RandGenesis(t, assetType) @@ -64,7 +64,11 @@ func randAddress(t *testing.T, net *ChainParams, groupPubKey, sibling bool, ) if groupPubKey { - groupInfo := asset.RandGroupKey(t, genesis) + protoAsset := asset.AssetNoErr( + t, genesis, amount, 0, 0, + asset.NewScriptKey(&scriptKey), nil, + ) + groupInfo := asset.RandGroupKey(t, genesis, protoAsset) groupKey = &groupInfo.GroupPubKey groupWitness = groupInfo.Witness } @@ -72,7 +76,7 @@ func randAddress(t *testing.T, net *ChainParams, groupPubKey, sibling bool, proofCourierAddr := RandProofCourierAddr(t) return New( - genesis, groupKey, groupWitness, pubKeyCopy1, pubKeyCopy2, + genesis, groupKey, groupWitness, scriptKey, internalKey, amount, tapscriptSibling, net, proofCourierAddr, ) } diff --git a/address/mock.go b/address/mock.go index 60504c086..53a553b7a 100644 --- a/address/mock.go +++ b/address/mock.go @@ -33,6 +33,13 @@ func RandAddr(t testing.TB, params *ChainParams, *asset.Genesis, *asset.GroupKey) { scriptKeyPriv := test.RandPrivKey(t) + scriptKey := asset.NewScriptKeyBip86(keychain.KeyDescriptor{ + PubKey: scriptKeyPriv.PubKey(), + KeyLocator: keychain.KeyLocator{ + Family: keychain.KeyFamily(test.RandIntn(255) + 1), + Index: uint32(test.RandIntn(255)), + }, + }) internalKey := test.RandPrivKey(t) @@ -49,7 +56,10 @@ func RandAddr(t testing.TB, params *ChainParams, tapscriptSibling *commitment.TapscriptPreimage ) if test.RandInt[uint32]()%2 == 0 { - groupInfo = asset.RandGroupKey(t, genesis) + protoAsset := asset.AssetNoErr( + t, genesis, amount, 0, 0, scriptKey, nil, + ) + groupInfo = asset.RandGroupKey(t, genesis, protoAsset) groupPubKey = &groupInfo.GroupPubKey groupWitness = groupInfo.Witness @@ -58,14 +68,6 @@ func RandAddr(t testing.TB, params *ChainParams, ) } - scriptKey := asset.NewScriptKeyBip86(keychain.KeyDescriptor{ - PubKey: scriptKeyPriv.PubKey(), - KeyLocator: keychain.KeyLocator{ - Family: keychain.KeyFamily(test.RandIntn(255) + 1), - Index: uint32(test.RandIntn(255)), - }, - }) - tapAddr, err := New( genesis, groupPubKey, groupWitness, *scriptKey.PubKey, *internalKey.PubKey(), amount, tapscriptSibling, params, diff --git a/rpcserver.go b/rpcserver.go index f4d2d3b4c..da2690956 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1287,8 +1287,8 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof, var ( rpcMeta *taprpc.AssetMeta - rpcGenesis = decodedProof.GenesisReveal - rpcGroupKey = decodedProof.GroupKeyReveal + rpcGenesis = p.GenesisReveal + rpcGroupKey = p.GroupKeyReveal anchorOutpoint = wire.OutPoint{ Hash: p.AnchorTx.TxHash(), Index: p.InclusionProof.OutputIndex, @@ -1387,7 +1387,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof, } } - decodedAssetID := decodedProof.Asset.ID() + decodedAssetID := p.Asset.ID() genesisReveal := &taprpc.GenesisReveal{ GenesisBaseReveal: &taprpc.GenesisInfo{ GenesisPoint: rpcGenesis.FirstPrevOut.String(), @@ -1396,7 +1396,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof, AssetId: decodedAssetID[:], OutputIndex: rpcGenesis.OutputIndex, }, - AssetType: taprpc.AssetType(decodedProof.Asset.Type), + AssetType: taprpc.AssetType(p.Asset.Type), } var GroupKeyReveal taprpc.GroupKeyReveal diff --git a/tapscript/send_test.go b/tapscript/send_test.go index 1e7f02a70..68c7c0936 100644 --- a/tapscript/send_test.go +++ b/tapscript/send_test.go @@ -119,7 +119,12 @@ func initSpendScenario(t *testing.T) spendData { state.receiverPrivKey = *receiverPrivKey state.receiverPubKey = *receiverPubKey - groupKey := asset.RandGroupKey(t, state.genesis1collect) + genesis1collectProtoAsset := asset.AssetNoErr( + t, state.genesis1collect, 1, 0, 0, spenderScriptKey, nil, + ) + groupKey := asset.RandGroupKey( + t, state.genesis1collect, genesis1collectProtoAsset, + ) state.groupKey = *groupKey // Addresses to cover both asset types and all three asset values. @@ -270,7 +275,9 @@ func createGenesisProof(t *testing.T, state *spendData) { require.NoError(t, err) asset2GenesisTx := &wire.MsgTx{ Version: 2, - TxIn: []*wire.TxIn{{}}, + TxIn: []*wire.TxIn{{ + PreviousOutPoint: state.genesis1.FirstPrevOut, + }}, TxOut: []*wire.TxOut{{ PkScript: senderScript, Value: 330, @@ -310,6 +317,7 @@ func createGenesisProof(t *testing.T, state *spendData) { Proof: *asset2CommitmentProof, }, }, + GenesisReveal: &state.asset2.Genesis, } state.asset2GenesisProof = asset2GenesisProof diff --git a/vm/vm_test.go b/vm/vm_test.go index fe59d9e84..cdb43f2d1 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -36,10 +36,13 @@ func randAsset(t *testing.T, assetType asset.Type, t.Helper() genesis := asset.RandGenesis(t, assetType) - groupKey := asset.RandGroupKey(t, genesis) scriptKey := asset.NewScriptKey(scriptKeyPub) + protoAsset := asset.RandAssetWithValues(t, genesis, nil, scriptKey) + groupKey := asset.RandGroupKey(t, genesis, protoAsset) - return asset.RandAssetWithValues(t, genesis, groupKey, scriptKey) + fullAsset := protoAsset.Copy() + fullAsset.GroupKey = groupKey + return fullAsset } func genTaprootKeySpend(t *testing.T, privKey btcec.PrivateKey,