Skip to content

Commit

Permalink
Merge branch 'master' into eip_152
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz committed Aug 27, 2019
2 parents 088dd82 + e71a934 commit 447f1ae
Show file tree
Hide file tree
Showing 270 changed files with 10,736 additions and 1,749 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ jobs:
dotnet test src/Nethermind/Nethermind.Abi.Test;
fi
name: "Nethermind.Abi.Test"
- script:
- git -c submodule."src/tests".update=none submodule update --init
- if [ $TRAVIS_PULL_REQUEST != false ] || [ $TRAVIS_BRANCH == "master" ]; then
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[Nethermind.HashLib]*%2c[Nethermind.Core.Test]*%2c[Nethermind.Blockchain.Test]*" src/Nethermind/Nethermind.AuRa.Test;
else
dotnet test src/Nethermind/Nethermind.AuRa.Test;
fi
name: "Nethermind.AuRa.Test"
- script:
- git -c submodule."src/tests".update=none submodule update --init
- if [ $TRAVIS_PULL_REQUEST != false ] || [ $TRAVIS_BRANCH == "master" ]; then
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[Nethermind.HashLib]*%2c[Nethermind.Core.Test]*" src/Nethermind/Nethermind.Blockchain.Test;
else
dotnet test src/Nethermind/Nethermind.Blockchain.Test;
fi
name: "Nethermind.Blockchain.Test"
name: "Nethermind.Blockchain.Test"
- script:
- git -c submodule."src/tests".update=none submodule update --init
- if [ $TRAVIS_PULL_REQUEST != false ] || [ $TRAVIS_BRANCH == "master" ]; then
Expand Down
130 changes: 130 additions & 0 deletions src/Nethermind/Chains/poacore.json

Large diffs are not rendered by default.

135 changes: 135 additions & 0 deletions src/Nethermind/Chains/sokol.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Basic.Test/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static TransactionTest Convert(TransactionTestJson testJson)
}

