github.com/decred/dcrlnd@v0.7.6/lnwallet/parameters_test.go (about)

     1  package lnwallet
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/decred/dcrd/dcrutil/v4"
     8  	"github.com/decred/dcrlnd/input"
     9  	"github.com/decred/dcrlnd/lnwire"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  // TestDefaultRoutingFeeLimitForAmount tests that we use the correct default
    14  // routing fee depending on the amount.
    15  func TestDefaultRoutingFeeLimitForAmount(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	tests := []struct {
    19  		amount        lnwire.MilliAtom
    20  		expectedLimit lnwire.MilliAtom
    21  	}{
    22  		{
    23  			amount:        1,
    24  			expectedLimit: 1,
    25  		},
    26  		{
    27  			amount:        lnwire.NewMAtomsFromAtoms(1_000),
    28  			expectedLimit: lnwire.NewMAtomsFromAtoms(1_000),
    29  		},
    30  		{
    31  			amount:        lnwire.NewMAtomsFromAtoms(1_001),
    32  			expectedLimit: 50_050,
    33  		},
    34  		{
    35  			amount:        5_000_000_000,
    36  			expectedLimit: 250_000_000,
    37  		},
    38  	}
    39  
    40  	for _, test := range tests {
    41  		test := test
    42  
    43  		t.Run(fmt.Sprintf("%d sats", test.amount), func(t *testing.T) {
    44  			feeLimit := DefaultRoutingFeeLimitForAmount(test.amount)
    45  			require.Equal(t, int64(test.expectedLimit), int64(feeLimit))
    46  		})
    47  	}
    48  }
    49  
    50  // TestDustLimitForSize tests that we receive the expected dust limits for
    51  // various script types from btcd's GetDustThreshold function.
    52  func TestDustLimitForSize(t *testing.T) {
    53  	t.Parallel()
    54  
    55  	tests := []struct {
    56  		name          string
    57  		size          int64
    58  		expectedLimit dcrutil.Amount
    59  	}{
    60  		{
    61  			name:          "p2pkh dust limit",
    62  			size:          input.P2PKHPkScriptSize,
    63  			expectedLimit: 6030,
    64  		},
    65  		{
    66  			name:          "p2sh dust limit",
    67  			size:          input.P2SHPkScriptSize,
    68  			expectedLimit: 6030,
    69  		},
    70  		{
    71  			name:          "unknown pk script limit",
    72  			size:          25,
    73  			expectedLimit: 6030,
    74  		},
    75  	}
    76  
    77  	for _, test := range tests {
    78  		test := test
    79  
    80  		t.Run(test.name, func(t *testing.T) {
    81  			dustlimit := DustLimitForSize(test.size)
    82  			require.Equal(t, test.expectedLimit, dustlimit)
    83  		})
    84  	}
    85  }