Пример #1
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));
    }
Пример #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);
    }
Пример #3
0
    public void MovesFromWhiteListHighlightsAllLabelsInOtherPocketsThatContainTargetLabel()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out _, "Target", "Dan", "Roland");
        pockets.AddPocket(1.0M, out _, "Target");
        pockets.AddPocket(1.0M, out _, "David", "Adam", "Lucas");
        pockets.AddPocket(1.0M, out _, "Jumar");

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Target"));

        Assert.Contains(selection.GetLabel("Target"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Roland"), selection.LabelsBlackList);

        Assert.DoesNotContain(selection.GetLabel("David"), selection.LabelsBlackList);
        Assert.DoesNotContain(selection.GetLabel("Adam"), selection.LabelsBlackList);
        Assert.DoesNotContain(selection.GetLabel("Lucas"), selection.LabelsBlackList);
        Assert.DoesNotContain(selection.GetLabel("Jumar"), selection.LabelsBlackList);

        Assert.DoesNotContain(selection.GetLabel("Target"), selection.LabelsWhiteList);
        Assert.DoesNotContain(selection.GetLabel("Dan"), selection.LabelsWhiteList);
        Assert.DoesNotContain(selection.GetLabel("Roland"), selection.LabelsWhiteList);

        Assert.Contains(selection.GetLabel("David"), selection.LabelsWhiteList);
        Assert.Contains(selection.GetLabel("Adam"), selection.LabelsWhiteList);
        Assert.Contains(selection.GetLabel("Lucas"), selection.LabelsWhiteList);
        Assert.Contains(selection.GetLabel("Jumar"), selection.LabelsWhiteList);
    }
Пример #4
0
    public void AutoSelectOnlyKnownPockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(1.1M, out var pocket2, "Dan");
        pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
        pockets.AddPocket(0.1M, out var pocket4, "David", "Lucas");
        pockets.AddPocket(0.15M, out var pocket5, "David");
        pockets.AddPocket(0.2M, out var pocket6, "Lucas");
        pockets.AddPocket(0.3M, out var pocket7, "David", "Lucas", "Dan");

        selection.Reset(pockets.ToArray());

        var output = selection.AutoSelectPockets(new SmartLabel("David", "Lucas"));

        Assert.DoesNotContain(pocket1, output);
        Assert.Contains(pocket2, output);
        Assert.DoesNotContain(pocket3, output);
        Assert.Contains(pocket4, output);
        Assert.Contains(pocket5, output);
        Assert.Contains(pocket6, output);
        Assert.Contains(pocket7, output);
    }
Пример #5
0
    public void BlackListHighlightsDealWithMultipleOverlapsCorrectly()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, "Target", "Dan");
        pockets.AddPocket(1.0M, out var pocket2, "Target");
        pockets.AddPocket(1.0M, out var pocket3, "Target", "Roland");

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Target"));

        Assert.Contains(selection.GetLabel("Target"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Roland"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsBlackList);

        selection.GetLabel("Dan").IsPointerOver = true;

        Assert.True(selection.GetLabel("Dan").IsHighlighted);
        Assert.False(selection.GetLabel("Roland").IsHighlighted);
        Assert.True(selection.GetLabel("Target").IsHighlighted);

        var output = selection.GetUsedPockets();

        Assert.DoesNotContain(pocket1, output);
        Assert.DoesNotContain(pocket2, output);
        Assert.DoesNotContain(pocket3, output);
    }
Пример #6
0
    public void AutoSelectMultipleKnownByMultipleRecipientPockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(1.1M, out var pocket2, "Dan");
        pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
        pockets.AddPocket(0.5M, out var pocket4, "David", "Lucas", "Dan");
        pockets.AddPocket(0.6M, out var pocket5, "David");
        pockets.AddPocket(0.5M, out var pocket6, "Lucas");
        pockets.AddPocket(0.5M, out var pocket7, "David", "Lucas", "Dan", "Roland");
        pockets.AddPocket(0.5M, out var pocket8, "David", "Dan");

        selection.Reset(pockets.ToArray());

        var output = selection.AutoSelectPockets("David, Lucas");

        Assert.DoesNotContain(pocket1, output);
        Assert.DoesNotContain(pocket2, output);
        Assert.DoesNotContain(pocket3, output);
        Assert.Contains(pocket4, output);
        Assert.Contains(pocket5, output);
        Assert.DoesNotContain(pocket6, output);
        Assert.DoesNotContain(pocket7, output);
        Assert.DoesNotContain(pocket8, output);
    }
Пример #7
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);
    }
Пример #8
0
    public void PrivatePocketIsHidden()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(2.0M, out var pocket2, "Dan");

        selection.Reset(pockets.ToArray());

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

        // Not found.
        Assert.Throws <InvalidOperationException>(() => selection.GetLabel(CoinPocketHelper.PrivateFundsText));
    }
Пример #9
0
    public void NotEnoughSelected()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

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

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("David"));
        selection.SwapLabel(selection.GetLabel("Dan"));

        Assert.False(selection.EnoughSelected);
    }
Пример #10
0
    public void UnlabelledPocketNotUsed()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("0.4"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.5M, out var pocket1, CoinPocketHelper.UnlabelledFundsText);
        pockets.AddPocket(0.5M, out var pocket2, "Dan");

        selection.Reset(pockets.ToArray());

        var output = selection.GetSafeToUsePockets();

        Assert.DoesNotContain(pocket1, output);
        Assert.Contains(pocket2, output);
    }
