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

TestEngine: add Checkpoints, RpcStorage and Dump to html #904

Merged
merged 31 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fbc827f
Draft Checkpoint
shargon Feb 15, 2024
dc39132
fix namespaces
shargon Feb 15, 2024
5d41e75
Add ut
shargon Feb 15, 2024
dffc549
Merge branch 'master' into core-test-checkpoint
shargon Feb 15, 2024
469502f
Update src/Neo.SmartContract.Testing/Storage/EngineStorage.cs
shargon Feb 15, 2024
49b05b9
Merge branch 'master' into core-test-checkpoint
shargon Feb 15, 2024
fef4902
Rpc Storage
shargon Feb 15, 2024
ffca0db
Merge branch 'core-test-checkpoint' of https://github.com/neo-project…
shargon Feb 15, 2024
159cbbd
Seek
shargon Feb 16, 2024
d1f65db
clean
shargon Feb 16, 2024
fa60aae
By pass RPC Backward
shargon Feb 16, 2024
71592fc
Change to testnet
shargon Feb 16, 2024
a93037e
Fix bug
shargon Feb 16, 2024
2640e16
clean using
shargon Feb 16, 2024
44a7ac3
Merge remote-tracking branch 'origin/master' into core-test-checkpoint
shargon Feb 17, 2024
c89f9f8
Conflicts
shargon Feb 17, 2024
cc0f6cb
Dump to html
shargon Feb 17, 2024
f8046be
Fix coverage during OnFault
shargon Feb 17, 2024
a265017
print string when possible
shargon Feb 17, 2024
9ce8353
Coverage 100%
shargon Feb 17, 2024
ac01009
fix comment
shargon Feb 17, 2024
30f45bd
Update README
shargon Feb 17, 2024
f0ec698
Update src/Neo.SmartContract.Testing/TestingApplicationEngine.cs
shargon Feb 17, 2024
26ad4a1
format
shargon Feb 17, 2024
98e3386
Improve method name
shargon Feb 17, 2024
85d1b3a
Merge branch 'core-test-checkpoint' of https://github.com/neo-project…
shargon Feb 17, 2024
4b492d6
Refactor AbiMethod constructor
shargon Feb 17, 2024
4b43514
Update tests/Neo.SmartContract.Template.UnitTests/templates/neocontra…
shargon Feb 18, 2024
a22d2fe
Merge branch 'master' into core-test-checkpoint
shargon Feb 19, 2024
2a5370c
Merge branch 'master' into core-test-checkpoint
shargon Feb 19, 2024
5a77852
Merge branch 'master' into core-test-checkpoint
Jim8y Feb 19, 2024
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
36 changes: 28 additions & 8 deletions src/Neo.SmartContract.Testing/Storage/Rpc/RpcStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using Neo.IO;
using Neo.Persistence;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -45,9 +49,25 @@ public void Dispose() { }
{
if (direction is SeekDirection.Backward)
{
Copy link
Member Author

@shargon shargon Feb 16, 2024

Choose a reason for hiding this comment

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

@Jim8y it should be great have this in rpc

// TODO: not implemented in RPC
// Not implemented in RPC, we will query all the storage from the contract, and do it manually
// it could return wrong results if we want to get data between contracts

throw new NotImplementedException();
var prefix = key.Take(4).ToArray();
ConcurrentDictionary<byte[], byte[]> data = new();

// We ask for 5 bytes because the minimum prefix is one byte

foreach (var entry in Seek(key.Take(key.Length == 4 ? 4 : 5).ToArray(), SeekDirection.Forward))
{
data.TryAdd(prefix.Concat(entry.Key).ToArray(), entry.Value);
}

foreach (var entry in new MemorySnapshot(data).Seek(key, direction))
{
yield return (entry.Key, entry.Value);
}

yield break;
}

var skey = new StorageKey(key);
Expand All @@ -69,21 +89,21 @@ public void Dispose() { }

JObject jo = JObject.Parse(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());

if (jo["result"]?["results"]?.Value<JArray>() is JArray results)
if (jo["result"]?.Value<JObject>() is JObject result && result["results"]?.Value<JArray>() is JArray results)
{
// iterate page

foreach (JObject result in results)
foreach (JObject r in results)
{
if (result["key"]?.Value<string>() is string jkey &&
result["value"]?.Value<string>() is string kvalue)
if (r["key"]?.Value<string>() is string jkey &&
r["value"]?.Value<string>() is string kvalue)
{
yield return (Convert.FromBase64String(jkey), Convert.FromBase64String(kvalue));
}
}

if (jo["truncated"]?.Value<bool>() == true &&
jo["next"]?.Value<int>() is int next)
if (result["truncated"]?.Value<bool>() == true &&
result["next"]?.Value<int>() is int next)
{
start = next;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void TestRpcStore()
Assert.AreEqual(100_000_000, engine.Native.NEO.TotalSupply);
Assert.IsTrue(engine.Native.Ledger.CurrentIndex > 4_905_187);

// check with Seek (RPC doesn't support Backward)
// check with Seek (RPC doesn't support Backward, it could be slow)

// Assert.IsTrue(engine.Native.NEO.GasPerBlock == 5);
Assert.IsTrue(engine.Native.NEO.GasPerBlock == 500000000);
shargon marked this conversation as resolved.
Show resolved Hide resolved

// check deploy

Expand Down