-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Nethermind as Optimism Sequencer (#7287)
- Loading branch information
1 parent
ba3045d
commit 1605dd7
Showing
6 changed files
with
121 additions
and
21 deletions.
There are no files selected for viewing
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
90 changes: 90 additions & 0 deletions
90
src/Nethermind/Nethermind.Optimism.Test/Rpc/OptimismEthRpcModuleTest.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,90 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Threading.Tasks; | ||
using Nethermind.Blockchain.Synchronization; | ||
using Nethermind.Config; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Crypto; | ||
using Nethermind.Facade; | ||
using Nethermind.Facade.Eth; | ||
using Nethermind.JsonRpc.Client; | ||
using Nethermind.JsonRpc.Modules.Eth.FeeHistory; | ||
using Nethermind.JsonRpc.Test.Modules; | ||
using Nethermind.Logging; | ||
using Nethermind.Optimism.Rpc; | ||
using Nethermind.Serialization.Rlp; | ||
using Nethermind.Synchronization.ParallelSync; | ||
using Nethermind.TxPool; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Optimism.Test.Rpc; | ||
|
||
public class OptimismEthRpcModuleTest | ||
{ | ||
[Test] | ||
public async Task Sequencer_send_transaction_with_signature_will_not_try_to_sign() | ||
{ | ||
IBlockchainBridge bridge = Substitute.For<IBlockchainBridge>(); | ||
ITxSender txSender = Substitute.For<ITxSender>(); | ||
txSender.SendTransaction(tx: Arg.Any<Transaction>(), txHandlingOptions: TxHandlingOptions.PersistentBroadcast) | ||
.Returns(returnThis: (TestItem.KeccakA, AcceptTxResult.Accepted)); | ||
|
||
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(chainId: TestBlockchainIds.ChainId, logManager: LimboLogs.Instance); | ||
TestRpcBlockchain rpcBlockchain = await TestRpcBlockchain | ||
.ForTest(sealEngineType: SealEngineType.Optimism) | ||
.WithBlockchainBridge(bridge) | ||
.WithTxSender(txSender) | ||
.WithOptimismEthRpcModule( | ||
sequencerRpcClient: null /* explicitly using null to behave as Sequencer */, | ||
accountStateProvider: Substitute.For<IAccountStateProvider>(), | ||
ecdsa: new OptimismEthereumEcdsa(ethereumEcdsa), | ||
sealer: Substitute.For<ITxSealer>(), | ||
opSpecHelper: Substitute.For<IOptimismSpecHelper>()) | ||
.Build(); | ||
|
||
Transaction tx = Build.A.Transaction | ||
.Signed(ecdsa: ethereumEcdsa, privateKey: TestItem.PrivateKeyA) | ||
.TestObject; | ||
string serialized = await rpcBlockchain.TestEthRpc("eth_sendRawTransaction", Rlp.Encode(item: tx, behaviors: RlpBehaviors.None).Bytes.ToHexString()); | ||
|
||
await txSender.Received().SendTransaction(tx: Arg.Any<Transaction>(), txHandlingOptions: TxHandlingOptions.PersistentBroadcast); | ||
Assert.That(actual: serialized, expression: Is.EqualTo(expected: $$"""{"jsonrpc":"2.0","result":"{{TestItem.KeccakA.Bytes.ToHexString(withZeroX: true)}}","id":67}""")); | ||
} | ||
} | ||
|
||
internal static class TestRpcBlockchainExt | ||
{ | ||
public static TestRpcBlockchain.Builder<TestRpcBlockchain> WithOptimismEthRpcModule( | ||
this TestRpcBlockchain.Builder<TestRpcBlockchain> @this, | ||
IJsonRpcClient? sequencerRpcClient, | ||
IAccountStateProvider accountStateProvider, | ||
IEthereumEcdsa ecdsa, | ||
ITxSealer sealer, | ||
IOptimismSpecHelper opSpecHelper) | ||
{ | ||
return @this.WithEthRpcModule(blockchain => new OptimismEthRpcModule( | ||
blockchain.RpcConfig, | ||
blockchain.Bridge, | ||
blockchain.BlockFinder, | ||
blockchain.ReceiptFinder, | ||
blockchain.StateReader, | ||
blockchain.TxPool, | ||
blockchain.TxSender, | ||
blockchain.TestWallet, | ||
LimboLogs.Instance, | ||
blockchain.SpecProvider, | ||
blockchain.GasPriceOracle, | ||
new EthSyncingInfo(blockchain.BlockTree, blockchain.ReceiptStorage, new SyncConfig(), | ||
new StaticSelector(SyncMode.All), Substitute.For<ISyncProgressResolver>(), blockchain.LogManager), | ||
blockchain.FeeHistoryOracle ?? | ||
new FeeHistoryOracle(blockchain.BlockTree, blockchain.ReceiptStorage, blockchain.SpecProvider), | ||
new BlocksConfig().SecondsPerSlot, | ||
sequencerRpcClient, accountStateProvider, ecdsa, sealer, opSpecHelper | ||
)); | ||
} | ||
} |
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