test.Unsigned = new Rlp(unsigned.Slice(0, unsigned.Length - 3));
test.StartGas = (UInt256)testJson.StartGas;
test.StartGas = testJson.StartGas;
test.To = string.IsNullOrEmpty(testJson.To) ? null : new Address(testJson.To);
return test;
}
Expand All @@ -127,7 +127,7 @@ public class TransactionTest
public PrivateKey PrivateKey { get; set; }
public UInt256 Nonce { get; set; }
public UInt256 GasPrice { get; set; }
public UInt256 StartGas { get; set; }
public long StartGas { get; set; }
public Address To { get; set; }
public UInt256 Value { get; set; }
public byte[] Data { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Threading.Tasks;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Receipts;
using Nethermind.Blockchain.Rewards;
using Nethermind.Blockchain.TxPools;
using Nethermind.Blockchain.TxPools.Storages;
using Nethermind.Blockchain.Validators;
Expand Down Expand Up @@ -579,7 +580,7 @@ private static Transaction Convert(TransactionJson transactionJson)
{
Transaction transaction = new Transaction();
transaction.Value = Bytes.FromHexString(transactionJson.Value).ToUInt256();
transaction.GasLimit = Bytes.FromHexString(transactionJson.GasLimit).ToUInt256();
transaction.GasLimit = Bytes.FromHexString(transactionJson.GasLimit).ToInt64();
transaction.GasPrice = Bytes.FromHexString(transactionJson.GasPrice).ToUInt256();
transaction.Nonce = Bytes.FromHexString(transactionJson.Nonce).ToUInt256();
transaction.To = string.IsNullOrWhiteSpace(transactionJson.To) ? null : new Address(transactionJson.To);
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Ethereum.VM.Test/AbiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class AbiTests
{
private static readonly Dictionary<string, AbiType> TypesByName = new Dictionary<string, AbiType>
{
{"uint256", AbiType.UInt},
{"uint256", AbiType.UInt256},
{"uint32[]", new AbiArray(new AbiUInt(32))},
{"bytes10", new AbiBytes(10)},
{"bytes", AbiType.DynamicBytes},
Expand Down
50 changes: 50 additions & 0 deletions src/Nethermind/Nethermind.Abi.Test/AbiEncoderExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018 Demerzel Solutions Limited
* This file is part of the Nethermind library.
*
* The Nethermind library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Nethermind library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

using NSubstitute;
using NUnit.Framework;

namespace Nethermind.Abi.Test
{
public class AbiEncoderExtensionsTests
{
[Test]
public void Encode_should_be_called()
{
var abi = Substitute.For<IAbiEncoder>();
var parameters = new object[] {"p1"};
var abiSignature = new AbiSignature("test", AbiType.String);
var abiEncodingStyle = AbiEncodingStyle.Packed;

abi.Encode(new AbiEncodingInfo(abiEncodingStyle, abiSignature), parameters);
abi.Received().Encode(abiEncodingStyle, abiSignature, parameters);
}

[Test]
public void Dencode_should_be_called()
{
var abi = Substitute.For<IAbiEncoder>();
var data = new byte[] {100, 200};
var abiSignature = new AbiSignature("test", AbiType.String);
var abiEncodingStyle = AbiEncodingStyle.Packed;

abi.Decode(new AbiEncodingInfo(abiEncodingStyle, abiSignature), data);
abi.Received().Decode(abiEncodingStyle, abiSignature, data);
}
}
}
16 changes: 8 additions & 8 deletions src/Nethermind/Nethermind.Abi.Test/AbiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AbiTests
[TestCase(AbiEncodingStyle.None)]
public void Dynamic_array_of_dynamic_array_of_uint(AbiEncodingStyle encodingStyle)
{
AbiType type = new AbiArray(new AbiArray(AbiType.UInt));
AbiType type = new AbiArray(new AbiArray(AbiType.UInt256));
AbiSignature signature = new AbiSignature("abc", type);
BigInteger[] element = {1, 2, 3};
BigInteger[][] data = {element, element};
Expand All @@ -53,7 +53,7 @@ public void Dynamic_array_of_dynamic_array_of_uint(AbiEncodingStyle encodingStyl
[TestCase(AbiEncodingStyle.None)]
public void Dynamic_array_of_dynamic_array_of_uint_empty(AbiEncodingStyle encodingStyle)
{
AbiType type = new AbiArray(new AbiArray(AbiType.UInt));
AbiType type = new AbiArray(new AbiArray(AbiType.UInt256));
AbiSignature signature = new AbiSignature("abc", type);
BigInteger[] data = { };
byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, data);
Expand Down Expand Up @@ -81,7 +81,7 @@ public void Dynamic_array_of_string(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Dynamic_array_of_uint(AbiEncodingStyle encodingStyle)
{
AbiType type = new AbiArray(AbiType.UInt);
AbiType type = new AbiArray(AbiType.UInt256);
AbiSignature signature = new AbiSignature("abc", type);
BigInteger[] data = {1, 2, 3};
byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, data);
Expand All @@ -95,7 +95,7 @@ public void Dynamic_array_of_uint(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Fixed_array_of_fixed_array_of_uint(AbiEncodingStyle encodingStyle)
{
AbiType type = new AbiFixedLengthArray(new AbiFixedLengthArray(AbiType.UInt, 2), 3);
AbiType type = new AbiFixedLengthArray(new AbiFixedLengthArray(AbiType.UInt256, 2), 3);
BigInteger[] element = {1, 1};
BigInteger[][] data = {element, element, element};
AbiSignature signature = new AbiSignature("abc", type);
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Fixed_array_of_string(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Fixed_array_of_uint(AbiEncodingStyle encodingStyle)
{
AbiType type = new AbiFixedLengthArray(AbiType.UInt, 2);
AbiType type = new AbiFixedLengthArray(AbiType.UInt256, 2);
BigInteger[] data = {1, 1};
AbiSignature signature = new AbiSignature("abc", type);
byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, data);
Expand Down Expand Up @@ -233,7 +233,7 @@ public void Test_single_function(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Test_single_int(AbiEncodingStyle encodingStyle)
{
AbiType type = AbiType.Int;
AbiType type = AbiType.Int256;
AbiSignature signature = new AbiSignature("abc", type);
byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, BigInteger.MinusOne);
object[] arguments = _abiEncoder.Decode(encodingStyle, signature, encoded);
Expand All @@ -246,7 +246,7 @@ public void Test_single_int(AbiEncodingStyle encodingStyle)
[TestCase(AbiEncodingStyle.None)]
public void Test_single_uint(AbiEncodingStyle encodingStyle)
{
AbiType type = AbiType.UInt;
AbiType type = AbiType.UInt256;
AbiSignature signature = new AbiSignature("abc", type);
byte[] encoded = _abiEncoder.Encode(encodingStyle, signature, BigInteger.Zero);
object[] arguments = _abiEncoder.Decode(encodingStyle, signature, encoded);
Expand Down Expand Up @@ -354,7 +354,7 @@ public void Tutorial_test()

AbiSignature signature = new AbiSignature(
"f",
AbiType.UInt,
AbiType.UInt256,
new AbiArray(new AbiUInt(32)),
new AbiBytes(10),
AbiType.DynamicBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="NSubstitute" Version="4.0.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/Nethermind/Nethermind.Abi/AbiAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using Nethermind.Core;
using Nethermind.Core.Extensions;

Expand All @@ -40,7 +41,7 @@ public override byte[] Encode(object arg, bool packed)
case Address input:
{
byte[] bytes = input.Bytes;
return packed ? bytes : bytes.PadLeft(UInt.LengthInBytes);
return packed ? bytes : bytes.PadLeft(UInt256.LengthInBytes);
}
case string stringInput:
{
Expand All @@ -55,9 +56,11 @@ public override byte[] Encode(object arg, bool packed)
}
}

public override Type CSharpType { get; } = typeof(Address);

public override (object, int) Decode(byte[] data, int position, bool packed)
{
return (new Address(data.Slice(position + (packed ? 0 : 12), Address.LengthInBytes)), position + (packed ? Address.LengthInBytes : UInt.LengthInBytes));
return (new Address(data.Slice(position + (packed ? 0 : 12), Address.LengthInBytes)), position + (packed ? Address.LengthInBytes : UInt256.LengthInBytes));
}
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Abi/AbiArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AbiArray(AbiType elementType)
public override (object, int) Decode(byte[] data, int position, bool packed)
{
BigInteger length;
(length, position) = UInt.DecodeUInt(data, position, packed);
(length, position) = UInt256.DecodeUInt(data, position, packed);

Array result = Array.CreateInstance(_elementType.CSharpType, (int)length);
for (int i = 0; i < length; i++)
Expand All @@ -61,7 +61,7 @@ public override byte[] Encode(object arg, bool packed)
{
byte[][] encodedItems = new byte[input.Length + 1][];
int i = 0;
encodedItems[i++] = UInt.Encode((BigInteger)input.Length, packed);
encodedItems[i++] = UInt256.Encode((BigInteger)input.Length, packed);
foreach (object o in input)
{
encodedItems[i++] = _elementType.Encode(o, packed);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Abi/AbiDynamicBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private AbiDynamicBytes()

public override (object, int) Decode(byte[] data, int position, bool packed)
{
(BigInteger length, int currentPosition) = UInt.DecodeUInt(data, position, packed);
(BigInteger length, int currentPosition) = UInt256.DecodeUInt(data, position, packed);
int paddingSize = packed ? (int)length : (1 + (int) length / PaddingMultiple) * PaddingMultiple;
return (data.Slice(currentPosition, (int) length), currentPosition + paddingSize);
}
Expand All @@ -51,7 +51,7 @@ public override byte[] Encode(object arg, bool packed)
if (arg is byte[] input)
{
int paddingSize = (1 + input.Length / PaddingMultiple) * PaddingMultiple;
byte[] lengthEncoded = UInt.Encode(new BigInteger(input.Length), packed);
byte[] lengthEncoded = UInt256.Encode(new BigInteger(input.Length), packed);
return Bytes.Concat(lengthEncoded, packed ? input : input.PadRight(paddingSize));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Abi/AbiEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public byte[] Encode(AbiEncodingStyle encodingStyle, AbiSignature signature, par

List<byte[]> dynamicParts = new List<byte[]>();
List<byte[]> headerParts = new List<byte[]>();
BigInteger currentOffset = arguments.Length * AbiType.UInt.LengthInBytes;
BigInteger currentOffset = arguments.Length * AbiType.UInt256.LengthInBytes;
for (int i = 0; i < arguments.Length; i++)
{
AbiType type = signature.Types[i];
if (type.IsDynamic)
{
headerParts.Add(AbiType.UInt.Encode(currentOffset, packed));
headerParts.Add(AbiType.UInt256.Encode(currentOffset, packed));
byte[] encoded = type.Encode(arguments[i], packed);
currentOffset += encoded.Length;
dynamicParts.Add(encoded);
Expand Down Expand Up @@ -138,7 +138,7 @@ public object[] Decode(AbiEncodingStyle encodingStyle, AbiSignature signature, b
if (type.IsDynamic)
{
// TODO: do not have to decode this - can just jump 32 and check if first call and use dynamic position
(BigInteger offset, int nextPosition) = AbiType.UInt.DecodeUInt(data, position, packed);
(BigInteger offset, int nextPosition) = AbiType.UInt256.DecodeUInt(data, position, packed);
(arguments[i], dynamicPosition) = type.Decode(data, sigOffset + (int)offset, packed);
position = nextPosition;
}
Expand Down
29 changes: 29 additions & 0 deletions src/Nethermind/Nethermind.Abi/AbiEncoderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2018 Demerzel Solutions Limited
* This file is part of the Nethermind library.
*
* The Nethermind library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Nethermind library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Nethermind.Abi
{
public static class AbiEncoderExtensions
{
public static byte[] Encode(this IAbiEncoder encoder, AbiEncodingInfo abiEncodingInfo, params object[] arguments)
=> encoder.Encode(abiEncodingInfo.EncodingStyle, abiEncodingInfo.Signature, arguments);

public static object[] Decode(this IAbiEncoder encoder, AbiEncodingInfo abiEncodingInfo, byte[] data)
=> encoder.Decode(abiEncodingInfo.EncodingStyle, abiEncodingInfo.Signature, data);
}
}
32 changes: 32 additions & 0 deletions src/Nethermind/Nethermind.Abi/AbiEncodingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2018 Demerzel Solutions Limited
* This file is part of the Nethermind library.
*
* The Nethermind library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Nethermind library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Nethermind.Abi
{
public class AbiEncodingInfo
{
public AbiEncodingStyle EncodingStyle { get; }
public AbiSignature Signature { get; }

public AbiEncodingInfo(AbiEncodingStyle encodingStyle, AbiSignature signature)
{
EncodingStyle = encodingStyle;
Signature = signature;
}
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Abi/AbiFixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AbiFixed(int length, int precision)

public override (object, int) Decode(byte[] data, int position, bool packed)
{
(BigInteger nominator, int newPosition) = Int.DecodeInt(data, position, packed);
(BigInteger nominator, int newPosition) = Int256.DecodeInt(data, position, packed);
BigRational rational = BigRational.FromBigInt(nominator) * BigRational.Reciprocal(BigRational.Pow(BigRational.FromInt(10), Precision));
return (rational, newPosition);
}
Expand All @@ -93,7 +93,7 @@ public override byte[] Encode(object arg, bool packed)
throw new AbiException(AbiEncodingExceptionMessage);
}

return UInt.Encode(input.Numerator, packed);
return UInt256.Encode(input.Numerator, packed);
}

throw new AbiException(AbiEncodingExceptionMessage);
Expand Down
Loading

0 comments on commit 447f1ae

Please sign in to comment.