Beispiel #1
0
        public void TestBlockchainRootBlockHash()
        {
            var randomBlockchain = RandomData.RandomBlockchain();

            Assert.AreEqual(randomBlockchain.BlockList.Last().BlockHash, randomBlockchain.RootBlockHash);
        }
Beispiel #2
0
        public void TestBlockchainBlockCount()
        {
            var randomBlockchain = RandomData.RandomBlockchain();

            Assert.AreEqual(randomBlockchain.BlockList.Count, randomBlockchain.BlockCount);
        }
Beispiel #3
0
        public void TestUnspentTxEquality()
        {
            var randomUnspentTx = RandomData.RandomUnspentTx();

            var sameUnspentTx = new UnspentTx
                                (
                txHash: randomUnspentTx.TxHash,
                blockHash: randomUnspentTx.BlockHash,
                txIndex: randomUnspentTx.TxIndex,
                unspentOutputs: randomUnspentTx.UnspentOutputs
                                );

            var differentUnspentTxBlockHash = new UnspentTx
                                              (
                txHash: randomUnspentTx.TxHash,
                blockHash: ~randomUnspentTx.BlockHash,
                txIndex: randomUnspentTx.TxIndex,
                unspentOutputs: randomUnspentTx.UnspentOutputs
                                              );

            var differentUnspentTxTxIndex = new UnspentTx
                                            (
                txHash: randomUnspentTx.TxHash,
                blockHash: randomUnspentTx.BlockHash,
                txIndex: ~randomUnspentTx.TxIndex,
                unspentOutputs: randomUnspentTx.UnspentOutputs
                                            );

            var differentUnspentTxTxHash = new UnspentTx
                                           (
                txHash: ~randomUnspentTx.TxHash,
                blockHash: randomUnspentTx.BlockHash,
                txIndex: randomUnspentTx.TxIndex,
                unspentOutputs: randomUnspentTx.UnspentOutputs
                                           );

            var differentUnspentTxUnpsentOutputs = new UnspentTx
                                                   (
                txHash: ~randomUnspentTx.TxHash,
                blockHash: randomUnspentTx.BlockHash,
                txIndex: randomUnspentTx.TxIndex,
                unspentOutputs: randomUnspentTx.UnspentOutputs
                                                   );

            Assert.IsTrue(randomUnspentTx.Equals(sameUnspentTx));
            Assert.IsTrue(randomUnspentTx == sameUnspentTx);
            Assert.IsFalse(randomUnspentTx != sameUnspentTx);

            Assert.IsFalse(randomUnspentTx.Equals(differentUnspentTxBlockHash));
            Assert.IsFalse(randomUnspentTx == differentUnspentTxBlockHash);
            Assert.IsTrue(randomUnspentTx != differentUnspentTxBlockHash);

            Assert.IsFalse(randomUnspentTx.Equals(differentUnspentTxTxIndex));
            Assert.IsFalse(randomUnspentTx == differentUnspentTxTxIndex);
            Assert.IsTrue(randomUnspentTx != differentUnspentTxTxIndex);

            Assert.IsFalse(randomUnspentTx.Equals(differentUnspentTxTxHash));
            Assert.IsFalse(randomUnspentTx == differentUnspentTxTxHash);
            Assert.IsTrue(randomUnspentTx != differentUnspentTxTxHash);

            Assert.IsFalse(randomUnspentTx.Equals(differentUnspentTxUnpsentOutputs));
            Assert.IsFalse(randomUnspentTx == differentUnspentTxUnpsentOutputs);
            Assert.IsTrue(randomUnspentTx != differentUnspentTxUnpsentOutputs);
        }
