MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.87k stars 846 forks source link

Add details to OutputTooSmallException #1183

Closed NicolasDorier closed 1 year ago

NicolasDorier commented 1 year ago

Ping @farukmeta https://github.com/MetacoSA/NBitcoin/pull/1182#issuecomment-1702470698

farukterzioglu commented 1 year ago

in here, you said;

Case Before Now
you send bob 200 satoshi (without substract fee) Silently remove output Throw exception

But right now it looks like it is still silently removed. I tried this test but it fails;

[Fact]
[Trait("UnitTest", "UnitTest")]
public void DoNotGenerateTransactionWithDust()
{   
    var k = new Key();
    var scriptCoin = RandomCoin(Money.Coins(0.0003m), k.PubKey.ScriptPubKey, true);

    var builder = Network.CreateTransactionBuilder();

    var dust = builder.GetDust(new Key().GetScriptPubKey(ScriptPubKeyType.Legacy));

    var ex = Assert.Throws<OutputTooSmallException>(() => {
        builder
            .AddCoins(scriptCoin)
            .Send(new Key(), dust - Money.Satoshis(1))
            .SetChange(new Key())
            .BuildTransaction(false);
    }
    );
    Assert.Equal(OutputTooSmallException.ErrorType.TooSmallBeforeSubstractedFee, ex.Reason);
}

It is not throwing any exception if the amount being sent is less than dust. it is being removed (as Before)

@NicolasDorier can you confirm before/after in the table is correct

NicolasDorier commented 1 year ago

wtf, seems like a bug to me. I check