mirror of
https://github.com/callebtc/electronwall.git
synced 2025-12-17 23:24:22 +01:00
works
This commit is contained in:
92
main_test.go
92
main_test.go
@@ -2,12 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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) {
|
||||
@@ -33,8 +33,8 @@ func TestHTLCDenylist_BothMatch(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ForwardMode = "denylist"
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
config.Configuration.ForwardMode = "denylist"
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
@@ -67,8 +67,8 @@ func TestHTLCDenylist_BothNoMatch(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ForwardMode = "denylist"
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
config.Configuration.ForwardMode = "denylist"
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
@@ -101,12 +101,12 @@ func TestHTLCDenylist_WildCardOutBothMatch(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ForwardMode = "denylist"
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
config.Configuration.ForwardMode = "denylist"
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->*"}
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->*"}
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 770495967390531585,
|
||||
@@ -137,14 +137,14 @@ func TestHTLCDenylist_WildCardOutNoMatch(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ForwardMode = "denylist"
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
config.Configuration.ForwardMode = "denylist"
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->690757x1005x1"}
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
// wildcard out, first key doesn't match: should be allowed
|
||||
|
||||
Configuration.ForwardDenylist = []string{"700762x1327x1->*"}
|
||||
config.Configuration.ForwardDenylist = []string{"700762x1327x1->*"}
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 759495353533530113,
|
||||
@@ -176,11 +176,11 @@ func TestHTLCAllowlist_BothMatch(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
|
||||
// both keys correct: should be allowed
|
||||
Configuration.ForwardAllowlist = []string{"700762x1327x1->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"700762x1327x1->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 770495967390531585,
|
||||
@@ -212,10 +212,10 @@ func TestHTLCAllowlist_BothNonMatch(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// both keys wrong: should be denied
|
||||
Configuration.ForwardAllowlist = []string{"700762x1327x1->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"700762x1327x1->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
@@ -246,10 +246,10 @@ func TestHTLCAllowlist_Wildcard(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard: should be allowed
|
||||
Configuration.ForwardAllowlist = []string{"*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
HtlcId: 1337000,
|
||||
@@ -279,11 +279,11 @@ func TestHTLCAllowlist_WildcardIn(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard in: should be allowed
|
||||
|
||||
Configuration.ForwardAllowlist = []string{"*->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"*->690757x1005x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
@@ -314,10 +314,10 @@ func TestHTLCAllowlist_WildcardOut(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard out: should be allowed
|
||||
Configuration.ForwardAllowlist = []string{"700762x1327x1->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"700762x1327x1->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 770495967390531585,
|
||||
@@ -348,10 +348,10 @@ func TestHTLCAllowlist_WildcardOutWrongKeyIn(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard out but wrong in key: should be denied
|
||||
Configuration.ForwardAllowlist = []string{"700762x1327x1->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"700762x1327x1->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
@@ -382,10 +382,10 @@ func TestHTLCAllowlist_WildcardIn_WrongKeyOut(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard in but wrong out key: should be denied
|
||||
Configuration.ForwardAllowlist = []string{"*->700762x1327x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"*->700762x1327x1"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
@@ -416,10 +416,10 @@ func TestHTLCAllowlist_WildcardBoth(t *testing.T) {
|
||||
|
||||
app.DispatchHTLCAcceptor(ctx)
|
||||
|
||||
Configuration.ForwardMode = "allowlist"
|
||||
config.Configuration.ForwardMode = "allowlist"
|
||||
// wildcard both: should be allowed
|
||||
Configuration.ForwardAllowlist = []string{"*->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", Configuration.ForwardMode, Configuration.ForwardAllowlist)
|
||||
config.Configuration.ForwardAllowlist = []string{"*->*"}
|
||||
log.Tracef("[test] Mode: %s, Rules: %v", config.Configuration.ForwardMode, config.Configuration.ForwardAllowlist)
|
||||
|
||||
key := &routerrpc.CircuitKey{
|
||||
ChanId: 123456789876543210,
|
||||
@@ -452,8 +452,8 @@ func TestChannelAllowlist_CorrectKey(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ChannelMode = "allowlist"
|
||||
Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
config.Configuration.ChannelMode = "allowlist"
|
||||
config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
|
||||
app.DispatchChannelAcceptor(ctx)
|
||||
|
||||
@@ -476,8 +476,8 @@ func TestChannelAllowlist_WrongKey(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ChannelMode = "allowlist"
|
||||
Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
config.Configuration.ChannelMode = "allowlist"
|
||||
config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
|
||||
app.DispatchChannelAcceptor(ctx)
|
||||
// wrong key: should be denied
|
||||
@@ -501,8 +501,8 @@ func TestChannelAllowlist_Wildcard(t *testing.T) {
|
||||
app.DispatchChannelAcceptor(ctx)
|
||||
|
||||
// wildcard: should be allowed
|
||||
Configuration.ChannelMode = "allowlist"
|
||||
Configuration.ChannelAllowlist = []string{"*"}
|
||||
config.Configuration.ChannelMode = "allowlist"
|
||||
config.Configuration.ChannelAllowlist = []string{"*"}
|
||||
|
||||
client.channelAcceptorRequests <- &lnrpc.ChannelAcceptRequest{
|
||||
NodePubkey: []byte("03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"),
|
||||
@@ -521,8 +521,8 @@ func TestChannelDenylist_Match(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ChannelMode = "denylist"
|
||||
Configuration.ChannelDenylist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
config.Configuration.ChannelMode = "denylist"
|
||||
config.Configuration.ChannelDenylist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
|
||||
app.DispatchChannelAcceptor(ctx)
|
||||
|
||||
@@ -545,8 +545,8 @@ func TestChannelAllowlist_Match(t *testing.T) {
|
||||
|
||||
app := NewApp(ctx, client)
|
||||
|
||||
Configuration.ChannelMode = "allowlist"
|
||||
Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
config.Configuration.ChannelMode = "allowlist"
|
||||
config.Configuration.ChannelAllowlist = []string{"03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6"}
|
||||
|
||||
app.DispatchChannelAcceptor(ctx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user