public void RunFullBlockTest() { var generator = new FullBlockTestGenerator(Network.Main); ValidationState validation = new ValidationState(Network.Main); validation.CheckMerkleRoot = false; validation.CheckProofOfWork = false; var scan = new ScanState(new PubKeyHashScanner(generator.CoinbaseKey.PubKey.ID), new Chain(), new Account(), 0); scan.CheckDoubleSpend = true; var mainChain = new Chain(Network.Main); var indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), CreateBlockStore()); indexed.Put(Network.Main.GetGenesis()); foreach (var test in generator.GetBlocksToTest(true, true).list.OfType <BlockAndValidity>()) { indexed.Put(test.block); mainChain.TrySetTip(test.block.Header); Assert.True(scan.Process(mainChain, indexed) == test.connects); //if(!) //{ // Assert.True(test.throwsException); //} Assert.Equal(test.heightAfterBlock, scan.Chain.Height); Assert.Equal(test.hashChainTipAfterBlock, scan.Chain.Tip.HashBlock); mainChain.SetTip(scan.Chain.Tip); } }
public void RunFullBlockTest() { var generator = new FullBlockTestGenerator(Network.Main); ValidationState validation = new ValidationState(Network.Main); validation.CheckMerkleRoot = false; validation.CheckProofOfWork = false; var scan = new ScanState(new PubKeyHashScanner(generator.CoinbaseKey.PubKey.ID), new Chain(), new Account(), 0); scan.CheckDoubleSpend = true; var mainChain = new Chain(Network.Main); var indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), CreateBlockStore()); indexed.Put(Network.Main.GetGenesis()); foreach(var test in generator.GetBlocksToTest(true, true).list.OfType<BlockAndValidity>()) { indexed.Put(test.block); mainChain.GetOrAdd(test.block.Header); Assert.True(scan.Process(mainChain, indexed) == test.connects); //if(!) //{ // Assert.True(test.throwsException); //} Assert.Equal(test.heightAfterBlock, scan.Chain.Height); Assert.Equal(test.hashChainTipAfterBlock, scan.Chain.Tip.HashBlock); mainChain.SetTip(scan.Chain.Tip); } }
public void GiveMoney(string amount, ScannerUser to, params Chain[] chains) { var tx = TestUtils.CreateFakeTx(amount, to.Id); var block = TestUtils.CreateFakeBlock(tx); if (chains != null) { foreach (var c in chains) { var localBlock = block.Clone(); localBlock.Header.HashPrevBlock = c.Tip.Header.GetHash(); c.TrySetTip(localBlock.Header); _Index.Put(localBlock); } } }
private Transaction RecieveTransaction(Transaction tx, Chain[] chains) { var block = TestUtils.CreateFakeBlock(tx); if (chains != null) { foreach (var c in chains) { var localBlock = block.Clone(); localBlock.Header.HashPrevBlock = c.Tip.Header.GetHash(); c.GetOrAdd(localBlock.Header); _Index.Put(localBlock); } } else { Wallet.UnconfirmedTransaction(tx); } return(tx); }
public ScannerTester(string folderName) { TestUtils.EnsureNew(folderName); _FolderName = folderName; string index = Path.Combine(folderName, "Index.dat"); _Index = new IndexedBlockStore(new SQLiteNoSqlRepository(index, true), new BlockStore(folderName, Network.TestNet)); var genesis = Network.TestNet.GetGenesis(); _Index.Put(genesis); }
public void CanIndexBlock() { IndexedBlockStore index = CreateIndexedStore(); foreach (StoredBlock block in StoredBlock.EnumerateFile(TestDataLocations.DataBlockFolder("blk0001.dat"), network:Network.StratisMain).Take(50)) { index.Put(block.Item); } Block genesis = index.Get(uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af")); Assert.NotNull(genesis); Block invalidBlock = index.Get(uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972ae")); Assert.Null(invalidBlock); }
public WalletTester([CallerMemberName] string name = null) { _Index = RepositoryTests.CreateIndexedStore(name); _Index.Put(Network.Main.GetGenesis()); }