예제 #1
0
        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;
            });
        }
예제 #2
0
        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);
        }
예제 #3
0
        private void BlocksStable()
        {
            var      apiInstance = new DefaultApi(nodeAddress);
            Progress p           = JsonConvert.DeserializeObject <Progress>(
                apiInstance.BlockchainProgress().ToString());

            var testCases = new[]
            {
                new
                {
                    name   = "multiple sequences",
                    golden = "blocks-3-5-7.golden",
                    start  = 0,
                    end    = 0,
                    seqs   = new List <int?> {
                        3, 5, 7
                    },
                    errCode = 200,
                    isRange = false,
                    errMsg  = ""
                },
                new
                {
                    name   = "block seq not found",
                    golden = "",
                    start  = 0,
                    end    = 0,
                    seqs   = new List <int?> {
                        3, 5, 7, 99999
                    },
                    errCode = 404,
                    isRange = false,
                    errMsg  = "Error calling Blocks: 404 Not Found - block does not exist seq=99999\n"
                },
                new
                {
                    name    = "first 10",
                    golden  = "blocks-first-10.golden",
                    start   = 1,
                    end     = 10,
                    seqs    = new List <int?>(),
                    errCode = 200,
                    isRange = true,
                    errMsg  = ""
                },
                new
                {
                    name    = "last 10",
                    golden  = "blocks-last-10.golden",
                    start   = p.Current - 10,
                    end     = p.Current,
                    seqs    = new List <int?>(),
                    errCode = 200,
                    isRange = true,
                    errMsg  = ""
                },
                new
                {
                    name    = "first block",
                    golden  = "blocks-first-1.golden",
                    start   = 1,
                    end     = 1,
                    seqs    = new List <int?>(),
                    errCode = 200,
                    isRange = true,
                    errMsg  = ""
                },
                new
                {
                    name    = "all blocks",
                    golden  = "blocks-all.golden",
                    start   = 0,
                    end     = p.Current,
                    seqs    = new List <int?>(),
                    errCode = 200,
                    isRange = true,
                    errMsg  = ""
                },
                new
                {
                    name    = "start > end",
                    golden  = "blocks-end-less-than-start.golden",
                    start   = 10,
                    end     = 9,
                    seqs    = new List <int?>(),
                    errCode = 200,
                    isRange = true,
                    errMsg  = ""
                }
            };

            foreach (var tc in testCases)
            {
                if (tc.errCode != 200)
                {
                    var err = Assert.Throws <ApiException>(() => apiInstance.Blocks(seqs: tc.seqs));
                    Assert.Equal(err.ErrorCode, tc.errCode);
                    Assert.Equal(err.Message, tc.errMsg);
                }
                else
                {
                    if (tc.isRange)
                    {
                        BlockInRangeTest(start: tc.start, end: tc.end);
                        var result = apiInstance.Blocks(start: tc.start, end: tc.end);
                        CheckGoldenFile(tc.golden, JsonConvert.SerializeObject(result, Formatting.Indented));
                    }
                    else
                    {
                        BlocksTest(tc.seqs);
                        var result = apiInstance.Blocks(seqs: tc.seqs);
                        CheckGoldenFile(tc.golden, JsonConvert.SerializeObject(result, Formatting.Indented));
                    }
                }
            }
        }