-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/arg out of range SnapProvider.AddAccountRange (#7060)
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
- Loading branch information
1 parent
4020ade
commit a61df04
Showing
4 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/Nethermind/Nethermind.Synchronization.Test/SnapSync/SnapProviderTests.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,62 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using FluentAssertions; | ||
using Nethermind.Blockchain; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Db; | ||
using Nethermind.Logging; | ||
using Nethermind.State.Snap; | ||
using Nethermind.Synchronization.SnapSync; | ||
using Nethermind.Trie; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Nethermind.Synchronization.Test.SnapSync; | ||
|
||
[TestFixture] | ||
public class SnapProviderTests | ||
{ | ||
|
||
[Test] | ||
public void AddAccountRange_AccountListIsEmpty_ThrowArgumentException() | ||
{ | ||
MemDb db = new(); | ||
IDbProvider dbProvider = new DbProvider(); | ||
dbProvider.RegisterDb(DbNames.State, db); | ||
using ProgressTracker progressTracker = new(Substitute.For<IBlockTree>(), dbProvider.GetDb<IDb>(DbNames.State), LimboLogs.Instance); | ||
dbProvider.RegisterDb(DbNames.Code, new MemDb()); | ||
SnapProvider sut = new(progressTracker, dbProvider.CodeDb, new NodeStorage(dbProvider.StateDb), LimboLogs.Instance); | ||
|
||
Assert.That( | ||
() => sut.AddAccountRange( | ||
0, | ||
Keccak.Zero, | ||
Keccak.Zero, | ||
Array.Empty<PathWithAccount>(), | ||
Array.Empty<byte[]>().AsReadOnly()), Throws.ArgumentException); | ||
} | ||
|
||
|
||
[Test] | ||
public void AddAccountRange_ResponseHasEmptyListOfAccountsAndOneProof_ReturnsExpiredRootHash() | ||
{ | ||
MemDb db = new(); | ||
IDbProvider dbProvider = new DbProvider(); | ||
dbProvider.RegisterDb(DbNames.State, db); | ||
using ProgressTracker progressTracker = new(Substitute.For<IBlockTree>(), dbProvider.GetDb<IDb>(DbNames.State), LimboLogs.Instance); | ||
dbProvider.RegisterDb(DbNames.Code, new MemDb()); | ||
AccountRange accountRange = new(Keccak.Zero, Keccak.Zero, Keccak.MaxValue); | ||
using AccountsAndProofs accountsAndProofs = new(); | ||
accountsAndProofs.PathAndAccounts = new List<PathWithAccount>().ToPooledList(); | ||
accountsAndProofs.Proofs = new List<byte[]> { new byte[] { 0x0 } }.ToPooledList(); | ||
|
||
SnapProvider sut = new(progressTracker, dbProvider.CodeDb, new NodeStorage(dbProvider.StateDb), LimboLogs.Instance); | ||
|
||
sut.AddAccountRange(accountRange, accountsAndProofs).Should().Be(AddRangeResult.ExpiredRootHash); | ||
} | ||
|
||
} |
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