Skip to content

Commit

Permalink
unittest for TxPool
Browse files Browse the repository at this point in the history
  • Loading branch information
ak88 committed Sep 6, 2024
1 parent 8f5c169 commit b1020eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/Nethermind/Nethermind.TxPool.Test/TxPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,35 @@ public void Should_correctly_add_tx_to_local_pool_when_underpaid([Values] TxType
_txPool.GetPendingTransactions().Should().NotContain(testTx);
}

static IEnumerable<(byte[], AcceptTxResult)> CodeCases()
{
yield return (new byte[16], AcceptTxResult.SenderIsContract);
//Delegation code
yield return ([..Eip7702Constants.DelegationHeader, ..new byte[20]], AcceptTxResult.Accepted);
}
[TestCaseSource(nameof(CodeCases))]
public void SubmitTx_((byte[] code, AcceptTxResult expected) testCase)
{
ISpecProvider specProvider = GetPragueSpecProvider();
TxPoolConfig txPoolConfig = new TxPoolConfig { Size = 30, PersistentBlobStorageSize = 0 };
_txPool = CreatePool(txPoolConfig, specProvider);

Transaction testTx = Build.A.Transaction
.WithNonce(0)
.WithMaxFeePerGas(9.GWei())
.WithMaxPriorityFeePerGas(9.GWei())
.WithGasLimit(100_000)
.WithTo(TestItem.AddressB)
.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA).TestObject;

EnsureSenderBalance(TestItem.PrivateKeyA.Address, UInt256.MaxValue);

_stateProvider.InsertCode(TestItem.PrivateKeyA.Address, testCase.code, Prague.Instance);

AcceptTxResult result = _txPool.SubmitTx(testTx, TxHandlingOptions.PersistentBroadcast);
result.Should().Be(testCase.expected);
}

private IDictionary<ITxPoolPeer, PrivateKey> GetPeers(int limit = 100)
{
var peers = new Dictionary<ITxPoolPeer, PrivateKey>();
Expand Down
6 changes: 1 addition & 5 deletions src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class TxPool : ITxPool, IDisposable
private readonly IBlobTxStorage _blobTxStorage;
private readonly IChainHeadInfoProvider _headInfo;
private readonly ITxPoolConfig _txPoolConfig;
private readonly ICodeInfoRepository _codeInfoRepository;
private readonly IWorldState _worldState;
private readonly bool _blobReorgsSupportEnabled;

private readonly ILogger _logger;
Expand Down Expand Up @@ -106,8 +104,6 @@ public TxPool(IEthereumEcdsa ecdsa,
_blobTxStorage = blobTxStorage ?? throw new ArgumentNullException(nameof(blobTxStorage));
_headInfo = chainHeadInfoProvider ?? throw new ArgumentNullException(nameof(chainHeadInfoProvider));
_txPoolConfig = txPoolConfig;
_codeInfoRepository = codeInfoRepository;
_worldState = worldState;
_blobReorgsSupportEnabled = txPoolConfig.BlobsSupport.SupportsReorgs();
_accounts = _accountCache = new AccountCache(_headInfo.AccountStateProvider);
_specProvider = _headInfo.SpecProvider;
Expand Down Expand Up @@ -157,7 +153,7 @@ public TxPool(IEthereumEcdsa ecdsa,
postHashFilters.Add(incomingTxFilter);
}

postHashFilters.Add(new DeployedCodeFilter(_worldState, _codeInfoRepository, _specProvider));
postHashFilters.Add(new DeployedCodeFilter(worldState, codeInfoRepository, _specProvider));

_postHashFilters = postHashFilters.ToArray();

Expand Down

0 comments on commit b1020eb

Please sign in to comment.