Example #1
0
        public void TestCanSpend_NegativeIndex()
        {
            // prepare utxo storage
            var unspentTransactions = ImmutableDictionary.CreateBuilder <UInt256, UnspentTx>();
            var unspentOutputs      = ImmutableDictionary.CreateBuilder <TxOutputKey, TxOutput>();

            // prepare unspent output
            var txHash = new UInt256(0);

            unspentTransactions.Add(txHash, new UnspentTx(confirmedBlockHash: 0, length: 1, state: OutputState.Unspent));
            unspentOutputs.Add(new TxOutputKey(txHash, UInt32.MaxValue), new TxOutput(0, ImmutableArray.Create <byte>()));

            // prepare utxo
            var chainStateStorage = new MemoryChainStateStorage(0, unspentTransactions.ToImmutable(), unspentOutputs.ToImmutable());
            var utxo = new Utxo(chainStateStorage);

            // prepare output reference
            var prevTxOutput = new TxOutputKey(txHash, txOutputIndex: UInt32.MaxValue);

            // check if output can be spent
            var canSpend = utxo.CanSpend(prevTxOutput);

            // verify output cannot be spent
            Assert.IsFalse(canSpend);
        }
Example #2
0
        public void TestCanSpend_Missing()
        {
            // prepare utxo storage
            var unspentTransactions = ImmutableDictionary.CreateBuilder <UInt256, UnspentTx>();
            var unspentOutputs      = ImmutableDictionary.CreateBuilder <TxOutputKey, TxOutput>();

            // prepare utxo
            var chainStateStorage = new MemoryChainStateStorage(0, unspentTransactions.ToImmutable(), unspentOutputs.ToImmutable());
            var utxo = new Utxo(chainStateStorage);

            // prepare output reference
            var prevTxOutput = new TxOutputKey(txHash: 0, txOutputIndex: 0);

            // check if output can be spent
            var canSpend = utxo.CanSpend(prevTxOutput);

            // verify output cannot be spent
            Assert.IsFalse(canSpend);
        }