public void NotEnoughFundsLogWarning() { // Throw a 'no spendable transactions' exception this.federationWalletTransactionHandler.Setup(x => x.BuildTransaction(It.IsAny <TransactionBuildContext>())) .Throws(new WalletException(FederationWalletTransactionHandler.NotEnoughFundsMessage)); var txBuilder = new WithdrawalTransactionBuilder( this.network, this.federationWalletManager.Object, this.federationWalletTransactionHandler.Object, this.federationGatewaySettings.Object, this.signals.Object, null ); var recipient = new Recipient { Amount = Money.Coins(101), ScriptPubKey = new Script() }; Transaction ret = txBuilder.BuildWithdrawalTransaction(0, uint256.One, 100, recipient); // Log out a warning in this case, not an error. this.logger .Setup(f => f.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>())) .Callback(new InvocationAction(invocation => { ((LogLevel)invocation.Arguments[0]).Should().Be(LogLevel.Warning); })); }
public void NotEnoughFundsLogWarning() { // Throw a 'no spendable transactions' exception this.federationWalletTransactionHandler.Setup(x => x.BuildTransaction(It.IsAny <TransactionBuildContext>())) .Throws(new WalletException(FederationWalletTransactionHandler.NotEnoughFundsMessage)); var txBuilder = new WithdrawalTransactionBuilder( this.loggerFactory.Object, this.network, this.federationWalletManager.Object, this.federationWalletTransactionHandler.Object, this.federationGatewaySettings.Object, this.signals.Object ); var recipient = new Recipient { Amount = Money.Coins(101), ScriptPubKey = new Script() }; Transaction ret = txBuilder.BuildWithdrawalTransaction(uint256.One, 100, recipient); // Log out a warning in this case, not an error. this.logger.Verify(x => x.Log <object>(LogLevel.Warning, It.IsAny <EventId>(), It.IsAny <object>(), null, It.IsAny <Func <object, Exception, string> >())); }
public void FeeIsTakenFromRecipient() { Script redeemScript = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, new[] { new Key().PubKey, new Key().PubKey }); this.federationWalletManager.Setup(x => x.GetSpendableTransactionsInWallet(It.IsAny <int>())) .Returns(new List <UnspentOutputReference> { new UnspentOutputReference { Transaction = new FederatedPeg.Wallet.TransactionData { Amount = Money.Coins(105), Id = uint256.One, ScriptPubKey = redeemScript.Hash.ScriptPubKey } } }); this.federationWalletManager.Setup(x => x.GetWallet()) .Returns(new FederationWallet { MultiSigAddress = new MultiSigAddress { RedeemScript = redeemScript } }); var txBuilder = new WithdrawalTransactionBuilder( this.loggerFactory.Object, this.network, this.federationWalletManager.Object, this.federationWalletTransactionHandler.Object, this.federationGatewaySettings.Object, this.signals.Object, null ); var recipient = new Recipient { Amount = Money.Coins(101), ScriptPubKey = new Script() }; Transaction ret = txBuilder.BuildWithdrawalTransaction(0, uint256.One, 100, recipient); Assert.NotNull(ret); // Fee taken from amount should be the total fee. Money expectedAmountAfterFee = recipient.Amount - FederatedPegSettings.CrossChainTransferFee; this.federationWalletTransactionHandler.Verify(x => x.BuildTransaction(It.Is <TransactionBuildContext>(y => y.Recipients.First().Amount == expectedAmountAfterFee))); // Fee used to send transaction should be a smaller amount. Money expectedTxFee = FederatedPegSettings.BaseTransactionFee + 1 * FederatedPegSettings.InputTransactionFee; this.federationWalletTransactionHandler.Verify(x => x.BuildTransaction(It.Is <TransactionBuildContext>(y => y.TransactionFee == expectedTxFee))); }
public void FeeIsTakenFromRecipient() { var txBuilder = new WithdrawalTransactionBuilder( this.loggerFactory.Object, this.network, this.federationWalletManager.Object, this.federationWalletTransactionHandler.Object, this.federationGatewaySettings.Object ); var recipient = new Recipient { Amount = Money.Coins(101), ScriptPubKey = new Script() }; Transaction ret = txBuilder.BuildWithdrawalTransaction(uint256.One, 100, recipient); Assert.NotNull(ret); Money expectedAmountAfterFee = recipient.Amount - this.federationGatewaySettings.Object.TransactionFee; this.federationWalletTransactionHandler.Verify(x=>x.BuildTransaction(It.Is<TransactionBuildContext>(y => y.Recipients.First().Amount == expectedAmountAfterFee))); }