Skip to content

Commit e78d1cb

Browse files
positiveblueguggero
authored andcommitted
itest: add itests for the Taproot Assets new subserver
1 parent 4be6ffb commit e78d1cb

File tree

2 files changed

+77
-14
lines changed

2 files changed

+77
-14
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
pool "github.com/lightninglabs/pool/perms"
3131
"github.com/lightninglabs/pool/poolrpc"
3232
tap "github.com/lightninglabs/taproot-assets/perms"
33+
"github.com/lightninglabs/taproot-assets/taprpc"
3334
"github.com/lightningnetwork/lnd/keychain"
3435
"github.com/lightningnetwork/lnd/lnrpc"
3536
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@@ -146,6 +147,15 @@ var (
146147
poolMacaroonFn = func(cfg *LitNodeConfig) string {
147148
return cfg.PoolMacPath
148149
}
150+
tapRequestFn = func(ctx context.Context,
151+
c grpc.ClientConnInterface) (proto.Message, error) {
152+
153+
tapConn := taprpc.NewTaprootAssetsClient(c)
154+
return tapConn.ListAssets(ctx, &taprpc.ListAssetRequest{})
155+
}
156+
tapMacaroonFn = func(cfg *LitNodeConfig) string {
157+
return cfg.TapMacPath
158+
}
149159
litSessionRequestFn = func(ctx context.Context,
150160
c grpc.ClientConnInterface) (proto.Message, error) {
151161

@@ -234,6 +244,14 @@ var (
234244
allowedThroughLNC: true,
235245
grpcWebURI: "/poolrpc.Trader/GetInfo",
236246
restWebURI: "/v1/pool/info",
247+
}, {
248+
name: "taprpc",
249+
macaroonFn: tapMacaroonFn,
250+
requestFn: tapRequestFn,
251+
successPattern: "\"assets\":[]",
252+
allowedThroughLNC: true,
253+
grpcWebURI: "/taprpc.TaprootAssets/ListAssets",
254+
restWebURI: "/v1/taproot-assets/assets",
237255
}, {
238256
name: "litrpc-sessions",
239257
macaroonFn: litMacaroonFn,
@@ -644,7 +662,13 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
644662
ctxm = macaroonContext(ctxt, dummyMacBytes)
645663
_, err = makeRequest(ctxm, rawConn)
646664
require.Error(t, err)
647-
require.Contains(t, err.Error(), "cannot get macaroon: root key with")
665+
666+
errStr := err.Error()
667+
err1 := strings.Contains(errStr, "cannot get macaroon: root")
668+
err2 := strings.Contains(errStr, "cannot get macaroon: sql: no")
669+
require.Truef(
670+
t, err1 || err2, "no macaroon, got unexpected error: %v", err,
671+
)
648672

649673
// Then finally we try with the correct macaroon which should now
650674
// succeed.
@@ -692,7 +716,9 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
692716
errStr := err.Error()
693717
err1 := strings.Contains(errStr, "invalid auth: invalid basic auth")
694718
err2 := strings.Contains(errStr, "cannot get macaroon: root key with")
695-
require.True(t, err1 || err2, "wrong UI password and dummy mac")
719+
err3 := strings.Contains(errStr, "cannot get macaroon: sql: no rows")
720+
require.Truef(t, err1 || err2 || err3, "wrong UI password and dummy "+
721+
"mac, got unexpected error: %v", err)
696722

697723
// Using the correct UI password should work for all requests.
698724
ctxm = uiPasswordContext(ctxt, uiPassword, false)
@@ -712,9 +738,11 @@ func runUIPasswordCheck(t *testing.T, hostPort, tlsCertPath, uiPassword string,
712738
_, err = makeRequest(ctxm, rawConn)
713739

714740
require.Error(t, err)
715-
require.Contains(
716-
t, err.Error(), "cannot get macaroon: root",
717-
)
741+
errStr := err.Error()
742+
err1 := strings.Contains(errStr, "cannot get macaroon: root")
743+
err2 := strings.Contains(errStr, "cannot get macaroon: sql: no")
744+
require.Truef(t, err1 || err2, "no macaroon, got unexpected "+
745+
"error: %v", err)
718746
return
719747
}
720748

@@ -1097,6 +1125,7 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
10971125

10981126
permsMgr.RegisterSubServer(subservers.LOOP, loop.RequiredPermissions)
10991127
permsMgr.RegisterSubServer(subservers.POOL, pool.RequiredPermissions)
1128+
permsMgr.RegisterSubServer(subservers.TAP, tap.RequiredPermissions)
11001129
permsMgr.RegisterSubServer(
11011130
subservers.FARADAY, faraday.RequiredPermissions,
11021131
)

itest/litd_node.go

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/lightninglabs/lightning-terminal/litrpc"
2828
"github.com/lightninglabs/loop/looprpc"
2929
"github.com/lightninglabs/pool/poolrpc"
30+
"github.com/lightninglabs/taproot-assets/taprpc"
3031
"github.com/lightningnetwork/lnd/lnrpc"
3132
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
3233
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@@ -71,6 +72,7 @@ type LitNodeConfig struct {
7172
FaradayMacPath string
7273
LoopMacPath string
7374
PoolMacPath string
75+
TapMacPath string
7476
LitTLSCertPath string
7577
LitMacPath string
7678

@@ -79,6 +81,7 @@ type LitNodeConfig struct {
7981
FaradayDir string
8082
LoopDir string
8183
PoolDir string
84+
TapdDir string
8285

8386
LitPort int
8487
LitRESTPort int
@@ -182,15 +185,16 @@ func (cfg *LitNodeConfig) GenArgs(opts ...LitArgOption) []string {
182185
func (cfg *LitNodeConfig) defaultLitdArgs() *litArgs {
183186
var (
184187
args = map[string]string{
185-
"httpslisten": cfg.LitAddr(),
186-
"insecure-httplisten": cfg.LitRESTAddr(),
187-
"lit-dir": cfg.LitDir,
188-
"faraday.faradaydir": cfg.FaradayDir,
189-
"loop.loopdir": cfg.LoopDir,
190-
"pool.basedir": cfg.PoolDir,
191-
"uipassword": cfg.UIPassword,
192-
"enablerest": "",
193-
"restcors": "*",
188+
"httpslisten": cfg.LitAddr(),
189+
"insecure-httplisten": cfg.LitRESTAddr(),
190+
"lit-dir": cfg.LitDir,
191+
"faraday.faradaydir": cfg.FaradayDir,
192+
"loop.loopdir": cfg.LoopDir,
193+
"pool.basedir": cfg.PoolDir,
194+
"taproot-assets.tapddir": cfg.TapdDir,
195+
"uipassword": cfg.UIPassword,
196+
"enablerest": "",
197+
"restcors": "*",
194198
}
195199
)
196200
for _, arg := range cfg.LitArgs {
@@ -356,6 +360,7 @@ func NewNode(t *testing.T, cfg *LitNodeConfig,
356360
cfg.FaradayDir = filepath.Join(cfg.LitDir, "faraday")
357361
cfg.LoopDir = filepath.Join(cfg.LitDir, "loop")
358362
cfg.PoolDir = filepath.Join(cfg.LitDir, "pool")
363+
cfg.TapdDir = filepath.Join(cfg.LitDir, "tapd")
359364
cfg.TLSCertPath = filepath.Join(cfg.BaseDir, "tls.cert")
360365
cfg.TLSKeyPath = filepath.Join(cfg.BaseDir, "tls.key")
361366

@@ -374,6 +379,9 @@ func NewNode(t *testing.T, cfg *LitNodeConfig,
374379
cfg.PoolMacPath = filepath.Join(
375380
cfg.PoolDir, cfg.NetParams.Name, "pool.macaroon",
376381
)
382+
cfg.TapMacPath = filepath.Join(
383+
cfg.TapdDir, "data", cfg.NetParams.Name, "admin.macaroon",
384+
)
377385
cfg.LitMacPath = filepath.Join(
378386
cfg.LitDir, cfg.NetParams.Name, "lit.macaroon",
379387
)
@@ -730,6 +738,18 @@ func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
730738
return err
731739
}
732740

741+
tapClient, err := hn.tapClient()
742+
if err != nil {
743+
return err
744+
}
745+
746+
_, err = tapClient.ListAssets(
747+
ctxt, &taprpc.ListAssetRequest{},
748+
)
749+
if err != nil {
750+
return err
751+
}
752+
733753
return nil
734754
}, timeout)
735755
}
@@ -778,6 +798,20 @@ func (hn *HarnessNode) poolClient() (poolrpc.TraderClient, error) {
778798
return poolrpc.NewTraderClient(conn), nil
779799
}
780800

801+
func (hn *HarnessNode) tapClient() (taprpc.TaprootAssetsClient, error) {
802+
mac, err := hn.ReadMacaroon(hn.Cfg.TapMacPath, lntest.DefaultTimeout)
803+
if err != nil {
804+
return nil, err
805+
}
806+
807+
conn, err := hn.ConnectRPCWithMacaroon(mac)
808+
if err != nil {
809+
return nil, err
810+
}
811+
812+
return taprpc.NewTaprootAssetsClient(conn), nil
813+
}
814+
781815
// waitForState waits until the current node state fulfills the given
782816
// predicate.
783817
func (hn *HarnessNode) waitForState(conn grpc.ClientConnInterface,

0 commit comments

Comments
 (0)