Fix CA2000 warnings.
MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/IndexBuilderServiceTests.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
InitialBlockDownload = false
}),
};
- var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
+ using var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
var indexer = new IndexBuilderService(rpc, blockNotifier, ".");
indexer.Synchronize();
@@ -53,7 +53,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
});
}
};
- var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
+ using var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
var indexer = new IndexBuilderService(rpc, blockNotifier, ".");
indexer.Synchronize();
@@ -84,7 +84,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
OnGetBlockHashAsync = (height) => Task.FromResult(blockchain[height].Hash),
OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash))
};
- var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
+ using var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
var indexer = new IndexBuilderService(rpc, blockNotifier, ".");
indexer.Synchronize();
@@ -110,7 +110,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
OnGetBlockHashAsync = (height) => Task.FromResult(blockchain[height].Hash),
OnGetVerboseBlockAsync = (hash) => Task.FromResult(blockchain.Single(x => x.Hash == hash))
};
- var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
+ using var blockNotifier = new BlockNotifier(TimeSpan.MaxValue, rpc);
var indexer = new IndexBuilderService(rpc, blockNotifier, "filters.txt");
indexer.Synchronize();

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/MacTests.cs
WalletWasabi.Tests/UnitTests/Crypto/MacTests.cs
@@ -13,7 +13,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Trait("UnitTest", "UnitTest")]
public void CannotBuildWrongMac()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var sk = new CoordinatorSecretKey(rnd);
Assert.Throws<ArgumentNullException>(() => MAC.ComputeMAC(null!, Generators.G, Scalar.One));
@@ -26,7 +26,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Trait("UnitTest", "UnitTest")]
public void CanProduceAndVerifyMAC()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var sk = new CoordinatorSecretKey(rnd);
var attribute = rnd.GetScalar() * Generators.G; // any random point
@@ -41,7 +41,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Trait("UnitTest", "UnitTest")]
public void CanDetectInvalidMAC()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var sk = new CoordinatorSecretKey(rnd);
var attribute = rnd.GetScalar() * Generators.G; // any random point
@@ -65,7 +65,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Trait("UnitTest", "UnitTest")]
public void EqualityTests()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var right = (attribute: rnd.GetScalar() * Generators.G, sk: new CoordinatorSecretKey(rnd), t: rnd.GetScalar());
var wrong = (attribute: rnd.GetScalar() * Generators.G, sk: new CoordinatorSecretKey(rnd), t: rnd.GetScalar());

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using NBitcoin.Secp256k1;
using WalletWasabi.Crypto;
@@ -13,11 +14,12 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
{
[Fact]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyMAC()
{
// The coordinator generates a composed private key called CoordinatorSecretKey
// and derives from that the coordinator's public parameters called CoordinatorParameters.
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var coordinatorKey = new CoordinatorSecretKey(rnd);
var coordinatorParameters = coordinatorKey.ComputeCoordinatorParameters();
@@ -56,9 +58,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Fact]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyMacShow()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var coordinatorKey = new CoordinatorSecretKey(rnd);
var coordinatorParameters = coordinatorKey.ComputeCoordinatorParameters();
@@ -95,9 +98,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Fact]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyPresentedBalance()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var a = new Scalar(10_000u);
var r = rnd.GetScalar();
@@ -119,9 +123,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Fact]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyRequestedBalance()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var a = new Scalar(10_000u);
var r = rnd.GetScalar();
@@ -151,9 +156,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[InlineData(int.MaxValue - 1, int.MaxValue)]
[InlineData(int.MaxValue, int.MaxValue - 1)]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyBalance(int presentedAmount, int requestedAmount)
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var a = new Scalar((uint)presentedAmount);
var r = rnd.GetScalar();
@@ -196,7 +202,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[InlineData((ulong)uint.MaxValue + 1, 33, true)]
public void CanProveAndVerifyCommitmentRange(ulong amount, int width, bool pass)
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var amountScalar = new Scalar(amount);
var randomness = rnd.GetScalar();
@@ -217,9 +223,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
[Fact]
[Trait("UnitTest", "UnitTest")]
+ [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Variables denote math symbols.")]
public void CanProveAndVerifyZeroProofs()
{
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var a0 = Scalar.Zero;
var r0 = rnd.GetScalar();

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/RandomTests.cs
WalletWasabi.Tests/UnitTests/Crypto/RandomTests.cs
using NBitcoin.Secp256k1;
using System;
using System.Collections.Generic;
-using System.Linq;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Helpers;
using Xunit;
@@ -68,7 +67,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
}
}
- foreach (var random in randoms.Where(x => x is IDisposable))
+ foreach (WasabiRandom random in randoms)
{
(random as IDisposable)?.Dispose();
}
@@ -104,7 +103,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
Assert.Equal(count, set.Count);
}
- foreach (var random in randoms.Where(x => x is IDisposable))
+ foreach (WasabiRandom random in randoms)
{
(random as IDisposable)?.Dispose();
}

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
public void SyntheticNoncesTest()
{
var protocol = Encoding.UTF8.GetBytes("test TranscriptRng collisions");
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var commitment1 = new[] { Generators.Gx0 };
var commitment2 = new[] { Generators.Gx1 };
@@ -151,7 +151,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
{
var protocol = Encoding.UTF8.GetBytes("witness size");
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var witness = new Scalar[size];
@@ -168,7 +168,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
{
var protocol = Encoding.UTF8.GetBytes("empty witness not allowed");
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var transcript = new Transcript(protocol);

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfDlogTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfDlogTests.cs
using NBitcoin.Secp256k1;
using WalletWasabi.Crypto.Groups;
using WalletWasabi.Crypto.Randomness;
-using WalletWasabi.Crypto.ZeroKnowledge;
using WalletWasabi.Crypto.ZeroKnowledge.LinearRelation;
using WalletWasabi.Tests.Helpers;
using Xunit;
@@ -38,7 +37,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var generator = Generators.G;
var publicPoint = secret * generator;
var statement = new Statement(publicPoint, Generators.G);
- var proof = ProofSystemHelpers.Prove(statement, secret, new SecureRandom());
+ using SecureRandom random = new();
+ var proof = ProofSystemHelpers.Prove(statement, secret, random);
Assert.True(ProofSystemHelpers.Verify(statement, proof));
}
}
@@ -46,7 +46,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
[Fact]
public void End2EndVerificationLargeScalar()
{
- var random = new SecureRandom();
+ using var random = new SecureRandom();
uint val = int.MaxValue;
var gen = new Scalar(4) * Generators.G;

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfRepTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfRepTests.cs
@@ -47,7 +47,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var generators = new GroupElementVector(Generators.G, Generators.Ga);
var publicPoint = secrets * generators;
var statement = new Statement(publicPoint, generators);
- var proof = ProofSystemHelpers.Prove(statement, secrets, new SecureRandom());
+ using SecureRandom random = new();
+ var proof = ProofSystemHelpers.Prove(statement, secrets, random);
Assert.True(ProofSystemHelpers.Verify(statement, proof));
}
}

