Simplify WabiSabiFactory assuming one input alices
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -22,16 +22,14 @@ namespace WalletWasabi.Tests.Helpers
{
public static class WabiSabiFactory
{
- public static InputRoundSignaturePair CreateInputRoundSignaturePair(Key? key = null, uint256? roundHash = null)
+ public static Coin CreateCoin(OutPoint? prevout = null, Key? key = null, Money? value = null)
+ => new Coin(prevout ?? BitcoinFactory.CreateOutPoint(), new TxOut(value ?? Money.Coins(1), BitcoinFactory.CreateScript(key)));
+
+ public static byte[] CreateOwnershipProof(Key? key = null, uint256? roundHash = null)
{
var rh = roundHash ?? BitcoinFactory.CreateUint256();
- var outpoint = BitcoinFactory.CreateOutPoint();
var coinJoinInputCommitmentData = new CoinJoinInputCommitmentData("CoinJoinCoordinatorIdentifier", rh);
-
- var signingKey = key ?? new();
- return new InputRoundSignaturePair(
- outpoint,
- OwnershipProof.GenerateCoinJoinInputProof(signingKey, coinJoinInputCommitmentData).ToBytes());
+ return OwnershipProof.GenerateCoinJoinInputProof(key ?? new(), coinJoinInputCommitmentData).ToBytes();
}
public static Round CreateRound(WabiSabiConfig cfg)
@@ -70,33 +68,22 @@ namespace WalletWasabi.Tests.Helpers
return arena;
}
- public static Alice CreateAlice(InputRoundSignaturePair? inputSigPair= null, Key? key = null, Money? value = null)
+ public static Alice CreateAlice(Key? key = null, OutPoint? prevout = null, Coin? coin = null, byte[]? roundSignature = null, Money? value = null)
{
- inputSigPair ??= CreateInputRoundSignaturePair();
-
- var coin = new Coin(inputSigPair.Input, new TxOut(value ?? Money.Coins(1), BitcoinFactory.CreateScript(key)));
-
- var alice = new Alice(coin, inputSigPair.RoundSignature);
+ key ??= new();
+ coin ??= CreateCoin(prevout, key, value);
+ roundSignature ??= CreateOwnershipProof(key);
+ var alice = new Alice(coin, roundSignature);
alice.Deadline = DateTimeOffset.UtcNow + TimeSpan.FromHours(1);
return alice;
}
- public static InputRegistrationRequest CreateInputRegistrationRequest(Key? key, Round? round)
- {
- var pair = CreateInputRoundSignaturePair(key, round?.Hash);
- return CreateInputRegistrationRequest(pair, round);
- }
-
- public static InputRegistrationRequest CreateInputRegistrationRequest(Round? round)
- => CreateInputRegistrationRequest(CreateInputRoundSignaturePair(null, round?.Hash), round);
-
- public static InputRegistrationRequest CreateInputRegistrationRequest()
- => CreateInputRegistrationRequest(pair: null, round: null);
+ public static InputRegistrationRequest CreateInputRegistrationRequest(Key? key = null, Round? round = null, OutPoint? prevout = null)
+ => CreateInputRegistrationRequest(prevout ?? BitcoinFactory.CreateOutPoint(), CreateOwnershipProof(key, round?.Hash), round);
- public static InputRegistrationRequest CreateInputRegistrationRequest(InputRoundSignaturePair? pair, Round? round)
+ public static InputRegistrationRequest CreateInputRegistrationRequest(OutPoint prevout, byte[] roundSignature, Round? round = null)
{
var roundId = round?.Id ?? Guid.NewGuid();
- var inputRoundSignaturePairs = pair ?? CreateInputRoundSignaturePair(null, round?.Hash);
(var amClient, var vsClient, _, _) = CreateWabiSabiClientsAndIssuers(round);
var (zeroAmountCredentialRequest, _) = amClient.CreateRequestForZeroAmount();
@@ -104,8 +91,8 @@ namespace WalletWasabi.Tests.Helpers
return new(
roundId,
- inputRoundSignaturePairs.Input,
- inputRoundSignaturePairs.RoundSignature,
+ prevout,
+ roundSignature,
zeroAmountCredentialRequest,
zeroVsizeCredentialRequest);
}

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputFailureTests.cs
@@ -150,13 +150,14 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
public async Task InputBannedAsync()
{
Prison prison = new();
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
+ var key = new Key();
+ var outpoint = BitcoinFactory.CreateOutPoint();
+ prison.Punish(outpoint, Punishment.Banned, Guid.NewGuid());
WabiSabiConfig cfg = new();
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
await using ArenaRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
- var req = WabiSabiFactory.CreateInputRegistrationRequest(pair, round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(prevout: outpoint, round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
@@ -167,14 +168,14 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
public async Task InputCanBeNotedAsync()
{
Prison prison = new();
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- prison.Punish(pair.Input, Punishment.Noted, Guid.NewGuid());
+ var outpoint = BitcoinFactory.CreateOutPoint();
+ prison.Punish(outpoint, Punishment.Noted, Guid.NewGuid());
WabiSabiConfig cfg = new();
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
await using ArenaRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
- var req = WabiSabiFactory.CreateInputRegistrationRequest(pair, round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(prevout: outpoint, round: round);
var ex = await Assert.ThrowsAnyAsync<Exception>(async () => await handler.RegisterInputAsync(req));
if (ex is WabiSabiProtocolException wspex)
{
@@ -188,14 +189,14 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
public async Task InputCantBeNotedAsync()
{
Prison prison = new();
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- prison.Punish(pair.Input, Punishment.Noted, Guid.NewGuid());
+ var outpoint = BitcoinFactory.CreateOutPoint();
+ prison.Punish(outpoint, Punishment.Noted, Guid.NewGuid());
WabiSabiConfig cfg = new() { AllowNotedInputRegistration = false };
var round = WabiSabiFactory.CreateRound(cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
await using ArenaRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
- var req = WabiSabiFactory.CreateInputRegistrationRequest(pair, round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(prevout: outpoint, round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);
@@ -212,7 +213,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
rpc.OnGetTxOutAsync = (_, _, _) => null;
await using ArenaRequestHandler handler = new(cfg, new(), arena, rpc);
- var req = WabiSabiFactory.CreateInputRegistrationRequest(round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputSpent, ex.ErrorCode);
@@ -229,7 +230,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
rpc.OnGetTxOutAsync = (_, _, _) => new() { Confirmations = 0 };
await using ArenaRequestHandler handler = new(cfg, new(), arena, rpc);
- var req = WabiSabiFactory.CreateInputRegistrationRequest(round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputUnconfirmed, ex.ErrorCode);
@@ -244,7 +245,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round);
MockRpcClient rpc = new();
- var req = WabiSabiFactory.CreateInputRegistrationRequest(round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: round);
for (int i = 1; i <= 100; i++)
{
rpc.OnGetTxOutAsync = (_, _, _) => new() { Confirmations = i, IsCoinBase = true };
@@ -273,7 +274,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
};
await using ArenaRequestHandler handler = new(cfg, new(), arena, rpc);
- var req = WabiSabiFactory.CreateInputRegistrationRequest(round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.ScriptNotAllowed, ex.ErrorCode);
@@ -289,7 +290,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
using Key key = new();
await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
- var req = WabiSabiFactory.CreateInputRegistrationRequest(round);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: round);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.WrongRoundSignature, ex.ErrorCode);
@@ -355,7 +356,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
var req = WabiSabiFactory.CreateInputRegistrationRequest(key, round);
// Make sure an Alice have already been registered with the same input.
- var anotherAlice = WabiSabiFactory.CreateAlice(new InputRoundSignaturePair(req.Input, req.RoundSignature)); // FIXME fugly
+ var anotherAlice = WabiSabiFactory.CreateAlice(prevout: req.Input, roundSignature: req.RoundSignature);
round.Alices.Add(anotherAlice);
round.SetPhase(Phase.ConnectionConfirmation);
@@ -377,7 +378,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
var req = WabiSabiFactory.CreateInputRegistrationRequest(key, round);
// Make sure an Alice have already been registered with the same input.
- var preAlice = WabiSabiFactory.CreateAlice(new (req.Input, req.RoundSignature)); // FIXME fugly
+ var preAlice = WabiSabiFactory.CreateAlice(prevout: req.Input, roundSignature: req.RoundSignature);
anotherRound.Alices.Add(preAlice);
anotherRound.SetPhase(Phase.ConnectionConfirmation);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputSuccessTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputSuccessTests.cs
@@ -51,7 +51,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
var req = WabiSabiFactory.CreateInputRegistrationRequest(key, round);
// Make sure an Alice have already been registered with the same input.
- var preAlice = WabiSabiFactory.CreateAlice(new (req.Input, req.RoundSignature)); // FIXME fugly
+ var preAlice = WabiSabiFactory.CreateAlice(prevout: req.Input, roundSignature: req.RoundSignature);
round.Alices.Add(preAlice);
await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
@@ -74,7 +74,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
var req = WabiSabiFactory.CreateInputRegistrationRequest(key, round);
// Make sure an Alice have already been registered with the same input.
- var preAlice = WabiSabiFactory.CreateAlice(new InputRoundSignaturePair(req.Input, req.RoundSignature)); // FIXME fugly
+ var preAlice = WabiSabiFactory.CreateAlice(prevout: req.Input, roundSignature: req.RoundSignature);
var initialRemaining = anotherRound.RemainingInputVsizeAllocation;
anotherRound.Alices.Add(preAlice);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputToBlameRoundTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterInputToBlameRoundTests.cs
@@ -25,7 +25,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
using Key key = new();
await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc(key));
- var req = WabiSabiFactory.CreateInputRegistrationRequest(blameRound);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: blameRound);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputNotWhitelisted, ex.ErrorCode);
@@ -35,15 +35,15 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
[Fact]
public async Task InputWhitelistedAsync()
{
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
+ var outpoint = BitcoinFactory.CreateOutPoint();
WabiSabiConfig cfg = new();
var round = WabiSabiFactory.CreateRound(cfg);
- round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
+ round.Alices.Add(WabiSabiFactory.CreateAlice(prevout: outpoint));
Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
await using ArenaRequestHandler handler = new(cfg, new(), arena, WabiSabiFactory.CreateMockRpc());
- var req = WabiSabiFactory.CreateInputRegistrationRequest(pair, blameRound);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(prevout: outpoint, round: blameRound);
var ex = await Assert.ThrowsAnyAsync<Exception>(async () => await handler.RegisterInputAsync(req));
if (ex is WabiSabiProtocolException wspex)
@@ -58,16 +58,16 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
public async Task InputWhitelistedButBannedAsync()
{
Prison prison = new();
- var pair = WabiSabiFactory.CreateInputRoundSignaturePair();
- prison.Punish(pair.Input, Punishment.Banned, Guid.NewGuid());
+ var outpoint = BitcoinFactory.CreateOutPoint();
+ prison.Punish(outpoint, Punishment.Banned, Guid.NewGuid());
WabiSabiConfig cfg = new();
var round = WabiSabiFactory.CreateRound(cfg);
- round.Alices.Add(WabiSabiFactory.CreateAlice(pair));
+ round.Alices.Add(WabiSabiFactory.CreateAlice(prevout: outpoint));
Round blameRound = WabiSabiFactory.CreateBlameRound(round, cfg);
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync(cfg, round, blameRound);
await using ArenaRequestHandler handler = new(cfg, prison, arena, WabiSabiFactory.CreateMockRpc());
- var req = WabiSabiFactory.CreateInputRegistrationRequest(pair, blameRound);
+ var req = WabiSabiFactory.CreateInputRegistrationRequest(round: blameRound, prevout: outpoint);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await handler.RegisterInputAsync(req));
Assert.Equal(WabiSabiProtocolErrorCode.InputBanned, ex.ErrorCode);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterOutputTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/RegisterOutputTests.cs
@@ -108,7 +108,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
[Fact]
public async Task TooMuchFundsAsync()
{
- WabiSabiConfig cfg = new() { MaxRegistrableAmount = Money.Coins(1.999m) };
+ WabiSabiConfig cfg = new() { MaxRegistrableAmount = Money.Coins(1.999m) }; // TODO migrate to MultipartyTransactionParameters
var round = WabiSabiFactory.CreateRound(cfg);
round.SetPhase(Phase.OutputRegistration);
round.Alices.Add(WabiSabiFactory.CreateAlice(value: Money.Coins(2)));

DELETE
WalletWasabi/WabiSabi/Models/InputRoundSignaturePair.cs
-using NBitcoin;
-
-namespace WalletWasabi.WabiSabi.Models
-{
- public record InputRoundSignaturePair(
- OutPoint Input,
- byte[] RoundSignature
- );
-}

Simplify WabiSabiFactory assuming one input alices