Add tests of ownership proofs
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore.Rpc;
+using WalletWasabi.Crypto;
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
@@ -315,24 +316,21 @@ public class RegisterInputFailureTests
}
[Fact]
- public async Task WrongOwnershipProofAsync()
+ public async Task WrongScriptPubKeyInOwnershipProofAsync()
{
- using Key key = new();
- var coin = WabiSabiFactory.CreateCoin(key);
- WabiSabiConfig cfg = new();
- var round = WabiSabiFactory.CreateRound(cfg);
- var rpc = WabiSabiFactory.CreatePreconfiguredRpcClient(coin);
- using Arena arena = await ArenaBuilder.From(cfg).With(rpc).CreateAndStartAsync(round);
-
- var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
- using Key nonOwnerKey = new();
- var wrongOwnershipProof = WabiSabiFactory.CreateOwnershipProof(nonOwnerKey, round.Id);
+ await TestOwnershipProof((key, roundId) => WabiSabiFactory.CreateOwnershipProof(new Key(), roundId));
+ }
- var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(
- async () => await arenaClient.RegisterInputAsync(round.Id, coin.Outpoint, wrongOwnershipProof, CancellationToken.None));
- Assert.Equal(WabiSabiProtocolErrorCode.WrongOwnershipProof, ex.ErrorCode);
+ [Fact]
+ public async Task WrongRoundIdInOwnershipProofAsync()
+ {
+ await TestOwnershipProof((key, roundId) => WabiSabiFactory.CreateOwnershipProof(key, uint256.One));
+ }
- await arena.StopAsync(CancellationToken.None);
+ [Fact]
+ public async Task WrongCoordinatorIdentifierInOwnershipProofAsync()
+ {
+ await TestOwnershipProof((key, roundId) => OwnershipProof.GenerateCoinJoinInputProof(key, new OwnershipIdentifier(key, key.PubKey.WitHash.ScriptPubKey), new CoinJoinInputCommitmentData("test", roundId)));
}
[Fact]
@@ -444,4 +442,23 @@ public class RegisterInputFailureTests
await arena.StopAsync(CancellationToken.None);
}
+
+ private async Task TestOwnershipProof(Func<Key, uint256, OwnershipProof> ownershipProofFunc)
+ {
+ using Key key = new();
+ var coin = WabiSabiFactory.CreateCoin(key);
+ WabiSabiConfig cfg = new();
+ var round = WabiSabiFactory.CreateRound(cfg);
+ var rpc = WabiSabiFactory.CreatePreconfiguredRpcClient(coin);
+ using Arena arena = await ArenaBuilder.From(cfg).With(rpc).CreateAndStartAsync(round);
+
+ var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
+ OwnershipProof ownershipProof = ownershipProofFunc(key, round.Id);
+
+ var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(
+ async () => await arenaClient.RegisterInputAsync(round.Id, coin.Outpoint, ownershipProof, CancellationToken.None));
+ Assert.Equal(WabiSabiProtocolErrorCode.WrongOwnershipProof, ex.ErrorCode);
+
+ await arena.StopAsync(CancellationToken.None);
+ }
}

Add tests of ownership proofs