parameters_test.go 2.1 KB

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