<commit_before>﻿using NBitcoin.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace NBitcoin.Tests
{
	public class MnemonicReference_tests
	{
		[Fact]
		public void CanCreateBrainAddress()
		{
			var repo = new NoSqlBlockRepository();
			var chain = new ConcurrentChain();

			Block b = new Block();
			b.Transactions.Add(new Transaction());
			b.Transactions.Add(new Transaction()
			{
				Outputs =
				{
					new TxOut(),
					new TxOut(Money.Zero,BitcoinAddress.Create("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe"))
				}
			});
			b.UpdateMerkleRoot();
			repo.PutAsync(b).Wait();
			chain.SetTip(b.Header);


			MnemonicReference address = MnemonicReference.CreateAsync(chain, repo, 0, 1, 1).Result;
			MnemonicReference address2 = MnemonicReference.ParseAsync(chain, repo, Wordlist.English, address.ToString(Wordlist.English)).Result;
			Assert.Equal(address.ToString(), address2.ToString());


			chain = new ConcurrentChain(Network.Main);
			var block = Network.Main.GetGenesis();
			var mnemo = MnemonicReference.Create(chain, block.Transactions[0], block, 0);

		}
		[Fact]
		public void CanCreateBrainAddressFromNetwork()
		{
			using(var node = Node.ConnectToLocal(Network.Main))
			{
				node.VersionHandshake();
				using(var listener = node.CreateListener())
				{
					node.SendMessage(new GetDataPayload(new InventoryVector(InventoryType.MSG_BLOCK, new uint256(" 00000000000000001790ced14940f5dc4a61cec2547b78f6dbfc1ebcbf1192d9 "))));
					var payload = listener.ReceivePayload<BlockPayload>();
					var block= payload.Object;
					var tx = block.Transactions.First(t => t.GetHash() == new uint256("4a85f6cc29aca334c1a78c5db74b492b741e67958aee59ff827c4c0862f4fbc1"));

					var chain = node.GetChain();
					var result = MnemonicReference.Create(chain, tx, block, 1);
				}
			}
		}
		[Fact]
		public void CanCreateBrainAddress2()
		{
			Test(1782, 123, 1000, 1, 2);
		}

		class MockChain : ChainBase
		{
			public void Return(BlockHeader header, int height)
			{
				_Return = new ChainedBlock(header, height);
			}
			ChainedBlock _Return;
			public override ChainedBlock GetBlock(uint256 id)
			{
				return _Return;
			}

			public override ChainedBlock GetBlock(int height)
			{
				return _Return;
			}

			public override ChainedBlock Tip
			{
				get
				{
					throw new NotImplementedException();
				}<commit_msg>fix test project portable compile<commit_after>﻿using NBitcoin.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace NBitcoin.Tests
{
	public class MnemonicReference_tests
	{
		[Fact]
		public void CanCreateBrainAddress()
		{
			var repo = new NoSqlBlockRepository();
			var chain = new ConcurrentChain();

			Block b = new Block();
			b.Transactions.Add(new Transaction());
			b.Transactions.Add(new Transaction()
			{
				Outputs =
				{
					new TxOut(),
					new TxOut(Money.Zero,BitcoinAddress.Create("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe"))
				}
			});
			b.UpdateMerkleRoot();
			repo.PutAsync(b).Wait();
			chain.SetTip(b.Header);


			MnemonicReference address = MnemonicReference.CreateAsync(chain, repo, 0, 1, 1).Result;
			MnemonicReference address2 = MnemonicReference.ParseAsync(chain, repo, Wordlist.English, address.ToString(Wordlist.English)).Result;
			Assert.Equal(address.ToString(), address2.ToString());


			chain = new ConcurrentChain(Network.Main);
			var block = Network.Main.GetGenesis();
			var mnemo = MnemonicReference.Create(chain, block.Transactions[0], block, 0);

		}

#if !NOSOCKET
		[Fact]
		public void CanCreateBrainAddressFromNetwork()
		{
			using(var node = Node.ConnectToLocal(Network.Main))
			{
				node.VersionHandshake();
				using(var listener = node.CreateListener())
				{
					node.SendMessage(new GetDataPayload(new InventoryVector(InventoryType.MSG_BLOCK, new uint256(" 00000000000000001790ced14940f5dc4a61cec2547b78f6dbfc1ebcbf1192d9 "))));
					var payload = listener.ReceivePayload<BlockPayload>();
					var block = payload.Object;
					var tx = block.Transactions.First(t => t.GetHash() == new uint256("4a85f6cc29aca334c1a78c5db74b492b741e67958aee59ff827c4c0862f4fbc1"));

					var chain = node.GetChain();
					var result = MnemonicReference.Create(chain, tx, block, 1);
				}
			}
		}
#endif
		[Fact]
		public void CanCreateBrainAddress2()
		{
			Test(1782, 123, 1000, 1, 2);
		}

		class MockChain : ChainBase
		{
			public void Return(BlockHeader header, int height)
			{
				_Return = new ChainedBlock(header, height);
			}
			ChainedBlock _Return;
			public override ChainedBlock GetBlock(uint256 id)
			{
				return _Return;
			}

			public override ChainedBlock GetBlock(int height)
			{
				return _Return;
			}

			public override ChainedBlock Tip
			{
				get
				{
					throw new NotImplementedException();
				}
{'fraction_non_alphanumeric': 0.10902791929896066, 'fraction_numerical': 0.04687181577338496, 'mean_word_length': 4.0184049079754605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3093420', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1630, 'n_words': 323}