Add test, fix bug
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/SmartTransactionTests.cs
WalletWasabi.Tests/UnitTests/Transactions/SmartTransactionTests.cs
@@ -3,6 +3,8 @@ using Newtonsoft.Json;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+using WalletWasabi.Blockchain.Analysis.Clustering;
+using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
@@ -228,6 +230,41 @@ public class SmartTransactionTests
Assert.Equal(foreingOutputsAmount, foreingVirtualOutputsAmount);
}
+ [Fact]
+ public void SmartTransactionVirtualForeignOutputMerge()
+ {
+ var km = ServiceFactory.CreateKeyManager("");
+ var network = km.GetNetwork();
+ HdPubKey hdPubKey = BitcoinFactory.CreateHdPubKey(km);
+
+ Script samePubScript1 = hdPubKey.PubKey.GetAddress(ScriptPubKeyType.Segwit, network).ScriptPubKey;
+ Script samePubScript2 = hdPubKey.PubKey.GetAddress(ScriptPubKeyType.Legacy, network).ScriptPubKey;
+
+ Transaction t = Transaction.Create(network);
+
+ TxOut txout = new(Money.Coins(1), samePubScript1);
+ TxOut txout2 = new(Money.Coins(1), samePubScript2);
+
+ t.Outputs.Add(txout);
+ t.Outputs.Add(txout2);
+ SmartTransaction st1 = new(t, 0);
+
+ Assert.Single(st1.ForeignVirtualOutputs);
+ Assert.Equal(2, st1.ForeignVirtualOutputs.First().OutPoints.Count);
+
+ Transaction t2 = Transaction.Create(network);
+
+ TxOut txout3 = new(Money.Coins(1), samePubScript1);
+ TxOut txout4 = new(Money.Coins(1), samePubScript1);
+
+ t2.Outputs.Add(txout3);
+ t2.Outputs.Add(txout4);
+ SmartTransaction st2 = new(t2, 0);
+
+ Assert.Equal(1, st2.ForeignVirtualOutputs.Count);
+ Assert.Equal(2, st2.ForeignVirtualOutputs.First().OutPoints.Count);
+ }
+
public static IEnumerable<object[]> GetSmartTransactionCombinations()
{
var networks = new List<Network>

MODIFY
WalletWasabi/Blockchain/Transactions/SmartTransaction.cs
WalletWasabi/Blockchain/Transactions/SmartTransaction.cs
@@ -6,6 +6,7 @@ using System.Linq;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Extensions;
+using WalletWasabi.Helpers;
using WalletWasabi.JsonConverters;
using WalletWasabi.Logging;
using WalletWasabi.Models;
@@ -101,7 +102,7 @@ public class SmartTransaction : IEquatable<SmartTransaction>
if (WalletVirtualInputsCache is null)
{
WalletVirtualInputsCache = WalletInputs
- .GroupBy(i => i.HdPubKey.PubKeyHash.ToBytes())
+ .GroupBy(i => i.HdPubKey.PubKeyHash.ToBytes(), new ByteArrayEqualityComparer())
.Select(g => new WalletVirtualInput(g.Key, g.ToHashSet()))
.ToHashSet();
}
@@ -117,7 +118,7 @@ public class SmartTransaction : IEquatable<SmartTransaction>
if (WalletVirtualOutputsCache is null)
{
WalletVirtualOutputsCache = WalletOutputs
- .GroupBy(o => o.HdPubKey.PubKeyHash.ToBytes())
+ .GroupBy(o => o.HdPubKey.PubKeyHash.ToBytes(), new ByteArrayEqualityComparer())
.Select(g => new WalletVirtualOutput(g.Key, g.Sum(o => o.Amount), g.Select(o => new OutPoint(GetHash(), o.Index)).ToHashSet()))
.ToHashSet();
}
@@ -133,7 +134,7 @@ public class SmartTransaction : IEquatable<SmartTransaction>
if (ForeignVirtualOutputsCache is null)
{
ForeignVirtualOutputsCache = ForeignOutputs
- .GroupBy(o => o.TxOut.ScriptPubKey.ExtractKeyId())
+ .GroupBy(o => o.TxOut.ScriptPubKey.ExtractKeyId(), new ByteArrayEqualityComparer())
.Select(g => new ForeignVirtualOutput(g.Key, g.Sum(o => o.TxOut.Value), g.Select(o => new OutPoint(GetHash(), o.N)).ToHashSet()))
.ToHashSet();
}

Add test, fix bug