Exemple #1
0
        public void SendDustAsFeeTest(
            BitcoinBasedCurrency currency,
            decimal available,
            decimal amount,
            decimal fee,
            DustUsagePolicy dustUsagePolicy)
        {
            var change = available - amount - fee;

            var broadcastCallback = new Action <IBlockchainTransaction, int, int, CancellationToken>((tx, attempts, attemptsInterval, token) =>
            {
                var btcBasedTx = (IBitcoinBasedTransaction)tx;
                Assert.True(btcBasedTx.Fees == currency.CoinToSatoshi(fee + change));
            });

            var error = Send(
                currency: currency,
                available: available,
                amount: amount,
                fee: fee,
                dustUsagePolicy: dustUsagePolicy,
                apiSetup: apiMock =>
            {
                apiMock.Setup(a => a.TryBroadcastAsync(It.IsAny <IBlockchainTransaction>(), 10, 1000, CancellationToken.None))
                .Callback(broadcastCallback)
                .Returns(Task.FromResult(new Result <string>("<txid>")));
            },
                repositorySetup: (repositoryMock, fromAddress) =>
            {
                repositoryMock.Setup(r => r.GetWalletAddressAsync(It.IsAny <string>(), fromAddress.Address))
                .Returns(Task.FromResult(fromAddress));
            });

            Assert.Null(error);
        }
Exemple #2
0
        private Error Send(
            BitcoinBasedCurrency currency,
            decimal available,
            decimal amount,
            decimal fee,
            DustUsagePolicy dustUsagePolicy,
            Action <Mock <IBlockchainApi> > apiSetup = null,
            Action <Mock <IAccountDataRepository>, WalletAddress> repositorySetup = null)
        {
            var apiMock = new Mock <IBlockchainApi>();

            apiSetup?.Invoke(apiMock);

            var wallet      = new HdWallet(Network.TestNet);
            var fromAddress = wallet.GetAddress(currency, 0, 0);
            var fromOutputs = GetOutputs(fromAddress.Address, NBitcoin.Network.TestNet, currency.CoinToSatoshi(available)).ToList();

            var repositoryMock = new Mock <IAccountDataRepository>();

            repositorySetup?.Invoke(repositoryMock, fromAddress);

            var currencies = Common.CurrenciesTestNet;

            currencies.GetByName(currency.Name).BlockchainApi = apiMock.Object;

            var account = new BitcoinBasedAccount(
                currency: currency.Name,
                currencies: currencies,
                wallet: wallet,
                dataRepository: repositoryMock.Object);

            return(account
                   .SendAsync(
                       outputs: fromOutputs,
                       to: currency.TestAddress(),
                       amount: amount,
                       fee: fee,
                       dustUsagePolicy: dustUsagePolicy)
                   .WaitForResult());
        }