Beispiel #4
0
        public void TestChainedBlockEquality()
        {
            var randomChainedBlock = RandomData.RandomChainedBlock();

            var sameChainedBlock = new ChainedBlock
                                   (
                blockHash: randomChainedBlock.BlockHash,
                previousBlockHash: randomChainedBlock.PreviousBlockHash,
                height: randomChainedBlock.Height,
                totalWork: randomChainedBlock.TotalWork
                                   );

            var differentChainedBlockBlockHash = new ChainedBlock
                                                 (
                blockHash: ~randomChainedBlock.BlockHash,
                previousBlockHash: randomChainedBlock.PreviousBlockHash,
                height: randomChainedBlock.Height,
                totalWork: randomChainedBlock.TotalWork
                                                 );

            var differentChainedBlockPreviousBlockHash = new ChainedBlock
                                                         (
                blockHash: randomChainedBlock.BlockHash,
                previousBlockHash: ~randomChainedBlock.PreviousBlockHash,
                height: randomChainedBlock.Height,
                totalWork: randomChainedBlock.TotalWork
                                                         );

            var differentChainedBlockHeight = new ChainedBlock
                                              (
                blockHash: randomChainedBlock.BlockHash,
                previousBlockHash: randomChainedBlock.PreviousBlockHash,
                height: ~randomChainedBlock.Height,
                totalWork: randomChainedBlock.TotalWork
                                              );

            var differentChainedBlockTotalWork = new ChainedBlock
                                                 (
                blockHash: randomChainedBlock.BlockHash,
                previousBlockHash: randomChainedBlock.PreviousBlockHash,
                height: randomChainedBlock.Height,
                totalWork: ~randomChainedBlock.TotalWork
                                                 );

            Assert.IsTrue(randomChainedBlock.Equals(sameChainedBlock));
            Assert.IsTrue(randomChainedBlock == sameChainedBlock);
            Assert.IsFalse(randomChainedBlock != sameChainedBlock);

            Assert.IsFalse(randomChainedBlock.Equals(differentChainedBlockBlockHash));
            Assert.IsFalse(randomChainedBlock == differentChainedBlockBlockHash);
            Assert.IsTrue(randomChainedBlock != differentChainedBlockBlockHash);

            Assert.IsFalse(randomChainedBlock.Equals(differentChainedBlockPreviousBlockHash));
            Assert.IsFalse(randomChainedBlock == differentChainedBlockPreviousBlockHash);
            Assert.IsTrue(randomChainedBlock != differentChainedBlockPreviousBlockHash);

            Assert.IsFalse(randomChainedBlock.Equals(differentChainedBlockHeight));
            Assert.IsFalse(randomChainedBlock == differentChainedBlockHeight);
            Assert.IsTrue(randomChainedBlock != differentChainedBlockHeight);

            Assert.IsFalse(randomChainedBlock.Equals(differentChainedBlockTotalWork));
            Assert.IsFalse(randomChainedBlock == differentChainedBlockTotalWork);
            Assert.IsTrue(randomChainedBlock != differentChainedBlockTotalWork);
        }
Beispiel #5
0
        public void TestTransactionEquality()
        {
            var randomTransaction = RandomData.RandomTransaction();

            var sameTransaction = new Transaction
                                  (
                version: randomTransaction.Version,
                inputs: ImmutableArray.Create(randomTransaction.Inputs.ToArray()),
                outputs: ImmutableArray.Create(randomTransaction.Outputs.ToArray()),
                lockTime: randomTransaction.LockTime
                                  );

            var differentTransactionVersion = new Transaction
                                              (
                version: ~randomTransaction.Version,
                inputs: randomTransaction.Inputs,
                outputs: randomTransaction.Outputs,
                lockTime: randomTransaction.LockTime
                                              );

            var differentTransactionInputs = new Transaction
                                             (
                version: randomTransaction.Version,
                inputs: ImmutableArray.Create(randomTransaction.Inputs.Concat(randomTransaction.Inputs.Last()).ToArray()),
                outputs: randomTransaction.Outputs,
                lockTime: randomTransaction.LockTime
                                             );

            var differentTransactionOutputs = new Transaction
                                              (
                version: randomTransaction.Version,
                inputs: randomTransaction.Inputs,
                outputs: ImmutableArray.Create(randomTransaction.Outputs.Concat(randomTransaction.Outputs.Last()).ToArray()),
                lockTime: randomTransaction.LockTime
                                              );

            var differentTransactionLockTime = new Transaction
                                               (
                version: randomTransaction.Version,
                inputs: randomTransaction.Inputs,
                outputs: randomTransaction.Outputs,
                lockTime: ~randomTransaction.LockTime
                                               );

            Assert.IsTrue(randomTransaction.Equals(sameTransaction));
            Assert.IsTrue(randomTransaction == sameTransaction);
            Assert.IsFalse(randomTransaction != sameTransaction);

            Assert.IsFalse(randomTransaction.Equals(differentTransactionVersion));
            Assert.IsFalse(randomTransaction == differentTransactionVersion);
            Assert.IsTrue(randomTransaction != differentTransactionVersion);

            Assert.IsFalse(randomTransaction.Equals(differentTransactionInputs));
            Assert.IsFalse(randomTransaction == differentTransactionInputs);
            Assert.IsTrue(randomTransaction != differentTransactionInputs);

            Assert.IsFalse(randomTransaction.Equals(differentTransactionOutputs));
            Assert.IsFalse(randomTransaction == differentTransactionOutputs);
            Assert.IsTrue(randomTransaction != differentTransactionOutputs);

            Assert.IsFalse(randomTransaction.Equals(differentTransactionLockTime));
            Assert.IsFalse(randomTransaction == differentTransactionLockTime);
            Assert.IsTrue(randomTransaction != differentTransactionLockTime);
        }
Beispiel #6
0
        public void TestBlockchainTotalWork()
        {
            var randomBlockchain = RandomData.RandomBlockchain();

            Assert.AreEqual(randomBlockchain.BlockList.Last().TotalWork, randomBlockchain.TotalWork);
        }
Beispiel #7
0
        public void TestBlockchainHeight()
        {
            var randomBlockchain = RandomData.RandomBlockchain();

            Assert.AreEqual(randomBlockchain.BlockList.Count - 1, randomBlockchain.Height);
        }