From 60eb2792d22e28f46c68b1fee2ac4b65b0dea4d5 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:42:48 +0200 Subject: [PATCH] fix test --- main_test.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main_test.go b/main_test.go index a635f50..64e1483 100644 --- a/main_test.go +++ b/main_test.go @@ -2,12 +2,14 @@ package main import ( "context" + "encoding/hex" + "testing" + "github.com/callebtc/electronwall/config" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" - "testing" ) func TestApp(t *testing.T) { @@ -451,16 +453,16 @@ func TestChannelAllowlist_CorrectKey(t *testing.T) { defer cancel() app := NewApp(ctx, client) - + pubkey_str := "03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6" config.Configuration.ChannelMode = "allowlist" - config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"} + config.Configuration.ChannelAllowlist = []string{pubkey_str} app.DispatchChannelAcceptor(ctx) // correct key: should be allowed - + pubkey, _ := hex.DecodeString(pubkey_str) client.channelAcceptorRequests <- &lnrpc.ChannelAcceptRequest{ - NodePubkey: []byte("03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"), + NodePubkey: pubkey, FundingAmt: 1337000, PendingChanId: []byte("759495353533530113"), } @@ -476,8 +478,9 @@ func TestChannelAllowlist_WrongKey(t *testing.T) { app := NewApp(ctx, client) + pubkey_str := "03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6" config.Configuration.ChannelMode = "allowlist" - config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"} + config.Configuration.ChannelAllowlist = []string{pubkey_str} app.DispatchChannelAcceptor(ctx) // wrong key: should be denied @@ -500,12 +503,14 @@ func TestChannelAllowlist_Wildcard(t *testing.T) { app.DispatchChannelAcceptor(ctx) + pubkey_str := "03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6" // wildcard: should be allowed config.Configuration.ChannelMode = "allowlist" config.Configuration.ChannelAllowlist = []string{"*"} + pubkey, _ := hex.DecodeString(pubkey_str) client.channelAcceptorRequests <- &lnrpc.ChannelAcceptRequest{ - NodePubkey: []byte("03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"), + NodePubkey: pubkey, FundingAmt: 1337000, PendingChanId: []byte("759495353533530113"), } @@ -520,16 +525,16 @@ func TestChannelDenylist_Match(t *testing.T) { defer cancel() app := NewApp(ctx, client) - + pubkey_str := "03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6" config.Configuration.ChannelMode = "denylist" - config.Configuration.ChannelDenylist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"} + config.Configuration.ChannelDenylist = []string{pubkey_str} app.DispatchChannelAcceptor(ctx) // should be denied - + pubkey, _ := hex.DecodeString(pubkey_str) client.channelAcceptorRequests <- &lnrpc.ChannelAcceptRequest{ - NodePubkey: []byte("03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"), + NodePubkey: []byte(pubkey), FundingAmt: 1337000, PendingChanId: []byte("759495353533530113"), } @@ -544,15 +549,16 @@ func TestChannelAllowlist_Match(t *testing.T) { defer cancel() app := NewApp(ctx, client) - + pubkey_str := "03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6" config.Configuration.ChannelMode = "allowlist" - config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"} + config.Configuration.ChannelAllowlist = []string{pubkey_str} app.DispatchChannelAcceptor(ctx) // should be allowed + pubkey, _ := hex.DecodeString(pubkey_str) client.channelAcceptorRequests <- &lnrpc.ChannelAcceptRequest{ - NodePubkey: []byte("03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"), + NodePubkey: []byte(pubkey), FundingAmt: 1337000, PendingChanId: []byte("759495353533530113"), }