private void BlockInRangeTest(int?start = null, int?end = null)
        {
            var apiInstance = new DefaultApi(nodeAddress);
            var result      = apiInstance.Blocks(start: start, end: end);

            if (start > end)
            {
                Assert.Empty(result.Blocks);
            }
            else
            {
                Assert.Equal(end - start + 1, result.Blocks.Count);
            }

            BlockSchema prevblock = null;

            result.Blocks.ForEach(b =>
            {
                if (prevblock != null)
                {
                    Assert.Equal(prevblock.Header.BlockHash, b.Header.PreviousBlockHash);
                }

                var bh = apiInstance.Block(hash: b.Header.BlockHash);
                Assert.Equal(result.Blocks.FindIndex(block => Equals(block, b)) + start, b.Header.Seq);
                Assert.NotNull(bh);
                Assert.Equal(bh.ToJson(), b.ToJson());
                prevblock = b;
            });
        }
        private void BlockLive()
        {
            var apiInstance = new DefaultApi(nodeAddress);

            BlockStable();
            var knownBadBlockSeqs = new int[]
            {
                // coinhour fee calculation mistake, related to distribution addresses:
                297,
                741,
                743,
                749,
                796,
                4956,
                10125,
                // coinhour overflow related:
                11685,
                11707,
                11710,
                11709,
                11705,
                11708,
                11711,
                11706,
                11699,
                13277
            };

            foreach (var seq in knownBadBlockSeqs)
            {
                var b = apiInstance.Block(seq: seq);
                Assert.Equal(seq, b.Header.Seq);
            }
        }
        private void BlocksTest(List <int?> seqs)
        {
            var apiInstance = new DefaultApi(nodeAddress);
            var result      = apiInstance.Blocks(seqs: seqs);

            Assert.Equal(seqs.Count, result.Blocks.Count);
            var seqsMap = new Dictionary <int?, BlockVerboseSchemaHeader>();

            seqs.ForEach(s => { seqsMap[s] = null; });
            result.Blocks.ForEach(b =>
            {
                Assert.True(seqsMap.ContainsKey(b.Header.Seq));
                seqsMap.Remove(b.Header.Seq);
                var bh = apiInstance.Block(b.Header.BlockHash);
                Assert.NotNull(bh);
                Assert.Equal(b.ToJson(), bh.ToJson());
            });
            Assert.Empty(seqsMap);
        }
        private void LastBlockLive()
        {
            var         apiInstance = new DefaultApi(nodeAddress);
            BlockSchema prevBlock   = null;
            var         results     = JsonConvert.DeserializeObject <InlineResponse2001>(apiInstance.LastBlocks(10).ToString());

            Assert.Equal(10, results.Blocks.Count);
            results.Blocks.ForEach(b =>
            {
                if (prevBlock != null)
                {
                    Assert.Equal(prevBlock.Header.BlockHash, b.Header.PreviousBlockHash);
                }

                var bh = apiInstance.Block(hash: b.Header.BlockHash);
                Assert.NotNull(bh);
                Assert.Equal(b.ToJson(), bh.ToJson());
                prevBlock = b;
            });
        }
        private void LastBlocksStable()
        {
            var apiInstance = new DefaultApi(nodeAddress);
            var result1     = JsonConvert.DeserializeObject <InlineResponse2001>(apiInstance.LastBlocks(1).ToString());

            CheckGoldenFile("block-last.golden", result1.ToJson());
            var result2 = JsonConvert.DeserializeObject <InlineResponse2001>(apiInstance.LastBlocks(10).ToString());

            Assert.Equal(10, result2.Blocks.Count);
            BlockSchema prevBlock = null;

            result2.Blocks.ForEach(block =>
            {
                if (prevBlock != null)
                {
                    Assert.NotEqual(prevBlock.Header.BlockHash, block.Header.BlockHash);
                }

                var bh = apiInstance.Block(hash: block.Header.BlockHash);
                Assert.NotNull(bh);
                Assert.Equal(block.ToJson(), bh.ToJson());
                prevBlock = block;
            });
        }
        private void BlockStable()
        {
            var apiInstance = new DefaultApi(nodeAddress);
            var testCases   = new[]
            {
                new
                {
                    name    = "unknown hash",
                    golden  = "",
                    hash    = "80744ec25e6233f40074d35bf0bfdbddfac777869b954a96833cb89f44204444",
                    seq     = -1,
                    errCode = 404,
                    errMsg  = "Error calling Block: 404 Not Found\n"
                },
                new
                {
                    name    = "valid hash",
                    golden  = "block-hash.golden",
                    hash    = "70584db7fb8ab88b8dbcfed72ddc42a1aeb8c4882266dbb78439ba3efcd0458d",
                    seq     = -1,
                    errCode = 200,
                    errMsg  = ""
                },
                new
                {
                    name    = "genesis hash",
                    golden  = "block-hash-genesis.golden",
                    hash    = "0551a1e5af999fe8fff529f6f2ab341e1e33db95135eef1b2be44fe6981349f3",
                    seq     = -1,
                    errCode = 200,
                    errMsg  = ""
                },
                new
                {
                    name    = "genesis seq",
                    golden  = "block-seq-0.golden",
                    hash    = "",
                    seq     = 0,
                    errCode = 200,
                    errMsg  = ""
                },
                new
                {
                    name    = "seq 1",
                    golden  = "block-seq-1.golden",
                    hash    = "",
                    seq     = 1,
                    errCode = 200,
                    errMsg  = ""
                },
                new
                {
                    name    = "seq 100",
                    golden  = "block-seq-100.golden",
                    hash    = "",
                    seq     = 100,
                    errCode = 200,
                    errMsg  = ""
                },
                new
                {
                    name    = "unknown seq",
                    golden  = "",
                    hash    = "",
                    seq     = 999999999,
                    errCode = 404,
                    errMsg  = "Error calling Block: 404 Not Found\n"
                }
            };

            foreach (var tc in testCases)
            {
                if (tc.errCode != 200)
                {
                    var err = Assert.Throws <ApiException>(() =>
                    {
                        if (tc.seq >= 0)
                        {
                            apiInstance.Block(seq: tc.seq);
                        }
                        else
                        {
                            apiInstance.Block(hash: tc.hash);
                        }
                    });
                    Assert.Equal(err.ErrorCode, tc.errCode);
                    Assert.Equal(err.Message, tc.errMsg);
                }
                else
                {
                    if (tc.seq >= 0)
                    {
                        var result = apiInstance.Block(seq: tc.seq);
                        CheckGoldenFile(tc.golden, result);
                    }
                    else
                    {
                        var result = apiInstance.Block(hash: tc.hash);
                        CheckGoldenFile(tc.golden, result);
                    }
                }
            }
        }