public (string txHex, string txId) CreateNewTransactionWithData(Transaction tx0)
        {
            // Create transaction from a coin
            var coin = availableCoins.Dequeue();

            long txLength        = 110000;
            long dataLength      = 0;
            long standard        = txLength - dataLength;
            var  fee             = FeeQuoteRepository.GetValidFeeQuotesByIdentity(null).Single().Fees.Single(x => x.FeeType == Const.FeeType.Data);
            var  minRequiredFees = Math.Min((dataLength * fee.RelayFee.Satoshis) / fee.RelayFee.Bytes, // 0
                                            (dataLength * fee.MiningFee.Satoshis) / fee.MiningFee.Bytes);

            fee              = FeeQuoteRepository.GetValidFeeQuotesByIdentity(null).Single().Fees.Single(x => x.FeeType == Const.FeeType.Standard);
            minRequiredFees += Math.Min((standard * fee.RelayFee.Satoshis) / fee.RelayFee.Bytes,
                                        (standard * fee.MiningFee.Satoshis) / fee.MiningFee.Bytes); // 27500


            var tx1 = CreateTransaction(tx0, txLength, dataLength, minRequiredFees, coin);

            var key1 = Key.Parse(testPrivateKeyWif, Network.RegTest);

            tx1.Sign(key1.GetBitcoinSecret(Network.RegTest), coin);

            return(tx1.ToHex(), tx1.GetHash().ToString());
        }
        public async Task GetByID_CheckFeeAmountsConsistency()
        {
            var entryPost    = GetItemToCreate();
            var entryPostKey = ExtractPostKey(entryPost);

            // Create new feeQuote using POST and check created entry
            await Post <FeeQuoteViewModelCreate, FeeQuoteConfigViewModelGet>(client, entryPost, HttpStatusCode.Created);

            var getEntry = await Get <FeeQuoteConfigViewModelGet>(client, UrlForKey(entryPostKey), HttpStatusCode.OK);

            CheckWasCreatedFrom(entryPost, getEntry);

            // feeQuoteDb is loaded directly from db, should be equal to the one we GET through REST API
            var feeQuoteDb = FeeQuoteRepository.GetFeeQuoteById(long.Parse(entryPostKey), false);
            FeeQuoteConfigViewModelGet getEntryVm = new FeeQuoteConfigViewModelGet(feeQuoteDb);

            CheckWasCreatedFrom(entryPost, getEntryVm);
            // getEntryVm should also have same order of fees
            Assert.IsTrue(getEntry.Fees.First().FeeType == getEntryVm.Fees.First().FeeType);
            Assert.IsTrue(getEntry.Fees.Last().FeeType == getEntryVm.Fees.Last().FeeType);

            // we check if miningFee and relayFee are correctly loaded from db
            // if we select feeAmounts ordered by DESC (inside JOIN query)
            var feeQuoteDbDesc = FeeQuoteRepository.GetFeeQuoteById(long.Parse(entryPostKey), true);

            getEntryVm = new FeeQuoteConfigViewModelGet(feeQuoteDbDesc);
            // getEntryVm should should have different order of fees from getEntry
            Assert.IsTrue(getEntry.Fees.First().FeeType == getEntryVm.Fees.Last().FeeType);
            Assert.IsTrue(getEntry.Fees.Last().FeeType == getEntryVm.Fees.First().FeeType);
            // feeAmounts consistency is checked inside CheckWasCreatedFrom
            CheckWasCreatedFrom(entryPost, getEntryVm);
        }
Example #3
0
        protected void SetPoliciesForCurrentFeeQuote(string policiesJsonString, UserAndIssuer userAndIssuer = null)
        {
            var feeQuote = FeeQuoteRepository.GetCurrentFeeQuoteByIdentity(userAndIssuer);

            FeeQuoteRepositoryPostgres.EmptyRepository(DbConnectionStringDDL);

            feeQuote.Policies = policiesJsonString;

            using (MockedClock.NowIs(DateTime.UtcNow.AddMinutes(-1)))
            {
                if (FeeQuoteRepository.InsertFeeQuoteAsync(feeQuote).Result == null)
                {
                    throw new Exception("Can not insert test fee quote with policies.");
                }
            }
        }
Example #4
0
 protected void InsertFeeQuote(UserAndIssuer userAndIssuer = null)
 {
     using (MockedClock.NowIs(DateTime.UtcNow.AddMinutes(-1)))
     {
         var feeQuote = new FeeQuote
         {
             Id               = 1,
             CreatedAt        = MockedClock.UtcNow,
             ValidFrom        = MockedClock.UtcNow,
             Identity         = userAndIssuer?.Identity,
             IdentityProvider = userAndIssuer?.IdentityProvider,
             Fees             = new[] {
                 new Fee {
                     FeeType   = Const.FeeType.Standard,
                     MiningFee = new FeeAmount {
                         Satoshis      = 500,
                         Bytes         = 1000,
                         FeeAmountType = Const.AmountType.MiningFee
                     },
                     RelayFee = new FeeAmount {
                         Satoshis      = 250,
                         Bytes         = 1000,
                         FeeAmountType = Const.AmountType.RelayFee
                     },
                 },
                 new Fee {
                     FeeType   = Const.FeeType.Data,
                     MiningFee = new FeeAmount {
                         Satoshis      = 500,
                         Bytes         = 1000,
                         FeeAmountType = Const.AmountType.MiningFee
                     },
                     RelayFee = new FeeAmount {
                         Satoshis      = 250,
                         Bytes         = 1000,
                         FeeAmountType = Const.AmountType.RelayFee
                     },
                 },
             }
         };
         if (FeeQuoteRepository.InsertFeeQuoteAsync(feeQuote).Result == null)
         {
             throw new Exception("Can not insert test fee quote");
         }
     }
 }