Skip to content

Commit b5fab78

Browse files
committed
Merge branch 'itest/logdir' into feat/zero-value-utxo-selection
2 parents d4b078a + 5f3ef95 commit b5fab78

19 files changed

+1195
-1084
lines changed

itest/assertions.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,11 +1275,6 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
12751275
outpoints[o.Anchor.Outpoint] = struct{}{}
12761276
scripts[string(o.ScriptKey)] = struct{}{}
12771277
}
1278-
1279-
sendRespJSON, err := formatProtoJSON(transfer)
1280-
require.NoError(t, err)
1281-
t.Logf("Got response from sending assets: %v", sendRespJSON)
1282-
12831278
// Mine a block to force the send event to complete (confirm on-chain).
12841279
var newBlock *wire.MsgBlock
12851280
if confirm {
@@ -1318,23 +1313,11 @@ func AssertAssetOutboundTransferWithOutputs(t *testing.T,
13181313
inputAssetIDs, hex.EncodeToString,
13191314
)
13201315

1321-
t.Logf("Want input asset IDs: %v, got: %v",
1322-
expectedInputAssetIDs, actualInputAssetIDs)
13231316
return fn.All(
13241317
expectedInputAssetIDs, func(id string) bool {
13251318
return slices.Contains(actualInputAssetIDs, id)
13261319
})
13271320
}, defaultTimeout, wait.PollInterval)
1328-
require.NoError(t, err)
1329-
1330-
transferResp, err := sender.ListTransfers(
1331-
ctxb, &taprpc.ListTransfersRequest{},
1332-
)
1333-
require.NoError(t, err)
1334-
1335-
transferRespJSON, err := formatProtoJSON(transferResp)
1336-
require.NoError(t, err)
1337-
t.Logf("Got response from list transfers: %v", transferRespJSON)
13381321

13391322
return newBlock
13401323
}

itest/tapd_harness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
190190
}
191191

192192
tapCfg := tapcfg.DefaultConfig()
193-
tapCfg.LogDir = "."
193+
tapCfg.LogDir = *logDir
194194
tapCfg.MaxLogFiles = 99
195195
tapCfg.MaxLogFileSize = 999
196196

itest/test_harness.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
"path/filepath"
78
"testing"
89
"time"
910

