Skip to content

Commit

Permalink
Merge branch 'master' into create_only_one_snapshot_for_persist
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Apr 27, 2020
2 parents 4d1f452 + 0c94a67 commit a326107
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit a326107

Please sign in to comment.