Exemplo n.º 1
0
 public virtual void ShouldDecodeNegativeByteArray()
 {
     IntType intType = new IntType("int");
     var bytes = intType.Encode(-100000569);
     var result = intType.Decode<BigInteger>(bytes);
     Assert.Equal(new BigInteger(-100000569), result);
 }
Exemplo n.º 2
0
 public virtual void ShouldEncodeUInt()
 {
     IntType intType = new IntType("uint");
     uint given = 1234567;
     var result = intType.Encode(given).ToHex();
     Assert.Equal("000000000000000000000000000000000000000000000000000000000012d687", result);
 }
Exemplo n.º 3
0
        public virtual void ShouldEncodeDecodeInt()
        {
            var intType   = new IntType("int");
            var result    = intType.Encode(int.MaxValue).ToHex();
            var intresult = intType.Decode <int>(result);

            Assert.Equal(int.MaxValue, intresult);
        }
Exemplo n.º 4
0
        public virtual void ShouldEncodeDecodeSByte()
        {
            var intType   = new IntType("int8");
            var result    = intType.Encode(sbyte.MaxValue).ToHex();
            var intresult = intType.Decode <sbyte>(result);

            Assert.Equal(sbyte.MaxValue, intresult);
        }
Exemplo n.º 5
0
        public virtual void ShouldThrowErrorWhenEncodingExceedingIntMaxValue()
        {
            var intType = new IntType("int");
            var given   = IntType.MAX_INT256_VALUE + 1;
            var ex      = Assert.Throws <ArgumentOutOfRangeException>("value", () => intType.Encode(given));

            Assert.StartsWith("Signed SmartContract integer must not exceed maximum value for int256", ex.Message);
        }
Exemplo n.º 6
0
        public virtual void ShouldEncodeDecodeUInt64()
        {
            var intType   = new IntType("uint64");
            var result    = intType.Encode(ulong.MaxValue).ToHex();
            var intresult = intType.Decode <ulong>(result);

            Assert.Equal(ulong.MaxValue, intresult);
        }
Exemplo n.º 7
0
        public virtual void ShouldEncodeDecodeUShort()
        {
            var intType   = new IntType("uint16");
            var result    = intType.Encode(ushort.MaxValue).ToHex();
            var intresult = intType.Decode <ushort>(result);

            Assert.Equal(ushort.MaxValue, intresult);
        }
Exemplo n.º 8
0
        public virtual void ShouldEncodeUInt()
        {
            var  intType = new IntType("uint");
            uint given   = 1234567;
            var  result  = intType.Encode(given).ToHex();

            Assert.Equal("000000000000000000000000000000000000000000000000000000000012d687", result);
        }
Exemplo n.º 9
0
        public virtual void ShouldDecodeNegativeByteArray()
        {
            var intType = new IntType("int");
            var bytes   = intType.Encode(-100000569);
            var result  = intType.Decode <BigInteger>(bytes);

            Assert.Equal(new BigInteger(-100000569), result);
        }
Exemplo n.º 10
0
        public virtual void ShouldThrowErrorWhenEncodingIsLessThanIntMinValue()
        {
            var intType = new IntType("int");
            var given   = IntType.MIN_INT256_VALUE - 1;
            var ex      = Assert.Throws <ArgumentOutOfRangeException>("value", () => intType.Encode(given));

            Assert.StartsWith($"Signed SmartContract integer must not be less than the minimum value for int256", ex.Message);
        }
        public virtual void ShouldEncodeDecodeEnum()
        {
            var intType    = new IntType("int");
            var result1    = intType.Encode(TestEnum.Monkey).ToHex();
            var decresult1 = intType.Decode <TestEnum>(result1);

            Assert.Equal(TestEnum.Monkey, decresult1);

            var result2    = intType.Encode(TestEnum.Elephant).ToHex();
            var decresult2 = intType.Decode <TestEnum>(result2);

            Assert.Equal(TestEnum.Elephant, decresult2);

            var result3    = intType.Encode(TestEnum.Lion).ToHex();
            var decresult3 = intType.Decode <TestEnum>(result3);

            Assert.Equal(TestEnum.Lion, decresult3);
        }
Exemplo n.º 12
0
        public virtual void ShouldThrowErrorWhenValueIsNull()
        {
            var    intType = new IntType("int");
            object given   = null;
            var    ex      = Assert.Throws <Exception>(() => intType.Encode(given));

            Assert.Equal("Invalid value for type 'Nethereum.ABI.Encoders.IntTypeEncoder'. Value: null, ValueType: ()",
                         ex.Message);
        }
Exemplo n.º 13
0
 public virtual void ShouldEncodeInt()
 {
     IntType intType = new IntType("int");
     var result = intType.Encode(69).ToHex();
     Assert.Equal("0000000000000000000000000000000000000000000000000000000000000045", result);
 }
Exemplo n.º 14
0
 public virtual void ShouldEncodeNegativeInt()
 {
     IntType intType = new IntType("int");
     var result = intType.Encode(-1234567).ToHex();
     Assert.Equal("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed2979", result);
 }
Exemplo n.º 15
0
 public virtual void ShouldEncodeStrings()
 {
     IntType intType = new IntType("int");
     var result2 = intType.Encode("1234567890abcdef1234567890abcdef12345678").ToHex();
     Assert.Equal("0000000000000000000000001234567890abcdef1234567890abcdef12345678", result2);
 }
Exemplo n.º 16
0
        public virtual void ShouldEncode(string value, string hexExpected)
        {
            IntType intType = new IntType("int");
            var result = intType.Encode(BigInteger.Parse(value));
            Assert.Equal(hexExpected, "0x" + result.ToHex());

        }
Exemplo n.º 17
0
        public virtual void ShouldThrowErrorWhileEncodeLargeInt()
        {
            const int maxIntSizeInBytes = 32;
            var       intType           = new IntType("uint");
            var       given             = new BigInteger(Enumerable.Range(1, maxIntSizeInBytes + 1).Select(x => (byte)x).ToArray());
            var       ex = Assert.Throws <ArgumentOutOfRangeException>("value", () => intType.Encode(given));

            Assert.StartsWith($"Integer value must not exceed maximum Solidity size of {maxIntSizeInBytes} bytes", ex.Message);
        }