Skip to content

Commit

Permalink
address+tapscript+vm: Update test setup + helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Sep 19, 2023
1 parent 75b25a2 commit 3a32d59
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
12 changes: 8 additions & 4 deletions address/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -64,15 +64,19 @@ 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
}

proofCourierAddr := RandProofCourierAddr(t)

return New(
genesis, groupKey, groupWitness, pubKeyCopy1, pubKeyCopy2,
genesis, groupKey, groupWitness, scriptKey, internalKey,
amount, tapscriptSibling, net, proofCourierAddr,
)
}
Expand Down
20 changes: 11 additions & 9 deletions address/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tapscript/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -310,6 +317,7 @@ func createGenesisProof(t *testing.T, state *spendData) {
Proof: *asset2CommitmentProof,
},
},
GenesisReveal: &state.asset2.Genesis,
}

state.asset2GenesisProof = asset2GenesisProof
Expand Down
7 changes: 5 additions & 2 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3a32d59

Please sign in to comment.