-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
12 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
65 changes: 65 additions & 0 deletions
65
src/Nethermind/Nethermind.State.Test/WorldStateManagerTests.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,65 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using FluentAssertions; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Db; | ||
using Nethermind.Logging; | ||
using Nethermind.Specs; | ||
using Nethermind.State; | ||
using Nethermind.Trie.Pruning; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Store.Test; | ||
|
||
public class WorldStateManagerTests | ||
{ | ||
[Test] | ||
public void ShouldProxyGlobalWorldState() | ||
{ | ||
IWorldState worldState = Substitute.For<IWorldState>(); | ||
ITrieStore trieStore = Substitute.For<ITrieStore>(); | ||
IDbProvider dbProvider = TestMemDbProvider.Init(); | ||
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance); | ||
|
||
worldStateManager.GlobalWorldState.Should().Be(worldState); | ||
} | ||
|
||
[Test] | ||
public void ShouldProxyReorgBoundaryEvent() | ||
{ | ||
IWorldState worldState = Substitute.For<IWorldState>(); | ||
ITrieStore trieStore = Substitute.For<ITrieStore>(); | ||
IDbProvider dbProvider = TestMemDbProvider.Init(); | ||
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance); | ||
|
||
bool gotEvent = false; | ||
worldStateManager.ReorgBoundaryReached += (sender, reached) => gotEvent = true; | ||
trieStore.ReorgBoundaryReached += Raise.EventWith<ReorgBoundaryReached>(new ReorgBoundaryReached(1)); | ||
|
||
gotEvent.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public void ShouldCreateTemporaryWorldState_AndCanReset() | ||
{ | ||
IWorldState worldState = Substitute.For<IWorldState>(); | ||
ITrieStore trieStore = Substitute.For<ITrieStore>(); | ||
IDbProvider dbProvider = TestMemDbProvider.Init(); | ||
WorldStateManager worldStateManager = new WorldStateManager(worldState, trieStore, dbProvider, LimboLogs.Instance); | ||
|
||
(IWorldState tempWorldState, IStateReader stateReader, Action reset) = worldStateManager.CreateResettableWorldState(); | ||
|
||
byte[] code = new byte[] { 1 }; | ||
Hash256 codeHash = Keccak.Compute(code); | ||
tempWorldState.CreateAccount(Address.Zero, 0, 0); | ||
tempWorldState.InsertCode(Address.Zero, code, MainnetSpecProvider.Instance.GenesisSpec); | ||
|
||
stateReader.GetCode(codeHash).Should().NotBeNull(); | ||
reset(); | ||
stateReader.GetCode(codeHash).Should().BeNull(); | ||
} | ||
} |
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