public static IEnumerable <object[]> GetLocatorCases() { var fman = new MockFileManager() { expReadFN = "Headers", returnReadData = BlockHeaderTests.GetSampleBlockHeaderBytes(), blockInfo = new byte[32 + 4 + 4] }; var consensus = new MockConsensus(); var bver = new BlockVerifier(null, consensus); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(1), GetHeaders(1) }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(2), GetHeaders(2).Reverse() }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(10), GetHeaders(10).Reverse() }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(11), GetHeaders(11).Reverse() }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(12), GetHeaders(12).Reverse() }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(13), new BlockHeader[12] { new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(3, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(14), new BlockHeader[13] { new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(3, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(1, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(15), new BlockHeader[13] { new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(16), new BlockHeader[13] { new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(3, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(17), new BlockHeader[13] { new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(18), new BlockHeader[14] { new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(1, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), GetHeaders(19), new BlockHeader[14] { new BlockHeader(18, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); yield return(new object[] { GetChain(fman, bver, consensus), new BlockHeader[19] { new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(1, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(3, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(18, new byte[32], new byte[32], (uint)UnixTimeStamp.TimeToEpoch(DateTime.Now.Subtract(TimeSpan.FromHours(1))), 0, 0), }, new BlockHeader[14] { // Last block (18) is not included new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(1, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); uint yesterday = (uint)UnixTimeStamp.TimeToEpoch(DateTime.UtcNow.Subtract(TimeSpan.FromHours(25))); yield return(new object[] { GetChain(fman, bver, consensus), new BlockHeader[19] { new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(1, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(3, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(4, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(5, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(7, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(18, new byte[32], new byte[32], yesterday, 0, 0), }, new BlockHeader[14] { new BlockHeader(18, new byte[32], new byte[32], yesterday, 0, 0), new BlockHeader(17, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(16, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(15, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(14, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(13, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(12, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(11, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(10, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(9, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(8, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(6, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(2, new byte[32], new byte[32], 0, 0, 0), new BlockHeader(0, new byte[32], new byte[32], 0, 0, 0), } }); }
private static Autarkysoft.Bitcoin.Blockchain.Blockchain GetChain(IFileManager fman, BlockVerifier bver, IConsensus c) { // TODO: we can mock Time too return(new Autarkysoft.Bitcoin.Blockchain.Blockchain(fman, bver, c) { Time = new ClientTime() }); }