Improve test classes
MODIFY
WalletWasabi.Tests/Helpers/AnalyzedTransaction/AnalyzedTransaction.cs
WalletWasabi.Tests/Helpers/AnalyzedTransaction/AnalyzedTransaction.cs
@@ -31,12 +31,14 @@ public class AnalyzedTransaction : SmartTransaction
private static Script CreateScript(string? label = null)
{
- return CreateKey(label).PubKey.WitHash.ScriptPubKey;
+ using var k = CreateKey(label);
+ return k.PubKey.WitHash.ScriptPubKey;
}
private static HdPubKey CreateHdPubKey(string? label = null)
{
- return new HdPubKey(CreateKey(label).PubKey, new KeyPath("0/0/0/0/0"), SmartLabel.Empty, KeyState.Clean);
+ using var k = CreateKey(label);
+ return new(k.PubKey, new KeyPath("0/0/0/0/0"), SmartLabel.Empty, KeyState.Clean);
}
public void AddForeignInput(ForeignOutput output)
@@ -82,8 +84,8 @@ public class AnalyzedTransaction : SmartTransaction
public ForeignOutput AddForeignOutput(decimal amount = 1, string? label = null)
{
- uint index = (uint)Transaction.Outputs.Count();
- TxOut txOut = Transaction.Outputs.Add(new Money(amount, MoneyUnit.BTC), CreateScript(label));
+ uint index = (uint)Transaction.Outputs.Count;
+ Transaction.Outputs.Add(new Money(amount, MoneyUnit.BTC), CreateScript(label));
return new ForeignOutput(Transaction, index);
}

MODIFY
WalletWasabi.Tests/Helpers/AnalyzedTransaction/ForeignOutput.cs
WalletWasabi.Tests/Helpers/AnalyzedTransaction/ForeignOutput.cs
@@ -3,21 +3,9 @@ using WalletWasabi.Blockchain.Keys;
namespace WalletWasabi.Tests.Helpers.AnalyzedTransaction;
-public record ForeignOutput
+public record ForeignOutput(Transaction Transaction, uint Index)
{
- public Transaction Transaction;
- public uint Index;
-
- public ForeignOutput(Transaction transaction, uint index)
- {
- Transaction = transaction;
- Index = index;
- }
-
- public OutPoint ToOutPoint()
- {
- return new OutPoint(Transaction, Index);
- }
+ public OutPoint ToOutPoint() => new OutPoint(Transaction, Index);
public static ForeignOutput Create(Money amount, Script scriptPubKey)
{

MODIFY
WalletWasabi.Tests/Helpers/AnalyzedTransaction/WalletOutput.cs
WalletWasabi.Tests/Helpers/AnalyzedTransaction/WalletOutput.cs
@@ -5,32 +5,22 @@ using WalletWasabi.Blockchain.Transactions;
namespace WalletWasabi.Tests.Helpers.AnalyzedTransaction;
-public record WalletOutput
+public record WalletOutput(SmartCoin Coin)
{
- public SmartCoin SmartCoin;
+ public int Anonymity => Coin.HdPubKey.AnonymitySet;
- public WalletOutput(SmartCoin smartCoin)
- {
- SmartCoin = smartCoin;
- }
-
- public int Anonymity => SmartCoin.HdPubKey.AnonymitySet;
-
- public SmartCoin ToSmartCoin()
- {
- return SmartCoin;
- }
+ public SmartCoin ToSmartCoin() => Coin;
public ForeignOutput ToForeignOutput()
{
- return new ForeignOutput(SmartCoin.Transaction.Transaction, SmartCoin.Index);
+ return new ForeignOutput(Coin.Transaction.Transaction, Coin.Index);
}
public static WalletOutput Create(Money amount, HdPubKey hdPubKey)
{
ForeignOutput output = ForeignOutput.Create(amount, hdPubKey.P2wpkhScript);
- SmartTransaction smartTransaction = new SmartTransaction(output.Transaction, 0);
- SmartCoin smartCoin = new SmartCoin(smartTransaction, output.Index, hdPubKey);
+ SmartTransaction smartTransaction = new(output.Transaction, 0);
+ SmartCoin smartCoin = new(smartTransaction, output.Index, hdPubKey);
smartTransaction.AddWalletOutput(smartCoin);
return new WalletOutput(smartCoin);
}

MODIFY
WalletWasabi.Tests/UnitTests/BlockchainAnalysis/CoinJoinAnonscoreTests.cs
WalletWasabi.Tests/UnitTests/BlockchainAnalysis/CoinJoinAnonscoreTests.cs
@@ -264,19 +264,19 @@ public class CoinJoinAnonScoreTests
var tx1 = new AnalyzedTransaction();
tx1.AddForeignInput();
tx1.AddWalletInput();
- var A = tx1.AddForeignOutput();
- var B = tx1.AddWalletOutput();
+ var a = tx1.AddForeignOutput();
+ var b = tx1.AddWalletOutput();
var tx2 = new AnalyzedTransaction();
- tx2.AddForeignInput(A);
- tx2.AddWalletInput(B);
+ tx2.AddForeignInput(a);
+ tx2.AddWalletInput(b);
tx2.AddForeignOutput();
- var F = tx2.AddWalletOutput();
+ var f = tx2.AddWalletOutput();
tx2.AnalyzeRecursively();
- Assert.Equal(2, B.Anonymity);
- Assert.Equal(2, F.Anonymity);
+ Assert.Equal(2, b.Anonymity);
+ Assert.Equal(2, f.Anonymity);
}
[Fact]
@@ -285,30 +285,30 @@ public class CoinJoinAnonScoreTests
var tx1 = new AnalyzedTransaction();
tx1.AddForeignInput();
tx1.AddWalletInput();
- var A = tx1.AddForeignOutput();
- var B = tx1.AddWalletOutput();
+ var a = tx1.AddForeignOutput();
+ var b = tx1.AddWalletOutput();
var tx2 = new AnalyzedTransaction();
tx2.AddForeignInput();
- tx2.AddWalletInput(B);
- var C = tx2.AddForeignOutput();
- var D = tx2.AddWalletOutput();
- var E = tx2.AddWalletOutput();
+ tx2.AddWalletInput(b);
+ var c = tx2.AddForeignOutput();
+ var d = tx2.AddWalletOutput();
+ var e = tx2.AddWalletOutput();
var tx3 = new AnalyzedTransaction();
- tx3.AddForeignInput(A);
- tx3.AddForeignInput(C);
- tx3.AddWalletInput(D);
+ tx3.AddForeignInput(a);
+ tx3.AddForeignInput(c);
+ tx3.AddWalletInput(d);
tx3.AddForeignOutput();
tx3.AddForeignOutput();
tx3.AddForeignOutput();
- var L = tx3.AddWalletOutput();
+ var l = tx3.AddWalletOutput();
tx3.AnalyzeRecursively();
- Assert.Equal(2, B.Anonymity);
- Assert.Equal(2, D.Anonymity);
- Assert.Equal(2, E.Anonymity);
- Assert.Equal(3, L.Anonymity);
+ Assert.Equal(2, b.Anonymity);
+ Assert.Equal(2, d.Anonymity);
+ Assert.Equal(2, e.Anonymity);
+ Assert.Equal(3, l.Anonymity);
}
}

Improve test classes