Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datacache correction #1611

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/neo/IO/Caching/DataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ public void Add(TKey key, TValue value)
/// </summary>
public void Commit()
{
LinkedList<TKey> deletedItem = new LinkedList<TKey>();
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<TKey, TValue> CreateSnapshot()
Expand Down
5 changes: 5 additions & 0 deletions tests/neo.UnitTests/Wallets/UT_Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Nep5AccountState>().Balance = 0;
snapshot.Commit();
}
Expand All @@ -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<Nep5AccountState>().Balance = 0;
snapshot.Commit();
}
Expand Down Expand Up @@ -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<Nep5AccountState>().Balance = 0;
entry2.GetInteroperable<NeoToken.AccountState>().Balance = 0;
snapshot.Commit();
Expand Down Expand Up @@ -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<Nep5AccountState>().Balance = 0;
snapshot.Commit();
}
Expand Down