Exemplo n.º 1
0
 def test_payment_below_min_part_size(self):
     amount = mpp_split.MIN_PART_MSAT // 2
     splits = mpp_split.suggest_splits(amount,
                                       self.channels_with_funds,
                                       exclude_single_parts=False)
     # we only get four configurations that end up spending the full amount
     # in a single channel
     self.assertEqual(4, len(splits))
Exemplo n.º 2
0
    def test_suggest_splits(self):
        with self.subTest(
                msg=
                "do a payment with the maximal amount spendable over a single channel"
        ):
            splits = mpp_split.suggest_splits(1_000_000_000,
                                              self.channels_with_funds,
                                              exclude_single_parts=True)
            self.assertEqual({
                0: 500_000_000,
                1: 500_000_000,
                2: 0,
                3: 0
            }, splits[0][0])

        with self.subTest(
                msg=
                "do a payment with a larger amount than what is supported by a single channel"
        ):
            splits = mpp_split.suggest_splits(1_100_000_000,
                                              self.channels_with_funds,
                                              exclude_single_parts=True)
            self.assertEqual({
                0: 798_000_000,
                1: 0,
                2: 302_000_000,
                3: 0
            }, splits[0][0])
            self.assertEqual({
                0: 908_000_000,
                1: 0,
                2: 192_000_000,
                3: 0
            }, splits[1][0])

        with self.subTest(
                msg=
                "do a payment with the maximal amount spendable over all channels"
        ):
            splits = mpp_split.suggest_splits(sum(
                self.channels_with_funds.values()),
                                              self.channels_with_funds,
                                              exclude_single_parts=True)
            self.assertEqual(
                {
                    0: 1_000_000_000,
                    1: 500_000_000,
                    2: 302_000_000,
                    3: 101_000_000
                }, splits[0][0])

        with self.subTest(
                msg="do a payment with the amount supported by all channels"):
            splits = mpp_split.suggest_splits(101_000_000,
                                              self.channels_with_funds,
                                              exclude_single_parts=False)
            for s in splits[:4]:
                self.assertEqual(1, mpp_split.number_nonzero_parts(s[0]))