Esempio n. 1
0
        public void TestExceptionInLoadTxInput()
        {
            var expectedException = new Exception();

            var coreStorage = new Mock <ICoreStorage>();

            var chainedHeader = RandomData.RandomChainedHeader();
            var tx            = RandomData.RandomTransaction(new RandomDataOptions {
                TxInputCount = 1
            });
            var txLookupKey = new TxLookupKey(UInt256.Zero, 0);
            var inputTx     = RandomData.RandomTransaction();
            var loadingTx   = new LoadingTx(1, tx, chainedHeader, ImmutableArray.Create(txLookupKey));

            var loadingTxes = new BufferBlock <LoadingTx>();

            loadingTxes.Post(loadingTx);
            loadingTxes.Complete();

            // throw expected exception when the input transaction is looked up
            BlockTx outputTx = null;

            coreStorage.Setup(x => x.TryGetTransaction(txLookupKey.BlockHash, txLookupKey.TxIndex, out outputTx)).Throws(expectedException);

            var loadedTxes = TxLoader.LoadTxes(coreStorage.Object, loadingTxes);

            Exception actualEx;

            AssertMethods.AssertAggregateThrows <Exception>(() =>
                                                            loadedTxes.ToEnumerable().ToList(), out actualEx);
            Assert.AreSame(expectedException, actualEx);
        }
Esempio n. 2
0
 public static byte[] EncodeTxLookupKey(TxLookupKey txLookupKey)
 {
     using (var stream = new MemoryStream())
         using (var writer = new BinaryWriter(stream))
         {
             EncodeTxLookupKey(writer, txLookupKey);
             return(stream.ToArray());
         }
 }
Esempio n. 3
0
 public static void EncodeTxLookupKey(BinaryWriter writer, TxLookupKey txLookupKey)
 {
     writer.WriteUInt256(txLookupKey.BlockHash);
     writer.WriteInt32(txLookupKey.TxIndex);
 }