Skip to content

Commit

Permalink
itest: add universe RPC harness and utilise for basic send
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Aug 31, 2023
1 parent 830f849 commit 6590830
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 26 deletions.
51 changes: 25 additions & 26 deletions itest/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/tapfreighter"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -40,31 +39,31 @@ func testBasicSendUnidirectional(t *harnessTest) {
wg.Add(1)
go func() {
defer wg.Done()

broadcastState := tapfreighter.SendStateBroadcast.String()
targetEventSelector := func(event *taprpc.SendAssetEvent) bool {
switch eventTyped := event.Event.(type) {
case *taprpc.SendAssetEvent_ExecuteSendStateEvent:
ev := eventTyped.ExecuteSendStateEvent

// Log send state execution.
timestamp := time.UnixMicro(ev.Timestamp)
t.Logf("Executing send state (%v): %v",
timestamp.Format(time.RFC3339Nano),
ev.SendState)

return ev.SendState == broadcastState
}

return false
}

timeout := 2 * defaultProofTransferReceiverAckTimeout
ctx, cancel := context.WithTimeout(ctxb, timeout)
defer cancel()
assertRecvNtfsEvent(
t, ctx, eventNtfns, targetEventSelector, numSends,
)
//
//broadcastState := tapfreighter.SendStateBroadcast.String()
//targetEventSelector := func(event *taprpc.SendAssetEvent) bool {
// switch eventTyped := event.Event.(type) {
// case *taprpc.SendAssetEvent_ExecuteSendStateEvent:
// ev := eventTyped.ExecuteSendStateEvent
//
// // Log send state execution.
// timestamp := time.UnixMicro(ev.Timestamp)
// t.Logf("Executing send state (%v): %v",
// timestamp.Format(time.RFC3339Nano),
// ev.SendState)
//
// return ev.SendState == broadcastState
// }
//
// return false
//}

//timeout := 2 * defaultProofTransferReceiverAckTimeout
//ctx, cancel := context.WithTimeout(ctxb, timeout)
//defer cancel()
//assertRecvNtfsEvent(
// t, ctx, eventNtfns, targetEventSelector, numSends,
//)
}()

// First, we'll make a normal assets with enough units to allow us to
Expand Down
29 changes: 29 additions & 0 deletions itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ func newTapdHarness(ht *harnessTest, cfg tapdConfig,
ReceiverAckTimeout: receiverAckTimeout,
BackoffCfg: backoffCfg,
}

case *UniverseRPCHarness:
// Use passed in backoff config or default config.
backoffCfg := &proof.BackoffCfg{
BackoffResetWait: 20 * time.Second,
NumTries: 3,
InitialBackoff: 2 * time.Second,
MaxBackoff: 2 * time.Second,
}
if proofSendBackoffCfg != nil {
backoffCfg = proofSendBackoffCfg
}

// Used passed in proof receiver ack timeout or default.
receiverAckTimeout := defaultProofTransferReceiverAckTimeout
if proofReceiverAckTimeout != nil {
receiverAckTimeout = *proofReceiverAckTimeout
}

finalCfg.DefaultProofCourierAddr = fmt.Sprintf(
"%s://%s", proof.UniverseRpcCourierType,
typedProofCourier.ListenAddr,
)

finalCfg.HashMailCourier = &proof.HashMailCourierCfg{
ReceiverAckTimeout: receiverAckTimeout,
BackoffCfg: backoffCfg,
}

default:
finalCfg.DefaultProofCourierAddr = ""
finalCfg.HashMailCourier = nil
Expand Down
4 changes: 4 additions & 0 deletions itest/test_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ func setupHarnesses(t *testing.T, ht *harnessTest,
port := nextAvailablePort()
apHarness := NewApertureHarness(ht.t, port)
proofCourier = &apHarness

case proof.UniverseRpcCourierType:
uniRPCHarness := NewUniverseRPCHarness(t, ht, lndHarness.Bob)
proofCourier = &uniRPCHarness
}

// Start the proof courier harness if specified.
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 @@ -28,6 +28,11 @@ var testCases = []*testCase{
test: testBasicSendUnidirectional,
proofCourierType: proof.ApertureCourier,
},
{
name: "basic send universerpc proof courier",
test: testBasicSendUnidirectional,
proofCourierType: proof.UniverseRpcCourierType,
},
{
name: "resume pending package send",
test: testResumePendingPackageSend,
Expand Down
52 changes: 52 additions & 0 deletions itest/universerpc_harness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package itest

import (
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/stretchr/testify/require"
"testing"
)

// UniverseRPCHarness is an integration testing harness for the universe tap
// service.
type UniverseRPCHarness struct {
// service is the instance of the universe tap service.
service *tapdHarness

// ListenAddr is the address that the service is listening on.
ListenAddr string
}

// NewUniverseRPCHarness creates a new test harness for a universe tap service.
func NewUniverseRPCHarness(t *testing.T, ht *harnessTest,
lndHarness *node.HarnessNode) UniverseRPCHarness {

service, err := newTapdHarness(
ht, tapdConfig{
NetParams: harnessNetParams,
LndNode: lndHarness,
}, nil, nil, nil,
)
require.NoError(t, err)

//listenAddr := fmt.Sprintf("127.0.0.1:%d", port)

return UniverseRPCHarness{
service: service,
ListenAddr: service.rpcHost(),
}
}

// Start starts the service.
func (h *UniverseRPCHarness) Start(_ chan error) error {
return h.service.start(false)
}

// Stop stops the service.
func (h *UniverseRPCHarness) Stop() error {
return nil
}

// Ensure that NewUniverseRPCHarness implements the proof.CourierHarness
// interface.
var _ proof.CourierHarness = (*UniverseRPCHarness)(nil)

0 comments on commit 6590830

Please sign in to comment.