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 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 Transaction 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); }
public static byte[] EncodeTxLookupKey(TxLookupKey txLookupKey) { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { EncodeTxLookupKey(writer, txLookupKey); return stream.ToArray(); } }
public static void EncodeTxLookupKey(BinaryWriter writer, TxLookupKey txLookupKey) { writer.WriteUInt256(txLookupKey.BlockHash); writer.WriteInt32(txLookupKey.TxIndex); }