Skip to content

Commit 80af8ad

Browse files
committed
itest: fix naming and other small issues
1 parent fc804cb commit 80af8ad

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

itest/psbt_test.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,16 +2170,16 @@ func testPsbtTrustlessSwap(t *harnessTest) {
21702170

21712171
// Now we need to create the bitcoin PSBT where the previously created
21722172
// vPSBT will be anchored to.
2173-
btcpsbt, err := tapsend.PrepareAnchoringTemplate([]*tappsbt.VPacket{
2173+
btcPacket, err := tapsend.PrepareAnchoringTemplate([]*tappsbt.VPacket{
21742174
vPkt,
21752175
})
21762176
require.NoError(t.t, err)
21772177

21782178
// This bitcoin PSBT should have 1 input, which is the anchor of Alice's
21792179
// assets, and 2 outputs that correspond to Alice's bitcoin change
21802180
// (index 0) and the anchor that carries the assets (index 1).
2181-
require.Len(t.t, btcpsbt.Inputs, 1)
2182-
require.Len(t.t, btcpsbt.Outputs, 2)
2181+
require.Len(t.t, btcPacket.Inputs, 1)
2182+
require.Len(t.t, btcPacket.Outputs, 2)
21832183

21842184
// Let's set an actual address for Alice's output.
21852185
addrResp := t.lndHarness.Alice.RPC.NewAddress(&lnrpc.NewAddressRequest{
@@ -2197,23 +2197,22 @@ func testPsbtTrustlessSwap(t *harnessTest) {
21972197
// These are basically Alice's terms that she signs the assets over:
21982198
// Send me 69420 satoshis to this address that belongs to me, and you
21992199
// will get assets in return.
2200-
btcpsbt.UnsignedTx.TxOut[0].PkScript = alicePkScript
2201-
btcpsbt.UnsignedTx.TxOut[0].Value = 69420
2200+
btcPacket.UnsignedTx.TxOut[0].PkScript = alicePkScript
2201+
btcPacket.UnsignedTx.TxOut[0].Value = 69420
22022202
derivation, trDerivation := getAddressBip32Derivation(
22032203
t.t, addrResp.Address, t.lndHarness.Alice,
22042204
)
22052205

22062206
// Add the derivation info and internal key for alice's taproot address.
2207-
btcpsbt.Outputs[0].Bip32Derivation = []*psbt.Bip32Derivation{
2207+
btcPacket.Outputs[0].Bip32Derivation = []*psbt.Bip32Derivation{
22082208
derivation,
22092209
}
2210-
btcpsbt.Outputs[0].TaprootBip32Derivation = []*psbt.TaprootBip32Derivation{
2211-
trDerivation,
2212-
}
2213-
btcpsbt.Outputs[0].TaprootInternalKey = trDerivation.XOnlyPubKey
2210+
btcPacket.Outputs[0].TaprootBip32Derivation =
2211+
[]*psbt.TaprootBip32Derivation{trDerivation}
2212+
btcPacket.Outputs[0].TaprootInternalKey = trDerivation.XOnlyPubKey
22142213

22152214
var b bytes.Buffer
2216-
err = btcpsbt.Serialize(&b)
2215+
err = btcPacket.Serialize(&b)
22172216
require.NoError(t.t, err)
22182217

22192218
// Now we need to commit the vPSBT and PSBT, creating all the related
@@ -2233,7 +2232,7 @@ func testPsbtTrustlessSwap(t *harnessTest) {
22332232
require.NoError(t.t, err)
22342233

22352234
// Now we retrieve the bitcoin PSBT from the response.
2236-
btcpsbt, err = psbt.NewFromRawBytes(
2235+
btcPacket, err = psbt.NewFromRawBytes(
22372236
bytes.NewReader(resp.AnchorPsbt), false,
22382237
)
22392238
require.NoError(t.t, err)
@@ -2244,27 +2243,27 @@ func testPsbtTrustlessSwap(t *harnessTest) {
22442243
// following sighash flag we commit to exactly that input and output,
22452244
// but we also allow anyone to add their own inputs, which will allow
22462245
// Bob later to add his btc input to pay Alice.
2247-
btcpsbt.Inputs[0].SighashType = txscript.SigHashSingle |
2246+
btcPacket.Inputs[0].SighashType = txscript.SigHashSingle |
22482247
txscript.SigHashAnyOneCanPay
22492248

22502249
// We now strip the extra input that was only used to fund the bitcoin
22512250
// psbt. This is meant to be filled later by the person redeeming this
22522251
// swap offer.
2253-
btcpsbt.Inputs = append(
2254-
btcpsbt.Inputs[:1], btcpsbt.Inputs[2:]...,
2252+
btcPacket.Inputs = append(
2253+
btcPacket.Inputs[:1], btcPacket.Inputs[2:]...,
22552254
)
2256-
btcpsbt.UnsignedTx.TxIn = append(
2257-
btcpsbt.UnsignedTx.TxIn[:1], btcpsbt.UnsignedTx.TxIn[2:]...,
2255+
btcPacket.UnsignedTx.TxIn = append(
2256+
btcPacket.UnsignedTx.TxIn[:1], btcPacket.UnsignedTx.TxIn[2:]...,
22582257
)
22592258

22602259
// Let's get rid of the change output that we no longer need.
2261-
btcpsbt.Outputs = btcpsbt.Outputs[:2]
2262-
btcpsbt.UnsignedTx.TxOut = btcpsbt.UnsignedTx.TxOut[:2]
2260+
btcPacket.Outputs = btcPacket.Outputs[:2]
2261+
btcPacket.UnsignedTx.TxOut = btcPacket.UnsignedTx.TxOut[:2]
22632262

2264-
t.Logf("Alice BTC PSBT: %v", spew.Sdump(btcpsbt))
2263+
t.Logf("Alice BTC PSBT: %v", spew.Sdump(btcPacket))
22652264

22662265
b.Reset()
2267-
err = btcpsbt.Serialize(&b)
2266+
err = btcPacket.Serialize(&b)
22682267
require.NoError(t.t, err)
22692268

22702269
// Now alice signs the bitcoin psbt.
@@ -2277,14 +2276,14 @@ func testPsbtTrustlessSwap(t *harnessTest) {
22772276
require.Len(t.t, signPsbtResp.SignedInputs, 1)
22782277
require.Equal(t.t, uint32(0), signPsbtResp.SignedInputs[0])
22792278

2280-
btcpsbt, err = psbt.NewFromRawBytes(
2279+
btcPacket, err = psbt.NewFromRawBytes(
22812280
bytes.NewReader(signPsbtResp.SignedPsbt), false,
22822281
)
22832282
require.NoError(t.t, err)
22842283

22852284
// Let's do some sanity checks.
2286-
require.Len(t.t, btcpsbt.Inputs, 1)
2287-
require.Len(t.t, btcpsbt.Outputs, 2)
2285+
require.Len(t.t, btcPacket.Inputs, 1)
2286+
require.Len(t.t, btcPacket.Outputs, 2)
22882287

22892288
signedVpsbtBytes, err := tappsbt.Encode(vPkt)
22902289
require.NoError(t.t, err)
@@ -2327,11 +2326,12 @@ func testPsbtTrustlessSwap(t *harnessTest) {
23272326
// needs to be updated to point to Bob's keys as well. Otherwise, he
23282327
// wouldn't be able to take over custody of the anchor carrying the
23292328
// assets.
2330-
btcpsbt.Outputs[1].TaprootInternalKey = schnorr.SerializePubKey(
2329+
btcPacket.Outputs[1].TaprootInternalKey = schnorr.SerializePubKey(
23312330
bobAnchorInternalKey.PubKey,
23322331
)
2333-
btcpsbt.Outputs[1].Bip32Derivation = bobVOut.AnchorOutputBip32Derivation
2334-
btcpsbt.Outputs[1].TaprootBip32Derivation =
2332+
btcPacket.Outputs[1].Bip32Derivation =
2333+
bobVOut.AnchorOutputBip32Derivation
2334+
btcPacket.Outputs[1].TaprootBip32Derivation =
23352335
bobVOut.AnchorOutputTaprootBip32Derivation
23362336

23372337
// Before Bob tidies up the output commitments he keeps a backup of the
@@ -2358,7 +2358,7 @@ func testPsbtTrustlessSwap(t *harnessTest) {
23582358
// Now let's serialize the edited vPSBT and commit it to our bitcoin
23592359
// PSBT.
23602360
b.Reset()
2361-
err = btcpsbt.Serialize(&b)
2361+
err = btcPacket.Serialize(&b)
23622362
require.NoError(t.t, err)
23632363

23642364
// This call will also fund the PSBT, which means that the bitcoin that
@@ -2383,7 +2383,7 @@ func testPsbtTrustlessSwap(t *harnessTest) {
23832383

23842384
// Since Bob brings in a new input to the bitcoin transaction, he needs
23852385
// to sign it. We do not care about the sighash flag here, that can be
2386-
// the default, as as we will not edit the bitcoin transaction further.
2386+
// the default, as we will not edit the bitcoin transaction further.
23872387
signResp := t.lndHarness.Bob.RPC.SignPsbt(
23882388
&walletrpc.SignPsbtRequest{
23892389
FundedPsbt: resp.AnchorPsbt,
@@ -2405,6 +2405,7 @@ func testPsbtTrustlessSwap(t *harnessTest) {
24052405

24062406
// Bob should sign exactly 1 input.
24072407
require.Len(t.t, signResp.SignedInputs, 1)
2408+
24082409
// Bob should have signed the input at the expected index.
24092410
require.Equal(t.t, bobInputIdx, signResp.SignedInputs[0])
24102411
require.NoError(t.t, finalPsbt.SanityCheck())

0 commit comments

Comments
 (0)