Exemplo n.º 1
0
    public void SetUsedLabelIncludePrivateFunds()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.5"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out _, "Dan");

        var privateCoins = new[]
        {
            BitcoinFactory.CreateSmartCoin(LabelTestExtensions.NewKey(anonymitySet: 999), 0.5m),
            BitcoinFactory.CreateSmartCoin(LabelTestExtensions.NewKey(anonymitySet: 999), 0.5m),
        };
        var coinsView = new CoinsView(privateCoins.ToArray());
        var pocket    = new Pocket((SmartLabel.Empty, coinsView));

        pockets.Add(pocket);

        selection.Reset(pockets.ToArray());

        var output = selection.AutoSelectPockets("Dan");

        selection.SetUsedLabel(output.SelectMany(x => x.Coins), privateThreshold: 10);

        Assert.True(selection.EnoughSelected);
    }
Exemplo n.º 2
0
    public void StillIncludePrivateFundsAfterSwap()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
        var pockets   = new List <Pocket>();

        var privateCoin   = LabelTestExtensions.CreateCoin(0.8m, "", 999);
        var privatePocket = new Pocket((CoinPocketHelper.PrivateFundsText, new CoinsView(new[] { privateCoin })));

        pockets.Add(privatePocket);

        pockets.AddPocket(0.2M, out var pocket2, "Dan");
        pockets.AddPocket(0.1M, out var pocket3, "Lucas");

        selection.Reset(pockets.ToArray());

        var usedCoins = new List <SmartCoin>
        {
            privateCoin
        };

        usedCoins.AddRange(pocket2.Coins);

        selection.SetUsedLabel(usedCoins, 10);
        var output = selection.GetUsedPockets();

        Assert.Contains(privatePocket, output);
        Assert.Contains(pocket2, output);
        Assert.DoesNotContain(pocket3, output);
        Assert.True(selection.EnoughSelected);

        selection.SwapLabel(selection.GetLabel("Lucas"));
        selection.SwapLabel(selection.GetLabel("Lucas"));
        Assert.True(selection.EnoughSelected);
    }
Exemplo n.º 3
0
    public void IsOtherSelectionPossibleCases()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("0.5"));
        var pockets   = new List <Pocket>();

        var privatePocket     = LabelTestExtensions.CreateSingleCoinPocket(1.0m, CoinPocketHelper.PrivateFundsText, anonSet: 999);
        var semiPrivatePocket = LabelTestExtensions.CreateSingleCoinPocket(1.0m, CoinPocketHelper.SemiPrivateFundsText, anonSet: 2);

        pockets.Add(LabelTestExtensions.CreateSingleCoinPocket(1.0m, "Dan"));
        pockets.Add(LabelTestExtensions.CreateSingleCoinPocket(1.0m, "Dan, Lucas"));
        selection.Reset(pockets.ToArray());

        // Other pocket can be used case.
        var recipient = "Lucas";
        var output    = selection.AutoSelectPockets(recipient);

        Assert.True(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        // Exact match. Recipient == pocket, no better selection.
        recipient = "Dan";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Add(privatePocket);
        selection.Reset(pockets.ToArray());

        // Private funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Remove(privatePocket);
        pockets.Add(semiPrivatePocket);
        selection = new LabelSelectionViewModel(Money.Parse("0.5"));
        selection.Reset(pockets.ToArray());

        // Semi funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use semi private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Add(privatePocket);
        selection = new LabelSelectionViewModel(Money.Parse("1.5"));
        selection.Reset(pockets.ToArray());

        // Private and semi funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use semi private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));
    }
Exemplo n.º 4
0
    public void SetUsedLabelIgnoreCase()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, "Dan");
        pockets.AddPocket(1.0M, out var pocket2, "Lucas");

        selection.Reset(pockets.ToArray());

        var output = selection.AutoSelectPockets("Dan");

        Assert.Contains(pocket1, output);
        Assert.DoesNotContain(pocket2, output);

        var hdpk     = LabelTestExtensions.NewKey("dan");
        var usedCoin = BitcoinFactory.CreateSmartCoin(hdpk, 1.0M);

        selection.SetUsedLabel(new[] { usedCoin }, privateThreshold: 10);

        Assert.Contains(selection.GetLabel("Lucas"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsWhiteList);
    }