<commit_before>using System;
using System.Collections.Generic;
using System.Numerics;
using Nethereum.Hex.HexConvertors.Extensions;
using Xunit;

namespace Nethereum.ABI.UnitTests
{
    public class DynamicArrayEncodingTests
    {
        [Fact]
        public virtual void ShouldDecodeDynamicIntArray()
        {
            //Given

            var given =
                "0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000003944700000000000000000000000000000000000000000000000000000000000394480000000000000000000000000000000000000000000000000000000000039449000000000000000000000000000000000000000000000000000000000003944a000000000000000000000000000000000000000000000000000000000003944b000000000000000000000000000000000000000000000000000000000003944c000000000000000000000000000000000000000000000000000000000003944d000000000000000000000000000000000000000000000000000000000003944e000000000000000000000000000000000000000000000000000000000003944f0000000000000000000000000000000000000000000000000000000000039450000000000000000000000000000000000000000000000000000000000003945100000000000000000000000000000000000000000000000000000000000394520000000000000000000000000000000000000000000000000000000000039453000000000000000000000000000000000000000000000000000000000003945400000000000000000000000000000000000000000000000000000000000394550000000000000000000000000000000000000000000000000000000000039456000000000000000000000000000000000000000000000000000000000003945700000000000000000000000000000000000000000000000000000000000394580000000000000000000000000000000000000000000000000000000000039459000000000000000000000000000000000000000000000000000000000003945a";

            var arrayType = ArrayType.CreateABIType("uint[]");

            //when
            var list = arrayType.Decode<List<BigInteger>>(given);

            //then


            if (list != null)
            {
                Assert.Equal(20, list.Count);

                for (var i = 0; i < list.Count; i++)
                    Assert.Equal(new BigInteger(i + 234567), list[i]);
            }
            else
            {
                throw new Exception("Expected to return IList object when decoding array");
            }
        }

        [Fact]
        public virtual void ShouldEncodeDynamicIntArray()
        {
            //Given
            var array = new uint[20];
            for (uint i = 0; i < 20; i++)
                array[i] = i + 234567;

            var listArray = new List<uint>(array);
<commit_msg>Add (failing) unit test for decoding too much<commit_after>using System;
using System.Collections.Generic;
using System.Numerics;
using Nethereum.Hex.HexConvertors.Extensions;
using Xunit;

namespace Nethereum.ABI.UnitTests
{
    public class DynamicArrayEncodingTests
    {
        [Fact]
        public virtual void ShouldDecodeDynamicIntArray()
        {
            //Given

            var given =
                "0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000003944700000000000000000000000000000000000000000000000000000000000394480000000000000000000000000000000000000000000000000000000000039449000000000000000000000000000000000000000000000000000000000003944a000000000000000000000000000000000000000000000000000000000003944b000000000000000000000000000000000000000000000000000000000003944c000000000000000000000000000000000000000000000000000000000003944d000000000000000000000000000000000000000000000000000000000003944e000000000000000000000000000000000000000000000000000000000003944f0000000000000000000000000000000000000000000000000000000000039450000000000000000000000000000000000000000000000000000000000003945100000000000000000000000000000000000000000000000000000000000394520000000000000000000000000000000000000000000000000000000000039453000000000000000000000000000000000000000000000000000000000003945400000000000000000000000000000000000000000000000000000000000394550000000000000000000000000000000000000000000000000000000000039456000000000000000000000000000000000000000000000000000000000003945700000000000000000000000000000000000000000000000000000000000394580000000000000000000000000000000000000000000000000000000000039459000000000000000000000000000000000000000000000000000000000003945a";

            var arrayType = ArrayType.CreateABIType("uint[]");

            //when
            var list = arrayType.Decode<List<BigInteger>>(given);

            //then


            if (list != null)
            {
                Assert.Equal(20, list.Count);

                for (var i = 0; i < list.Count; i++)
                    Assert.Equal(new BigInteger(i + 234567), list[i]);
            }
            else
            {
                throw new Exception("Expected to return IList object when decoding array");
            }
        }
        
        [Fact]
        public virtual void ShouldDecodeDynamicIntArrayOverread()
        {
            //Given

            // this covers an edge case where the array decoder would continue reading until all data was consumed
            // not until the given size was read
            var given =
                "0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000003944700000000000000000000000000000000000000000000000000000000000394480000000000000000000000000000000000000000000000000000000000039449000000000000000000000000000000000000000000000000000000000003944a000000000000000000000000000000000000000000000000000000000003944b000000000000000000000000000000000000000000000000000000000003944c000000000000000000000000000000000000000000000000000000000003944d000000000000000000000000000000000000000000000000000000000003944e000000000000000000000000000000000000000000000000000000000003944f0000000000000000000000000000000000000000000000000000000000039450000000000000000000000000000000000000000000000000000000000003945100000000000000000000000000000000000000000000000000000000000394520000000000000000000000000000000000000000000000000000000000039453000000000000000000000000000000000000000000000000000000000003945400000000000000000000000000000000000000000000000000000000000394550000000000000000000000000000000000000000000000000000000000039456000000000000000000000000000000000000000000000000000000000003945700000000000000000000000000000000000000000000000000000000000394580000000000000000000000000000000000000000000000000000000000039459000000000000000000000000000000000000000000000000000000000003945a000000000000000000000000000000000000000000000000000000000003945b000000000000000000000000000000000000000000000000000000000003945c";

            var arrayType = ArrayType.CreateABIType("uint[]");

            //when
            var list = arrayType.Decode<List<BigInteger>>(given);

            //then


            if (list != null)
            {
                Assert.Equal(20, list.Count);

                for (var i = 0; i < list.Count; i++)
                    Assert.Equal(new BigInteger(i + 234567), list[i]);
            }
            else
            {
                throw new Exception("Expected to return IList object when decoding array");
            }
        }
        [Fact]
        public virtual void ShouldEncodeDynamicIntArray()
        {
            //Given
            var array = new uint[20];
            for (uint i = 0; i < 20; i++)
                array[i] = i + 234567;

            var listArray = new List<uint>(array);

{'fraction_non_alphanumeric': 0.042422625400213444, 'fraction_numerical': 0.5584311632870864, 'mean_word_length': 4.385775862068965, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 65, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3017165', 'n_tokens_mistral': 5089, 'n_tokens_neox': 1242, 'n_words': 241}