//[Trait("UnitTest", "UnitTest")]
		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);

		}
Пример #2
0
        //[Trait("UnitTest", "UnitTest")]
        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);
        }
Пример #3
0
        public void CheckBlockProofOfStake()
        {
            var totalblocks = 5000;              // fill only a small portion so test wont be too long
            var mainStore   = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main);

            // create the stores
            var store = CreateBlockStore();

            var index      = 0;
            var blockStore = new NoSqlBlockRepository();

            foreach (var storedBlock in mainStore.Enumerate(false).Take(totalblocks))
            {
                store.Append(storedBlock.Item);
                blockStore.PutAsync(storedBlock.Item);
                index++;
            }

            // build the chain
            var chain = store.GetChain();

            // fill the transaction store
            var trxStore = new NoSqlTransactionRepository();
            var mapStore = new BlockTransactionMapStore();

            foreach (var chainedBlock in chain.ToEnumerable(false).Take(totalblocks))
            {
                var block = blockStore.GetBlock(chainedBlock.HashBlock);
                foreach (var blockTransaction in block.Transactions)
                {
                    trxStore.Put(blockTransaction);
                    mapStore.PutAsync(blockTransaction.GetHash(), block.GetHash());
                }
            }

            RPCClient client = null;            // new RPCClient(new NetworkCredential("rpcuser", "rpcpassword"), new Uri("http://127.0.0.1:" + Network.Main.RPCPort), Network.Main);

            // validate the stake trasnaction
            foreach (var item in chain.ToEnumerable(false).Take(totalblocks).ToList())
            {
                var block = blockStore.GetBlock(item.HashBlock);
                Assert.True(BlockValidator.CheckAndComputeStake(blockStore, trxStore, mapStore, chain, item, block));

                if (item.Height == 1125)
                {
                    var g = block.ToHex();
                }

                if (client != null)
                {
                    var fetched = client.GetRPCBlock(item.HashBlock).Result;
                    Assert.Equal(uint256.Parse(fetched.modifierv2), item.Header.PosParameters.StakeModifierV2);
                    Assert.Equal(uint256.Parse(fetched.proofhash), item.Header.PosParameters.HashProof);
                }
            }
        }
Пример #4
0
        private void Test(int blockHeight, int txIndex, int txCount, int txOutIndex, int txOutCount)
        {
            var         repo       = new NoSqlBlockRepository();
            var         chain      = new MockChain();
            var         block      = new Block();
            Transaction relevantTx = null;

            for (int i = 0; i < txCount; i++)
            {
                var tx = block.AddTransaction(new Transaction());
                if (i == txIndex)
                {
                    relevantTx = tx;
                    for (int ii = 0; ii < txOutCount; ii++)
                    {
                        var txout = tx.AddOutput(new TxOut());
                        if (ii == txOutIndex)
                        {
                            txout.Value = Money.Coins(1.0m);
                        }
                    }
                }
            }
            block.UpdateMerkleRoot();
            chain.Return(block.Header, blockHeight);

            repo.PutAsync(block).Wait();


            var address  = MnemonicReference.CreateAsync(chain, repo, blockHeight, txIndex, txOutIndex).Result;
            var address2 = MnemonicReference.ParseAsync(chain, repo, Wordlist.English, address.ToString()).Result;

            Assert.Equal(address.ToString(), address2.ToString());
            Assert.Equal(Money.Coins(1.0m), address.Output.Value);
            Assert.Equal(Money.Coins(1.0m), address2.Output.Value);

            var merkleBlock = block.Filter(relevantTx.GetHash());
            var address3    = MnemonicReference.Parse(chain, Wordlist.English, address.ToString(), relevantTx, merkleBlock);

            Assert.Equal(address.ToString(), address3.ToString());
        }
		private void Test(int blockHeight, int txIndex, int txCount, int txOutIndex, int txOutCount)
		{
			var repo = new NoSqlBlockRepository();
			var chain = new MockChain();
			var block = new Block();
			Transaction relevantTx = null;

			for(int i = 0 ; i < txCount ; i++)
			{
				var tx = block.AddTransaction(new Transaction());
				if(i == txIndex)
				{
					relevantTx = tx;
					for(int ii = 0 ; ii < txOutCount ; ii++)
					{
						var txout = tx.AddOutput(new TxOut());
						if(ii == txOutIndex)
							txout.Value = Money.Coins(1.0m);
					}
				}
			}
			block.UpdateMerkleRoot();
			chain.Return(block.Header, blockHeight);

			repo.PutAsync(block).Wait();


			var address = MnemonicReference.CreateAsync(chain, repo, blockHeight, txIndex, txOutIndex).Result;
			var address2 = MnemonicReference.ParseAsync(chain, repo, Wordlist.English, address.ToString()).Result;
			Assert.Equal(address.ToString(), address2.ToString());
			Assert.Equal(Money.Coins(1.0m), address.Output.Value);
			Assert.Equal(Money.Coins(1.0m), address2.Output.Value);

			var merkleBlock = block.Filter(relevantTx.GetHash());
			var address3 = MnemonicReference.Parse(chain, Wordlist.English, address.ToString(), relevantTx, merkleBlock);
			Assert.Equal(address.ToString(), address3.ToString());
		}