`TransactionSignaturesRequest`: Add equality tests and define equality rules.
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/ConnectionConfirmationRequestTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/ConnectionConfirmationRequestTests.cs
@@ -18,6 +18,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
/// </summary>
public class ConnectionConfirmationRequestTests
{
+ /// <summary>Implementation of equality rules is important for idempotent request cache.</summary>
[Fact]
public void EqualityTest()
{

ADD
WalletWasabi.Tests/UnitTests/WabiSabi/Models/TransactionSignaturesRequestTests.cs
+using NBitcoin;
+using WalletWasabi.Tests.Helpers;
+using WalletWasabi.WabiSabi.Models;
+using Xunit;
+
+namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
+{
+ /// <summary>
+ /// Tests for <see cref="TransactionSignaturesRequest"/> class.
+ /// </summary>
+ public class TransactionSignaturesRequestTests
+ {
+ [Fact]
+ public void EqualityTest()
+ {
+ uint256 roundId = BitcoinFactory.CreateUint256();
+
+ using Key key1 = new();
+ using Key key2 = new();
+
+ // Request #1.
+ TransactionSignaturesRequest request1 = new(
+ RoundId: roundId,
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
+ new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
+ }
+ );
+
+ //// Request #2.
+ TransactionSignaturesRequest request2 = new(
+ RoundId: roundId,
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
+ new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
+ }
+ );
+
+ Assert.Equal(request1, request2);
+
+ //// Request #3.
+ TransactionSignaturesRequest request3 = new(
+ RoundId: BitcoinFactory.CreateUint256(), // Intentionally changed.
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
+ new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
+ }
+ );
+
+ Assert.NotEqual(request1, request3);
+
+ //// Request #4.
+ TransactionSignaturesRequest request4 = new(
+ RoundId: roundId,
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(999, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ), // Intentionally changed.
+ new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
+ }
+ );
+
+ Assert.NotEqual(request1, request4);
+
+ //// Request #5.
+ TransactionSignaturesRequest request5 = new(
+ RoundId: roundId,
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(1, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) ), // Intentionally changed.
+ new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
+ }
+ );
+
+ Assert.NotEqual(request1, request5);
+
+ //// Request #6.
+ TransactionSignaturesRequest request6 = new(
+ RoundId: roundId,
+ InputWitnessPairs: new InputWitnessPair[]
+ {
+ new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
+ new InputWitnessPair(999, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) ) // Intentionally changed.
+ }
+ );
+
+ Assert.NotEqual(request1, request6);
+ }
+ }
+}

MODIFY
WalletWasabi/WabiSabi/Models/TransactionSignaturesRequest.cs
WalletWasabi/WabiSabi/Models/TransactionSignaturesRequest.cs
+using NBitcoin;
using System;
using System.Collections.Generic;
-using NBitcoin;
+using System.Linq;
namespace WalletWasabi.WabiSabi.Models
{
- public record TransactionSignaturesRequest(
- uint256 RoundId,
- IEnumerable<InputWitnessPair> InputWitnessPairs
- );
+ public record TransactionSignaturesRequest(uint256 RoundId, IEnumerable<InputWitnessPair> InputWitnessPairs)
+ {
+ public override int GetHashCode()
+ {
+ int hash = 0;
+
+ foreach (InputWitnessPair item in InputWitnessPairs)
+ {
+ hash = (hash << 4) + item.GetHashCode();
+ }
+
+ return HashCode.Combine(RoundId, hash);
+ }
+
+ public virtual bool Equals(TransactionSignaturesRequest? other)
+ {
+ if (other is null)
+ {
+ return false;
+ }
+
+ bool isEqual = RoundId == other.RoundId
+ && InputWitnessPairs.SequenceEqual(other.InputWitnessPairs);
+
+ return isEqual;
+ }
+ }
}

`TransactionSignaturesRequest`: Add equality tests and define equality rules.