public void Given_AWatchedAddress_And_A_WatchedTransaction_CanPopulateLookup() { DataFolder dataFolder = CreateDataFolder(this); WatchOnlyWallet watchOnlyWallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder); // Only need to watch a single address/transaction Script newScript = BitcoinAddress.Create("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE", this.networkTestNet).ScriptPubKey; string transactionHex = "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff230384041200fe0eb3a959fe1af507000963676d696e6572343208000000000000000000ffffffff02155e8b09000000001976a9144bfe90c8e6c6352c034b3f57d50a9a6e77a62a0788ac0000000000000000266a24aa21a9ed0bc6e4bfe82e04a1c52e66b72b199c5124794dd8c3c368f6ab95a0ba6cde277d0120000000000000000000000000000000000000000000000000000000000000000000000000"; // Ensure transaction appears in block Transaction transaction = this.networkTestNet.CreateTransaction(transactionHex); Block block = this.networkTestNet.Consensus.ConsensusFactory.CreateBlock(); block.AddTransaction(transaction); block.UpdateMerkleRoot(); var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, this.networkTestNet, dataFolder, this.signals); walletManager.Initialize(); walletManager.WatchAddress("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE"); walletManager.StoreTransaction(new WatchTransactionData() { Id = transaction.GetHash(), Hex = transactionHex }); walletManager.ProcessBlock(block); WatchOnlyWallet wallet = walletManager.GetWatchOnlyWallet(); // Artificially remove info from the watched address version of the transaction WatchedAddress addressInWallet = wallet.WatchedAddresses[newScript.ToString()]; WatchTransactionData watchedTransaction = addressInWallet.Transactions.Values.First(); watchedTransaction.MerkleProof = null; watchedTransaction.BlockHash = null; // Now populate lookup ConcurrentDictionary <uint256, WatchTransactionData> lookup = wallet.GetWatchedTransactions(); // Expect that the cached version of the transaction has a // Merkle proof and block hash WatchTransactionData lookupTransaction = lookup[transaction.GetHash()]; Assert.NotNull(lookupTransaction.MerkleProof); Assert.NotNull(lookupTransaction.BlockHash); }
public void Given_AWatchedAddress_When_ATransactionIsReceivedInABlock_ThenTransactionDataIsAddedToTheAddress() { // Arrange. DataFolder dataFolder = CreateDataFolder(this); // Create the wallet to watch. WatchOnlyWallet wallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder); // Create the address to watch. Script newScript = BitcoinAddress.Create("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE", this.networkTestNet).ScriptPubKey; string newAddress = newScript.GetDestinationAddress(this.networkTestNet).ToString(); // Create a transaction to be received. string transactionHex = "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff230384041200fe0eb3a959fe1af507000963676d696e6572343208000000000000000000ffffffff02155e8b09000000001976a9144bfe90c8e6c6352c034b3f57d50a9a6e77a62a0788ac0000000000000000266a24aa21a9ed0bc6e4bfe82e04a1c52e66b72b199c5124794dd8c3c368f6ab95a0ba6cde277d0120000000000000000000000000000000000000000000000000000000000000000000000000"; Transaction transaction = this.networkTestNet.CreateTransaction(transactionHex); Block block = this.networkTestNet.Consensus.ConsensusFactory.CreateBlock(); block.AddTransaction(transaction); block.UpdateMerkleRoot(); // Act. var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, this.networkTestNet, dataFolder, this.signals); walletManager.Initialize(); walletManager.WatchAddress("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE"); walletManager.ProcessBlock(block); // Assert. WatchOnlyWallet returnedWallet = walletManager.GetWatchOnlyWallet(); Assert.NotNull(returnedWallet); WatchedAddress addressInWallet = returnedWallet.WatchedAddresses[newScript.ToString()]; Assert.NotNull(addressInWallet); Assert.False(addressInWallet.Transactions.IsEmpty); Assert.Single(addressInWallet.Transactions); WatchTransactionData transactionExpected = addressInWallet.Transactions.Single().Value; Assert.Equal(transactionHex, transactionExpected.Hex); Assert.NotNull(transactionExpected.BlockHash); Assert.NotNull(transactionExpected.MerkleProof); }