diff --git a/src/neo/IO/Caching/DataCache.cs b/src/neo/IO/Caching/DataCache.cs index d20d1bba2e..dd0d5221c8 100644 --- a/src/neo/IO/Caching/DataCache.cs +++ b/src/neo/IO/Caching/DataCache.cs @@ -75,19 +75,27 @@ public void Add(TKey key, TValue value) /// public void Commit() { + LinkedList deletedItem = new LinkedList(); foreach (Trackable trackable in GetChangeSet()) switch (trackable.State) { case TrackState.Added: AddInternal(trackable.Key, trackable.Item); + trackable.State = TrackState.None; break; case TrackState.Changed: UpdateInternal(trackable.Key, trackable.Item); + trackable.State = TrackState.None; break; case TrackState.Deleted: DeleteInternal(trackable.Key); + deletedItem.AddFirst(trackable.Key); break; } + foreach (TKey key in deletedItem) + { + dictionary.Remove(key); + } } public DataCache CreateSnapshot() diff --git a/tests/neo.UnitTests/Wallets/UT_Wallet.cs b/tests/neo.UnitTests/Wallets/UT_Wallet.cs index 091caa2b65..e8cd43a46a 100644 --- a/tests/neo.UnitTests/Wallets/UT_Wallet.cs +++ b/tests/neo.UnitTests/Wallets/UT_Wallet.cs @@ -209,6 +209,7 @@ public void TestGetAvailable() wallet.GetAvailable(NativeContract.GAS.Hash).Should().Be(new BigDecimal(1000000000000, 8)); + entry = snapshot.Storages.GetAndChange(key, () => new StorageItem(new Nep5AccountState())); entry.GetInteroperable().Balance = 0; snapshot.Commit(); } @@ -231,6 +232,7 @@ public void TestGetBalance() wallet.GetBalance(UInt160.Zero, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(0, 0)); wallet.GetBalance(NativeContract.GAS.Hash, new UInt160[] { account.ScriptHash }).Should().Be(new BigDecimal(1000000000000, 8)); + entry = snapshot.Storages.GetAndChange(key, () => new StorageItem(new Nep5AccountState())); entry.GetInteroperable().Balance = 0; snapshot.Commit(); } @@ -354,6 +356,8 @@ public void TestMakeTransaction1() }); tx.Should().NotBeNull(); + entry1 = snapshot.Storages.GetAndChange(key, () => new StorageItem(new Nep5AccountState())); + entry2 = snapshot.Storages.GetAndChange(key, () => new StorageItem(new Nep5AccountState())); entry1.GetInteroperable().Balance = 0; entry2.GetInteroperable().Balance = 0; snapshot.Commit(); @@ -383,6 +387,7 @@ public void TestMakeTransaction2() tx = wallet.MakeTransaction(new byte[] { }, null, new TransactionAttribute[] { }); tx.Should().NotBeNull(); + entry = snapshot.Storages.GetAndChange(key, () => new StorageItem(new Nep5AccountState())); entry.GetInteroperable().Balance = 0; snapshot.Commit(); }