//UtxoManagerのテスト5 public static void Test16() { string basepath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); UtxoFileAccessDB ufadb = new UtxoFileAccessDB(basepath); string ufadbPath = ufadb.GetPath(); if (File.Exists(ufadbPath)) File.Delete(ufadbPath); UtxoFilePointersDB ufpdb = new UtxoFilePointersDB(basepath); string ufpdbPath = ufpdb.GetPath(); if (File.Exists(ufpdbPath)) File.Delete(ufpdbPath); UtxoFilePointersTempDB ufptempdb = new UtxoFilePointersTempDB(basepath); string ufptempdbPath = ufptempdb.GetPath(); if (File.Exists(ufptempdbPath)) File.Delete(ufptempdbPath); UtxoDB utxodb = new UtxoDB(basepath); string utxodbPath = utxodb.GetPath(); if (File.Exists(utxodbPath)) File.Delete(utxodbPath); UtxoManager utxom = new UtxoManager(ufadb, ufpdb, ufptempdb, utxodb); BlockGenerator bg = new BlockGenerator(); Block[] blks = new Block[100]; BlockContext[] blkCons = new BlockContext[blks.Length]; for (int i = 0; i < blks.Length; i++) { blkCons[i] = bg.CreateNextValidBlock(); blks[i] = blkCons[i].block; Console.WriteLine("block" + i.ToString() + " created."); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < blks.Length; i++) { utxodb.Open(); utxom.ApplyBlock(blks[i], blkCons[i].prevTxOutss); utxom.SaveUFPTemp(); utxodb.Close(); } stopwatch.Stop(); Console.WriteLine(string.Join(":", "test16_1", stopwatch.ElapsedMilliseconds.ToString() + "ms")); Console.WriteLine("test16_succeeded"); }
//UtxoManagerのテスト4 public static void Test15() { string basepath = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); UtxoFileAccessDB ufadb = new UtxoFileAccessDB(basepath); string ufadbPath = ufadb.GetPath(); if (File.Exists(ufadbPath)) File.Delete(ufadbPath); UtxoFilePointersDB ufpdb = new UtxoFilePointersDB(basepath); string ufpdbPath = ufpdb.GetPath(); if (File.Exists(ufpdbPath)) File.Delete(ufpdbPath); UtxoFilePointersTempDB ufptempdb = new UtxoFilePointersTempDB(basepath); string ufptempdbPath = ufptempdb.GetPath(); if (File.Exists(ufptempdbPath)) File.Delete(ufptempdbPath); UtxoDB utxodb = new UtxoDB(basepath); string utxodbPath = utxodb.GetPath(); if (File.Exists(utxodbPath)) File.Delete(utxodbPath); UtxoManager utxom = new UtxoManager(ufadb, ufpdb, ufptempdb, utxodb); BlockGenerator bg = new BlockGenerator(); Block[] blks = new Block[100]; BlockContext[] blkCons = new BlockContext[blks.Length]; for (int i = 0; i < blks.Length; i++) { blkCons[i] = bg.CreateNextValidBlock(); blks[i] = blkCons[i].block; Console.WriteLine("block" + i.ToString() + " created."); } for (int i = 0; i < blks.Length; i++) { utxodb.Open(); utxom.ApplyBlock(blks[i], blkCons[i].prevTxOutss); utxom.SaveUFPTemp(); utxodb.Close(); utxodb.Open(); foreach (var address in blkCons[i].unspentTxOuts.Keys) foreach (var toc in blkCons[i].unspentTxOuts[address]) if (utxom.FindUtxo(address, toc.bIndex, toc.txIndex, toc.txOutIndex) == null) throw new Exception("test15_1"); foreach (var address in blkCons[i].spentTxOuts.Keys) foreach (var toc in blkCons[i].spentTxOuts[address]) if (utxom.FindUtxo(address, toc.bIndex, toc.txIndex, toc.txOutIndex) != null) throw new Exception("test15_2"); utxodb.Close(); Console.WriteLine("block" + i.ToString() + " apply tested."); } for (int i = blks.Length - 1; i > 0; i--) { utxodb.Open(); utxom.RevertBlock(blks[i], blkCons[i].prevTxOutss); utxom.SaveUFPTemp(); utxodb.Close(); utxodb.Open(); foreach (var address in blkCons[i - 1].unspentTxOuts.Keys) foreach (var toc in blkCons[i - 1].unspentTxOuts[address]) if (utxom.FindUtxo(address, toc.bIndex, toc.txIndex, toc.txOutIndex) == null) throw new Exception("test15_3"); foreach (var address in blkCons[i - 1].spentTxOuts.Keys) foreach (var toc in blkCons[i - 1].spentTxOuts[address]) if (utxom.FindUtxo(address, toc.bIndex, toc.txIndex, toc.txOutIndex) != null) throw new Exception("test15_4"); utxodb.Close(); Console.WriteLine("block" + i.ToString() + " revert tested."); } Console.WriteLine("test15_succeeded"); }