MODIFY
WalletWasabi.Tests/UnitTests/MemoryTests.cs
WalletWasabi.Tests/UnitTests/MemoryTests.cs
@@ -97,7 +97,7 @@ namespace WalletWasabi.Tests.UnitTests
}
using var cache = new MemoryCache(new MemoryCacheOptions());
- var expireKey1 = new CancellationTokenSource();
+ using var expireKey1 = new CancellationTokenSource();
var options = new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(10) };
options.AddExpirationToken(new CancellationChangeToken(expireKey1.Token));

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
WalletWasabi.Tests/UnitTests/Transactions/PayjoinTests.cs
using NBitcoin;
using System;
-using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
-using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionBuilding;
-using WalletWasabi.Blockchain.TransactionOutputs;
-using WalletWasabi.Blockchain.Transactions;
using WalletWasabi.Tests.UnitTests.Clients;
using WalletWasabi.WebClients.PayJoin;
using Xunit;
using System.Net.Http;
using System.Net;
using System.Text;
-using WalletWasabi.Models;
using System.Collections.Specialized;
-using WalletWasabi.Tor.Http;
using WalletWasabi.Tests.Helpers;
namespace WalletWasabi.Tests.UnitTests.Transactions
@@ -97,7 +91,8 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var allowedCoins = transactionFactory.Coins.ToArray();
var amount = Money.Coins(0.001m);
- var payment = new PaymentIntent(new Key().ScriptPubKey, amount);
+ using Key key = new();
+ PaymentIntent payment = new(key.ScriptPubKey, amount);
var tx = transactionFactory.BuildTransaction(payment, new FeeRate(2m), allowedCoins.Select(x => x.OutPoint), payjoinClient);

MODIFY
WalletWasabi.Tests/UnitTests/Wabisabi/CredentialTests.cs
WalletWasabi.Tests/UnitTests/Wabisabi/CredentialTests.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
public void CredentialIssuance()
{
var numberOfCredentials = 3;
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var sk = new CoordinatorSecretKey(rnd);
var client = new WabiSabiClient(sk.ComputeCoordinatorParameters(), numberOfCredentials, rnd);
@@ -121,7 +121,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
public void InvalidCredentialRequests()
{
var numberOfCredentials = 3;
- var rnd = new SecureRandom();
+ using var rnd = new SecureRandom();
var sk = new CoordinatorSecretKey(rnd);
var issuer = new CredentialIssuer(sk, numberOfCredentials, rnd);

MODIFY
WalletWasabi/Crypto/UnblindedSignature.cs
WalletWasabi/Crypto/UnblindedSignature.cs
using System;
+using System.Diagnostics.CodeAnalysis;
using NBitcoin.DataEncoders;
using NBitcoin.Secp256k1;
@@ -15,7 +16,7 @@ namespace WalletWasabi.Crypto
internal Scalar C { get; }
internal Scalar S { get; }
- public static bool TryParse(ReadOnlySpan<byte> in64, out UnblindedSignature? unblindedSignature)
+ public static bool TryParse(ReadOnlySpan<byte> in64, [NotNullWhen(true)] out UnblindedSignature? unblindedSignature)
{
unblindedSignature = null;
if (in64.Length != 64)
@@ -59,7 +60,7 @@ namespace WalletWasabi.Crypto
throw new FormatException("Invalid unblinded signature");
}
- public static bool TryParse(string str, out UnblindedSignature? unblindedSignature)
+ public static bool TryParse(string str, [NotNullWhen(true)] out UnblindedSignature? unblindedSignature)
{
unblindedSignature = null;
if (str is null)

Fix CA2000 warnings.