-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSZ encoding and hashing for Blob txs
- Loading branch information
Showing
45 changed files
with
1,204 additions
and
364 deletions.
There are no files selected for viewing
17 changes: 2 additions & 15 deletions
17
src/Nethermind/Nethermind.Cli/Console/ColorfulCliConsole.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
src/Nethermind/Nethermind.Core.Test/Builders/Build.Transaction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Nethermind.Core.Test.Builders | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Nethermind.Core.Eip2930; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Crypto; | ||
using Nethermind.Int256; | ||
using Nethermind.Logging; | ||
|
||
namespace Nethermind.Core.Test.Builders; | ||
|
||
public partial class Build | ||
{ | ||
public partial class Build | ||
{ | ||
public TransactionBuilder<Transaction> Transaction => new(); | ||
public TransactionBuilder<SystemTransaction> SystemTransaction => new(); | ||
public TransactionBuilder<GeneratedTransaction> GeneratedTransaction => new(); | ||
public TransactionBuilder<T> TypedTransaction<T>() where T : Transaction, new() => new(); | ||
public TransactionBuilder<Transaction> Transaction => new(); | ||
public TransactionBuilder<SystemTransaction> SystemTransaction => new(); | ||
public TransactionBuilder<GeneratedTransaction> GeneratedTransaction => new(); | ||
public TransactionBuilder<T> TypedTransaction<T>() where T : Transaction, new() => new(); | ||
|
||
public TransactionBuilder<NamedTransaction> NamedTransaction(string name) | ||
{ | ||
return new() { TestObjectInternal = { Name = name } }; | ||
} | ||
public TransactionBuilder<NamedTransaction> NamedTransaction(string name) | ||
{ | ||
return new() { TestObjectInternal = { Name = name } }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Nethermind/Nethermind.Core.Test/Encoding/ShardBlobTxDecoderTests.TestCases.cs
Large diffs are not rendered by default.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
src/Nethermind/Nethermind.Core.Test/Encoding/ShardBlobTxDecoderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Crypto; | ||
using Nethermind.Logging; | ||
using Nethermind.Serialization.Rlp; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Core.Test.Encoding; | ||
|
||
[TestFixture] | ||
public partial class ShardBlobTxDecoderTests | ||
{ | ||
private readonly TxDecoder _txDecoder = new(); | ||
|
||
public static IEnumerable<(Transaction, string)> TestCaseSource() => | ||
TxDecoderTests.TestObjectsSource().Select(tos => (tos.Item1 | ||
.WithChainId(TestBlockchainIds.ChainId) | ||
.WithShardBlobTxTypeAndFields(2, false) | ||
.SignedAndResolved() | ||
.TestObject, tos.Item2)); | ||
|
||
[TestCaseSource(nameof(TestCaseSource))] | ||
public void Roundtrip_ExecutionPayloadForm_for_shard_blobs((Transaction Tx, string Description) testCase) | ||
{ | ||
RlpStream rlpStream = new RlpStream(_txDecoder.GetLength(testCase.Tx)); | ||
_txDecoder.Encode(rlpStream, testCase.Tx); | ||
rlpStream.Position = 0; | ||
Transaction? decoded = _txDecoder.Decode(rlpStream); | ||
decoded!.SenderAddress = | ||
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded); | ||
decoded.Hash = decoded.CalculateHash(); | ||
decoded.Should().BeEquivalentTo(testCase.Tx, testCase.Description); | ||
} | ||
|
||
[TestCaseSource(nameof(TestCaseSource))] | ||
public void Roundtrip_ValueDecoderContext_ExecutionPayloadForm_for_shard_blobs((Transaction Tx, string Description) testCase) | ||
{ | ||
RlpStream rlpStream = new(10000); | ||
_txDecoder.Encode(rlpStream, testCase.Tx); | ||
|
||
Span<byte> spanIncomingTxRlp = rlpStream.Data.AsSpan(); | ||
Rlp.ValueDecoderContext decoderContext = new(spanIncomingTxRlp); | ||
rlpStream.Position = 0; | ||
Transaction? decoded = _txDecoder.Decode(ref decoderContext); | ||
decoded!.SenderAddress = | ||
new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance).RecoverAddress(decoded); | ||
decoded.Hash = decoded.CalculateHash(); | ||
decoded.Should().BeEquivalentTo(testCase.Tx, testCase.Description); | ||
} | ||
|
||
[TestCaseSource(nameof(ShardBlobTxTests))] | ||
public void NetworkWrapper_is_decoded_correctly(string rlp, Keccak signedHash, RlpBehaviors rlpBehaviors) | ||
{ | ||
RlpStream incomingTxRlp = Bytes.FromHexString(rlp).AsRlpStream(); | ||
byte[] spanIncomingTxRlp = Bytes.FromHexString(rlp); | ||
Rlp.ValueDecoderContext decoderContext = new(spanIncomingTxRlp.AsSpan()); | ||
|
||
Transaction? decoded = _txDecoder.Decode(incomingTxRlp, rlpBehaviors); | ||
Transaction? decodedByValueDecoderContext = _txDecoder.Decode(ref decoderContext, rlpBehaviors); | ||
|
||
Assert.That(decoded!.Hash, Is.EqualTo(signedHash)); | ||
Assert.That(decodedByValueDecoderContext!.Hash, Is.EqualTo(signedHash)); | ||
|
||
Rlp encoded = _txDecoder.Encode(decoded!, rlpBehaviors); | ||
Rlp encodedWithDecodedByValueDecoderContext = | ||
_txDecoder.Encode(decodedByValueDecoderContext!, rlpBehaviors); | ||
Assert.That(encoded.Bytes, Is.EquivalentTo(spanIncomingTxRlp)); | ||
Assert.That(encodedWithDecodedByValueDecoderContext.Bytes, Is.EquivalentTo(spanIncomingTxRlp)); | ||
} | ||
} |
Oops, something went wrong.