Exemplo n.º 1
0
        public async Task CreateBlock_EmptyTransactionSet_Null()
        {
            // Arrange

            // Act
            var result = await _blockProvider.CreateBlock(new HashSet <Transaction>(), new DateTime(1, 1, 1));

            // Assert
            Assert.Null(result);
        }
        public void GetTransaction_Id_SuccessResponse()
        {
            // Arrange
            var blockchainProvider =
                new ProofOfWorkBlockProvider(new MerkleTreeProvider(), _configurationServiceMock.Object);

            var transactionSetList = TransactionDataSet.TransactionData.Select(ts => (HashSet <Transaction>)ts.First())
                                     .ToList();

            transactionSetList[1].First().Id = "111111";

            BlockBase block = null;

            transactionSetList.ForEach(ts =>
                                       block = blockchainProvider.CreateBlock(ts, new DateTime(1, 1, 1), block).Result);

            _blockchainServiceMock.Setup(p => p.GetBlockchainTreeLinked())
            .Returns(new SuccessResponse <BlockBase>("The blockchain!", block));

            const string id = "111111";

            // Act
            var result = _transactionService.GetTransaction(id) as SuccessResponse <Transaction>;

            // Assert
            _blockchainServiceMock.Verify(p => p.GetBlockchainTreeLinked());

            Assert.NotNull(result);
            Assert.NotNull(result.Result);
            Assert.Equal(id, result.Result.Id);
            Assert.NotNull(result.Message);
            Assert.Equal("The transaction has been found", result.Message);
        }
        public async Task Validate_Blockchain_ErrorValidationResult()
        {
            // Arrange
            var genesisTransactions = (HashSet <Transaction>)TransactionDataSet.TransactionData.First().First();
            var blockTransactions   = (HashSet <Transaction>)TransactionDataSet.TransactionData.Last().First();

            var genesisBlock = await _proofOfWorkBlockProvider.CreateBlock(genesisTransactions, new DateTime(1, 1, 1));

            var blockchain =
                await _proofOfWorkBlockProvider.CreateBlock(blockTransactions, new DateTime(1, 1, 1), genesisBlock);

            blockchain.Header.Nonce     = "0";
            blockchain.Header.TimeStamp = new DateTime(1, 1, 1);

            // Act
            var result = _proofOfWorkValidator.Validate(blockchain);

            // Assert
            Assert.False(result.IsSuccess);
            Assert.Single(result.Errors);
        }