Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itest: resume pending package send #365

Merged
merged 3 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func confirmAndAssetOutboundTransferWithOutputs(t *harnessTest,
require.NoError(t.t, err)
t.Logf("Got response from sending assets: %v", sendRespJSON)

// Mine a block to force the send we created above to confirm.
// Mine a block to force the send event to complete (confirm on-chain).
_ = mineBlocks(t, t.lndHarness, 1, 1)

// Confirm that we can externally view the transfer.
Expand Down
17 changes: 10 additions & 7 deletions itest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,27 @@ func TestTaprootAssetsDaemon(t *testing.T) {
testCase.name)

success := t.Run(testCase.name, func(t1 *testing.T) {
// Create a subtest harness for each test case.
subTestLnd := lndHarness.Subtest(t1)

// The universe server and tapd client are both freshly
// created and later discarded for each test run to
// assure no state is taken over between runs.
tapdHarness, universeServer, proofCourier :=
setupHarnesses(
t1, ht, lndHarness,
t1, ht, subTestLnd,
testCase.proofCourierType,
)
lndHarness.EnsureConnected(
lndHarness.Alice, lndHarness.Bob,
subTestLnd.EnsureConnected(
subTestLnd.Alice, subTestLnd.Bob,
)

lndHarness.Alice.AddToLogf(logLine)
lndHarness.Bob.AddToLogf(logLine)
subTestLnd.Alice.AddToLogf(logLine)
subTestLnd.Bob.AddToLogf(logLine)

ht := ht.newHarnessTest(
t1, lndHarness, universeServer, tapdHarness,
proofCourier,
t1, subTestLnd, universeServer,
tapdHarness, proofCourier,
)

// Now we have everything to run the test case.
Expand Down
92 changes: 92 additions & 0 deletions itest/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,98 @@ func testBasicSend(t *harnessTest) {
wg.Wait()
}

// testResumePendingPackageSend tests that we can properly resume a pending
// package send after a restart.
func testResumePendingPackageSend(t *harnessTest) {
ctxb := context.Background()

sendTapd := t.tapd

// Setup a receiver node.
recvLnd := t.lndHarness.Bob
recvTapd := setupTapdHarness(
t.t, t, recvLnd, t.universeServer,
func(params *tapdHarnessParams) {
// We expect the receiver node to exit with an error
// since it will fail to receive the asset at the first
// attempt. We will confirm that the receiver node does
// eventually receive the asset correctly via an RPC
// call.
params.expectErrExit = true
},
)

// Mint (and mine) an asset for sending.
rpcAssets := mintAssetsConfirmBatch(
t, sendTapd, []*mintrpc.MintAssetRequest{simpleAssets[0]},
)

genInfo := rpcAssets[0].AssetGenesis

// Synchronize the Universe state of the sending node, with the
// receiving node.
t.syncUniverseState(sendTapd, recvTapd, len(rpcAssets))

// The receiver node generates a new address.
recvAddr, err := recvTapd.NewAddr(
ctxb, &taprpc.NewAddrRequest{
AssetId: genInfo.AssetId,
Amt: 10,
},
)
require.NoError(t.t, err)
assertAddrCreated(t.t, recvTapd, rpcAssets[0], recvAddr)

// We will now start two asset send events in sequence. We will stop and
// restart the sending node during each send. During one sending event
// we will mine whilst the sending node is stopped. During the other
// sending event we will only mine once the sending node is restarted.
for i := range []int{0, 1} {
ffranr marked this conversation as resolved.
Show resolved Hide resolved
mineWhileNodeDown := i == 0

// Start the asset send procedure.
t.t.Logf("Commencing asset send procedure")
sendAssetsToAddr(t, sendTapd, recvAddr)

// Stop the sending node before mining the asset transfer's
// anchoring transaction. This will ensure that the send
// procedure does not complete. The sending node will be stalled
// waiting for the broadcast transaction to confirm.
t.t.Logf("Stopping sending tapd node")
err = sendTapd.stop(false)
require.NoError(t.t, err)

if mineWhileNodeDown {
// Mine the anchoring transaction to ensure that the
// asset transfer is broadcast.
t.lndHarness.MineBlocks(6)
}

// Re-commence the asset send procedure by restarting the
// sending node. The asset package should be picked up as a
// pending package.
t.t.Logf("Re-starting sending tapd node so as to complete " +
"transfer")
err = sendTapd.start(false)
require.NoError(t.t, err)

if !mineWhileNodeDown {
// Complete the transfer by mining the anchoring
// transaction and sending the proof to the receiver
// node.
t.lndHarness.MineBlocks(6)
}

_ = sendProof(
t, sendTapd, recvTapd, recvAddr.ScriptKey, genInfo,
)

// Confirm with the receiver node that the asset was fully
// received.
assertNonInteractiveRecvComplete(t, recvTapd, i+1)
}
}

// testBasicSendPassiveAsset tests that we can properly send assets which were
// passive assets during a previous send.
func testBasicSendPassiveAsset(t *harnessTest) {
Expand Down
5 changes: 5 additions & 0 deletions itest/test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var testCases = []*testCase{
test: testBasicSend,
proofCourierType: proof.ApertureCourier,
},
{
name: "resume pending package send",
test: testResumePendingPackageSend,
proofCourierType: proof.ApertureCourier,
},
{
name: "reattempt failed asset send",
test: testReattemptFailedAssetSend,
Expand Down