Skip to content

Commit

Permalink
Fix: FeeRate.GetFee would return 1000x more fee if the fee for the vi…
Browse files Browse the repository at this point in the history
…rtualSize was less than 1 sat
  • Loading branch information
NicolasDorier committed Sep 23, 2022
1 parent 738be49 commit fe7a177
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions NBitcoin.Tests/util_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,15 @@ public void Overflow()
Assert.Throws<OverflowException>(() => -1 * (Money)long.MinValue);
}


[Fact]
[Trait("UnitTest", "UnitTest")]
public void FeeRateCalculation()
{
Assert.Equal(Money.Satoshis(1L), new FeeRate(0.5m).GetFee(1));
Assert.Equal(Money.Satoshis(3L), new FeeRate(3m).GetFee(1));
}

[Fact]
[Trait("UnitTest", "UnitTest")]
public void FeeRateFormatting()
Expand Down
4 changes: 2 additions & 2 deletions NBitcoin/FeeRate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public FeeRate(decimal satoshiPerByte)
public Money GetFee(int virtualSize)
{
Money nFee = _FeePerK.Satoshi * virtualSize / 1000;
if (nFee == Money.Zero && _FeePerK.Satoshi > Money.Zero)
nFee = _FeePerK.Satoshi;
if (nFee == Money.Zero)
nFee = Money.Satoshis(1.0m);
return nFee;
}
public Money GetFee(Transaction tx)
Expand Down

0 comments on commit fe7a177

Please sign in to comment.