diff --git a/Libplanet.Tests/Store/TrieStateStoreTest.cs b/Libplanet.Tests/Store/TrieStateStoreTest.cs index d0a83b3716d..7a8daa35ce8 100644 --- a/Libplanet.Tests/Store/TrieStateStoreTest.cs +++ b/Libplanet.Tests/Store/TrieStateStoreTest.cs @@ -81,21 +81,21 @@ public void PruneStates() )) .ToList(); - ITrie trie = stateStore.GetStateRoot(null); + ITrie firstTrie = stateStore.GetStateRoot(null); foreach (var kv in kvs) { - trie = trie.Set(kv.Item1, kv.Item2); + firstTrie = firstTrie.Set(kv.Item1, kv.Item2); } - trie = stateStore.Commit(trie); - HashDigest firstHash = trie.Hash; + firstTrie = stateStore.Commit(firstTrie); + HashDigest firstHash = firstTrie.Hash; int firstStateCount = _stateKeyValueStore.ListKeys().Count(); - trie = trie.Set( + ITrie secondTrie = firstTrie.Set( new KeyBytes(GetRandomBytes(35)), (IValue)new Binary(GetRandomBytes(20))); - trie = stateStore.Commit(trie); - HashDigest secondHash = trie.Hash; + secondTrie = stateStore.Commit(secondTrie); + HashDigest secondHash = secondTrie.Hash; int secondStateCount = _stateKeyValueStore.ListKeys().Count(); Assert.True(secondStateCount > firstStateCount); @@ -117,6 +117,19 @@ public void PruneStates() stateStore.PruneStates( ImmutableHashSet>.Empty.Add(firstHash)); Assert.Equal(firstStateCount, _stateKeyValueStore.ListKeys().Count()); + Assert.Equal( + firstTrie.IterateNodes().Count(), + stateStore.GetStateRoot(firstHash).IterateNodes().Count()); + Assert.Equal( + firstTrie.IterateValues().Count(), + stateStore.GetStateRoot(firstHash).IterateValues().Count()); + + // To clear node cache. + stateStore = new TrieStateStore(_stateKeyValueStore); + Assert.Throws( + () => stateStore.GetStateRoot(secondHash).IterateNodes().ToList()); + Assert.Throws( + () => stateStore.GetStateRoot(secondHash).IterateValues().ToList()); } [Fact]