@@ -45,8 +46,12 @@ var (
4546

4647
// logLevel is a command line flag for setting the log level of the
4748
// integration test output.
48-
logLevel = flag.String("loglevel", "info", "Set the log level of the "+
49+
logLevel = flag.String("loglevel", "debug", "Set the log level of the "+
4950
"integration test output")
51+
52+
// logDir is the directory for tapd and test logs.
53+
// We hardcode this to match the Makefile's -logdir=regtest flag.
54+
logDir = &[]string{"regtest"}[0]
5055
)
5156

5257
const (
@@ -201,12 +206,18 @@ func (h *harnessTest) shutdown(_ *testing.T) error {
201206
func (h *harnessTest) setupLogging() {
202207
h.logWriter = build.NewRotatingLogWriter()
203208

209+
// Initialize the log rotator with a file in the log directory.
204210
logConfig := build.DefaultLogConfig()
211+
// Disable console logging to avoid mixing with test output
212+
logConfig.Console.Disable = true
213+
logFile := filepath.Join(*logDir, "tapd.log")
214+
err := h.logWriter.InitLogRotator(logConfig.File, logFile)
215+
require.NoError(h.t, err)
216+
205217
h.logMgr = build.NewSubLoggerManager(
206218
build.NewDefaultLogHandlers(logConfig, h.logWriter)...,
207219
)
208220

209-
var err error
210221
h.interceptor, err = signal.Intercept()
211222
require.NoError(h.t, err)
212223

itest/zero_value_anchor_test.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,66 +50,74 @@ func testZeroValueAnchorSweep(t *harnessTest) {
5050
AssertNonInteractiveRecvComplete(t.t, secondTapd, 1)
5151

5252
// At this point, Alice should have a tombstone UTXO.
53-
// Check Alice's UTXOs to see if there are any without assets (tombstones).
54-
aliceUtxos, err := t.tapd.ListUtxos(ctxb, &taprpc.ListUtxosRequest{})
53+
// Check Alice's UTXOs to see if there are any with tombstone script keys.
54+
aliceUtxos, err := t.tapd.ListUtxos(ctxb, &taprpc.ListUtxosRequest{
55+
ScriptKeyType: &taprpc.ScriptKeyTypeQuery{
56+
Type: &taprpc.ScriptKeyTypeQuery_ExplicitType{
57+
ExplicitType: taprpc.ScriptKeyType_SCRIPT_KEY_TOMBSTONE,
58+
},
59+
},
60+
})
5561
require.NoError(t.t, err)
5662

63+
// Filter out swept UTXOs
5764
tombstoneCount := 0
5865
for _, utxo := range aliceUtxos.ManagedUtxos {
59-
if len(utxo.Assets) == 0 {
66+
if !utxo.Swept {
6067
tombstoneCount++
61-
t.t.Logf("Found tombstone UTXO: %s, value=%d",
62-
utxo.OutPoint, utxo.AmtSat)
6368
}
6469
}
6570

66-
t.t.Logf("Alice has %d tombstone UTXOs before sweep", tombstoneCount)
6771
require.Greater(t.t, tombstoneCount, 0, "Should have at least one tombstone UTXO")
6872

6973
// Now mint more assets for Alice so she can create another transaction
7074
// that should sweep the tombstones.
7175
rpcAssets2 := MintAssetsConfirmBatch(
7276
t.t, t.lndHarness.Miner().Client, t.tapd,
73-
[]*mintrpc.MintAssetRequest{simpleAssets[1]},
77+
[]*mintrpc.MintAssetRequest{simpleAssets[0]},
7478
)
7579

7680
genInfo2 := rpcAssets2[0].AssetGenesis
77-
assetAmount2 := simpleAssets[1].Asset.Amount
81+
assetAmount2 := simpleAssets[0].Asset.Amount
7882

79-
// Create another address for Bob.
83+
// Create another address for Bob (partial amount, not full).
84+
partialAmount := assetAmount2 / 2
8085
bobAddr2, err := secondTapd.NewAddr(ctxb, &taprpc.NewAddrRequest{
8186
AssetId: genInfo2.AssetId,
82-
Amt: assetAmount2,
87+
Amt: partialAmount,
8388
AssetVersion: rpcAssets2[0].Version,
8489
})
8590
require.NoError(t.t, err)
8691

87-
// Send the new assets. This should sweep Alice's tombstone UTXOs.
92+
// Send partial amount of the new assets. This should sweep Alice's tombstone UTXOs
93+
// but not create a new tombstone since it's not a full send.
8894
sendResp2, _ := sendAssetsToAddr(t, t.tapd, bobAddr2)
8995

90-
// Confirm the send.
9196
ConfirmAndAssertOutboundTransfer(
9297
t.t, t.lndHarness.Miner().Client, t.tapd, sendResp2,
9398
genInfo2.AssetId,
94-
[]uint64{0, assetAmount2}, 1, 2,
99+
[]uint64{assetAmount2 - partialAmount, partialAmount}, 1, 2,
95100
)
96101
AssertNonInteractiveRecvComplete(t.t, secondTapd, 2)
97102

98103
// Check Alice's UTXOs again. The tombstones should have been swept.
99-
finalAliceUtxos, err := t.tapd.ListUtxos(ctxb, &taprpc.ListUtxosRequest{})
104+
finalAliceUtxos, err := t.tapd.ListUtxos(ctxb, &taprpc.ListUtxosRequest{
105+
ScriptKeyType: &taprpc.ScriptKeyTypeQuery{
106+
Type: &taprpc.ScriptKeyTypeQuery_ExplicitType{
107+
ExplicitType: taprpc.ScriptKeyType_SCRIPT_KEY_TOMBSTONE,
108+
},
109+
},
110+
})
100111
require.NoError(t.t, err)
101112

113+
// Filter out swept UTXOs
102114
finalTombstoneCount := 0
103115
for _, utxo := range finalAliceUtxos.ManagedUtxos {
104-
if len(utxo.Assets) == 0 {
116+
if !utxo.Swept {
105117
finalTombstoneCount++
106-
t.t.Logf("Found tombstone UTXO after sweep: %s, value=%d",
107-
utxo.OutPoint, utxo.AmtSat)
108118
}
109119
}
110120

111-
t.t.Logf("Alice has %d tombstone UTXOs after sweep", finalTombstoneCount)
112-
113121
// We expect no tombstones after the sweep transaction.
114122
require.Equal(t.t, 0, finalTombstoneCount,
115123
"All tombstones should be swept")

rpcserver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ func (r *rpcServer) ListUtxos(ctx context.Context,
14031403
MerkleRoot: u.MerkleRoot,
14041404
LeaseOwner: u.LeaseOwner[:],
14051405
LeaseExpiryUnix: u.LeaseExpiry.Unix(),
1406+
Swept: u.Swept,
14061407
}
14071408
}
14081409

@@ -1419,6 +1420,14 @@ func (r *rpcServer) ListUtxos(ctx context.Context,
14191420
utxos[op] = utxo
14201421
}
14211422

1423+
// As a final pass, we'll prune out any UTXOs that don't have any
1424+
// assets, as these may be in the DB just for record keeping.
1425+
for _, utxo := range utxos {
1426+
if len(utxo.Assets) == 0 {
1427+
delete(utxos, utxo.OutPoint)
1428+
}
1429+
}
1430+
14221431
return &taprpc.ListUtxosResponse{
14231432
ManagedUtxos: utxos,
14241433
}, nil

0 commit comments

Comments
 (0)