Skip to content

Commit

Permalink
real fix
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jul 24, 2019
1 parent f2606e1 commit ac85174
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions neo.UnitTests/UT_DataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void TestCachedFind_Between()
);

CollectionAssert.AreEqual(
cache.Find(new byte[] { 0x00 }).Select(u => u.Key.Key[1]).ToArray(),
cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(),
new byte[] { 0x01, 0x02, 0x03 }
);

Expand Down Expand Up @@ -88,7 +88,7 @@ public void TestCachedFind_Last()
);

CollectionAssert.AreEqual(
cache.Find(new byte[] { 0x00 }).Select(u => u.Key.Key[1]).ToArray(),
cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(),
new byte[] { 0x01, 0x02 }
);

Expand Down Expand Up @@ -116,7 +116,7 @@ public void TestCachedFind_Empty()
);

CollectionAssert.AreEqual(
cache.Find(new byte[] { 0x00 }).Select(u => u.Key.Key[1]).ToArray(),
cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(),
new byte[] { 0x02 }
);

Expand Down

3 comments on commit ac85174

@shargon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should process the prefix inside the find function, because here you don't need to know how is stored

@erikzhang
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static bool Storage_Find(ApplicationEngine engine)
{
if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
{
StorageContext context = _interface.GetInterface<StorageContext>();
if (!CheckStorageContext(engine, context)) return false;
byte[] prefix = engine.CurrentContext.EvaluationStack.Pop().GetByteArray();
byte[] prefix_key;
using (MemoryStream ms = new MemoryStream())
{
int index = 0;
int remain = prefix.Length;
while (remain >= 16)
{
ms.Write(prefix, index, 16);
ms.WriteByte(0);
index += 16;
remain -= 16;
}
if (remain > 0)
ms.Write(prefix, index, remain);
prefix_key = context.ScriptHash.ToArray().Concat(ms.ToArray()).ToArray();
}
StorageIterator iterator = engine.AddDisposable(new StorageIterator(engine.Snapshot.Storages.Find(prefix_key).Where(p => p.Key.Key.Take(prefix.Length).SequenceEqual(prefix)).GetEnumerator()));
engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(iterator));
return true;
}
return false;
}

@shargon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this class is not only used for StorageKeys it could have Contracts or other classes (without grouping)

Please sign in to comment.