Remove duplicate CreateCoin()
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -30,13 +30,12 @@ namespace WalletWasabi.Tests.Helpers;
public static class WabiSabiFactory
{
- public static Coin CreateCoin(Key key)
- => CreateCoin(key, Money.Coins(1));
-
- public static Coin CreateCoin(Key key, Money amount)
- => new(
- new OutPoint(Hashes.DoubleSHA256(key.PubKey.ToBytes()), 0),
- new TxOut(amount, key.PubKey.WitHash.ScriptPubKey));
+ public static Coin CreateCoin(Key? key = null, Money? amount = null)
+ {
+ key ??= new();
+ amount ??= Money.Coins(1);
+ return new(new OutPoint(Hashes.DoubleSHA256(key.PubKey.ToBytes()), 0), new TxOut(amount, key.PubKey.WitHash.ScriptPubKey));
+ }
public static OwnershipProof CreateOwnershipProof(Key key, uint256? roundHash = null)
=> OwnershipProof.GenerateCoinJoinInputProof(

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/Rounds/MultipartyTransactionStateTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/Rounds/MultipartyTransactionStateTests.cs
@@ -4,7 +4,6 @@ using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Rounds;
-using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using Xunit;
@@ -18,19 +17,13 @@ public class MultipartyTransactionStateTests
var cfg = new WabiSabiConfig();
var round = WabiSabiFactory.CreateRound(cfg);
- static Coin CreateCoin()
- {
- using var key = new Key();
- return WabiSabiFactory.CreateCoin(key);
- }
-
Coin coin1, coin2, coin3;
// Three events / three states
var state0 = round.Assert<ConstructionState>();
- var state1 = state0.AddInput(coin1 = CreateCoin());
- var state2 = state1.AddInput(coin2 = CreateCoin());
- var state3 = state2.AddInput(coin3 = CreateCoin());
+ var state1 = state0.AddInput(coin1 = WabiSabiFactory.CreateCoin());
+ var state2 = state1.AddInput(coin2 = WabiSabiFactory.CreateCoin());
+ var state3 = state2.AddInput(coin3 = WabiSabiFactory.CreateCoin());
// Unknown state. Assumes full state is required
var diffd30 = state3.GetStateFrom(-1);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/MultipartyTransactionTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/MultipartyTransactionTests.cs
@@ -31,8 +31,8 @@ public class MultipartyTransactionTests
using Key key1 = new();
using Key key2 = new();
- var alice1Coin = CreateCoin(script: key1.PubKey.WitHash.ScriptPubKey);
- var alice2Coin = CreateCoin(script: key2.PubKey.WitHash.ScriptPubKey);
+ var alice1Coin = WabiSabiFactory.CreateCoin(key1);
+ var alice2Coin = WabiSabiFactory.CreateCoin(key2);
var state = new ConstructionState(DefaultParameters);
@@ -107,7 +107,7 @@ public class MultipartyTransactionTests
[Fact]
public void AddWithOptimize()
{
- var coin = CreateCoin();
+ var coin = WabiSabiFactory.CreateCoin();
var state = new ConstructionState(DefaultParameters).AddInput(coin);
@@ -128,8 +128,8 @@ public class MultipartyTransactionTests
using Key key1 = new();
using Key key2 = new();
- var alice1Coin = CreateCoin(script: key1.PubKey.WitHash.ScriptPubKey);
- var alice2Coin = CreateCoin(script: key2.PubKey.WitHash.ScriptPubKey);
+ var alice1Coin = WabiSabiFactory.CreateCoin(key1);
+ var alice2Coin = WabiSabiFactory.CreateCoin(key2);
var state = new ConstructionState(DefaultParameters).AddInput(alice1Coin).AddInput(alice2Coin);
@@ -182,8 +182,8 @@ public class MultipartyTransactionTests
using Key key1 = new();
using Key key2 = new();
- var alice1Coin = CreateCoin(script: key1.PubKey.WitHash.ScriptPubKey);
- var alice2Coin = CreateCoin(script: key2.PubKey.WitHash.ScriptPubKey);
+ var alice1Coin = WabiSabiFactory.CreateCoin(key1);
+ var alice2Coin = WabiSabiFactory.CreateCoin(key2);
var state = new ConstructionState(DefaultParameters with { MiningFeeRate = feeRate })
.AddInput(alice1Coin)
@@ -238,7 +238,7 @@ public class MultipartyTransactionTests
[Fact]
public void NoDuplicateInputs()
{
- var coin = CreateCoin();
+ var coin = WabiSabiFactory.CreateCoin();
var state = new ConstructionState(DefaultParameters).AddInput(coin);
ThrowsProtocolException(WabiSabiProtocolErrorCode.NonUniqueInputs, () => state.AddInput(coin));
Assert.Single(state.Inputs);
@@ -250,14 +250,14 @@ public class MultipartyTransactionTests
public void OnlyAllowedInputTypes()
{
var legacyOnly = new ConstructionState(DefaultParameters with { AllowedInputTypes = ImmutableSortedSet.Create<ScriptType>(ScriptType.P2PKH) });
- var coin = CreateCoin();
+ var coin = WabiSabiFactory.CreateCoin();
ThrowsProtocolException(WabiSabiProtocolErrorCode.ScriptNotAllowed, () => legacyOnly.AddInput(coin));
}
[Fact]
public void InputAmountRanges()
{
- var coin = CreateCoin();
+ var coin = WabiSabiFactory.CreateCoin();
var exact = new ConstructionState(DefaultParameters with { AllowedInputAmounts = new MoneyRange(coin.Amount, coin.Amount) });
var above = new ConstructionState(DefaultParameters with { AllowedInputAmounts = new MoneyRange(2 * coin.Amount, 3 * coin.Amount) });
@@ -273,8 +273,8 @@ public class MultipartyTransactionTests
[Fact]
public void UneconomicalInputs()
{
- var alice1Coin = CreateCoin(new Money(1000L));
- var alice2Coin = CreateCoin(new Money(1001L));
+ var alice1Coin = WabiSabiFactory.CreateCoin(amount: new Money(1000L));
+ var alice2Coin = WabiSabiFactory.CreateCoin(amount: new Money(1001L));
// requires 1k sats per input in sat/vKB
var inputVsize = alice1Coin.ScriptPubKey.EstimateInputVsize();
@@ -331,9 +331,4 @@ public class MultipartyTransactionTests
var updated = state.AddOutput(output);
Assert.Equal(output, Assert.Single(updated.Outputs));
}
-
- private Coin CreateCoin(Money? amount = null, Script? script = null)
- => new Coin(
- BitcoinFactory.CreateOutPoint(),
- new TxOut(amount ?? Money.Coins(1), script ?? BitcoinFactory.CreateScript()));
}

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
@@ -139,7 +139,7 @@ public class SerializationTests
AssertSerialization(RoundState.FromRound(round));
var state = round.Assert<ConstructionState>();
- state = state.AddInput(CreateCoin());
+ state = state.AddInput(WabiSabiFactory.CreateCoin());
round.CoinjoinState = new SigningState(round.Parameters, state.Events);
AssertSerialization(RoundState.FromRound(round));
}
@@ -206,10 +206,4 @@ public class SerializationTests
new(
new[] { MAC.ComputeMAC(IssuerKey, Points.First(), Scalars.First()) },
new[] { new Proof(new GroupElementVector(Points.Take(2)), new ScalarVector(Scalars.Take(2))) });
-
- private static Coin CreateCoin()
- {
- using var key = new Key();
- return WabiSabiFactory.CreateCoin(key);
- }
}

Remove duplicate CreateCoin()