Пример #11
0
    public void WhiteListSwapsAllLabelsInOtherPocketsThatContainTargetLabelAndTheOtherLabelsInThosePockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

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

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Dan"));

        Assert.Contains(selection.GetLabel("Target"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Roland"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsBlackList);
    }
Пример #12
0
    public void WhiteListHighlightsAllLabelsInOtherPocketsThatContainTargetLabelAndTheOtherLabelsInThosePockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

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

        selection.Reset(pockets.ToArray());

        selection.GetLabel("Dan").IsPointerOver = true;

        Assert.True(selection.GetLabel("Target").IsHighlighted);
        Assert.True(selection.GetLabel("Roland").IsHighlighted);
        Assert.True(selection.GetLabel("Dan").IsHighlighted);
    }
Пример #13
0
    public void AutoSelectAllPockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.5"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(0.3M, out var pocket2, "Dan");
        pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);

        selection.Reset(pockets.ToArray());

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

        Assert.Contains(pocket1, output);
        Assert.Contains(pocket2, output);
        Assert.Contains(pocket3, output);
    }
Пример #14
0
    public void IncludePrivateFunds()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("2.5"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(2.0M, out var pocket2, "Dan");

        selection.Reset(pockets.ToArray());

        Assert.True(selection.EnoughSelected);

        var output = selection.GetUsedPockets();

        Assert.Contains(pocket1, output);
        Assert.Contains(pocket2, output);
    }
Пример #15
0
    public void OutPutMatchesWhiteListScenario1()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

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

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Dan"));

        var output = selection.GetUsedPockets();

        Assert.DoesNotContain(pocket1, output);
        Assert.DoesNotContain(pocket2, output);
    }
Пример #16
0
    public void WhiteListHighlightsDealWithMultipleOverlapsCorrectly()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

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

        selection.Reset(pockets.ToArray());

        selection.GetLabel("Dan").IsPointerOver = true;

        Assert.True(selection.GetLabel("Dan").IsHighlighted);
        Assert.False(selection.GetLabel("Roland").IsHighlighted);
        Assert.False(selection.GetLabel("Target").IsHighlighted);
    }
Пример #17
0
    public void NotEnoughSelectedWhenSameLabelFoundInSeveralPockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.4M, out _, "Dan");
        pockets.AddPocket(2.0M, out _, "Dan", "David");

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Dan"));
        selection.SwapLabel(selection.GetLabel("Dan"));

        Assert.DoesNotContain(selection.GetLabel("Dan"), selection.LabelsBlackList);
        Assert.DoesNotContain(selection.GetLabel("David"), selection.LabelsWhiteList);

        Assert.False(selection.EnoughSelected);
    }
Пример #18
0
    public void AutoSelectOnlyUnknownPocket()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("0.7"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(0.5M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(0.5M, out var pocket2, "Dan");
        pockets.AddPocket(0.8M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
        pockets.AddPocket(0.1M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);

        selection.Reset(pockets.ToArray());

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

        Assert.DoesNotContain(pocket1, output);
        Assert.DoesNotContain(pocket2, output);
        Assert.Contains(pocket3, output);
        Assert.DoesNotContain(pocket4, output);
    }
Пример #19
0
    public void AutoSelectOnlyKnownByRecipientPocketsCaseInsensitive()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(2.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(1.1M, out var pocket2, "Dan");
        pockets.AddPocket(1.1M, out var pocket3, "Lucas", "Dan");
        pockets.AddPocket(1.1M, out var pocket4, "dan");

        selection.Reset(pockets.ToArray());

        var output = selection.AutoSelectPockets(new SmartLabel("dAN"));

        Assert.DoesNotContain(pocket1, output);
        Assert.Contains(pocket2, output);
        Assert.DoesNotContain(pocket3, output);
        Assert.Contains(pocket4, output);
    }
Пример #20
0
    public void AllWhitelistPocketsAreOutput()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, "Target", "Dan", "Roland");
        pockets.AddPocket(1.0M, out var pocket2, "Target");
        pockets.AddPocket(1.0M, out var pocket3, "David", "Adam", "Lucas");
        pockets.AddPocket(1.0M, out var pocket4, "Jumar");

        selection.Reset(pockets.ToArray());

        var output = selection.GetUsedPockets();

        Assert.Contains(pocket1, output);
        Assert.Contains(pocket2, output);
        Assert.Contains(pocket3, output);
        Assert.Contains(pocket4, output);
    }
Пример #21
0
    public void UseOnlyPrivateFunds()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, CoinPocketHelper.PrivateFundsText);
        pockets.AddPocket(2.0M, out var pocket2, "Dan");

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Dan"));

        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsBlackList);
        Assert.True(selection.EnoughSelected);

        var output = selection.GetUsedPockets();

        Assert.DoesNotContain(pocket2, output);
        Assert.Contains(pocket1, output);
    }
Пример #22
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);
    }
Пример #23
0
    public void WhiteListSwapsGroupedLabelsInOtherPocketsThatContainTargetLabelExceptThoseAvailableInOtherPockets()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("1.0"));

        var pockets = new List <Pocket>();

        pockets.AddPocket(1.0M, out var pocket1, "Target", "Dan");
        pockets.AddPocket(1.0M, out var pocket2, "Target");
        pockets.AddPocket(1.0M, out var pocket3, "Target", "Roland");

        selection.Reset(pockets.ToArray());

        selection.SwapLabel(selection.GetLabel("Dan"));

        Assert.DoesNotContain(selection.GetLabel("Target"), selection.LabelsBlackList);
        Assert.DoesNotContain(selection.GetLabel("Roland"), selection.LabelsBlackList);
        Assert.Contains(selection.GetLabel("Dan"), selection.LabelsBlackList);

        var output = selection.GetUsedPockets();

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