Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhitong committed Aug 19, 2024
1 parent b6391a2 commit f0cceb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ public void TestGetContractState()
var result = _rpcServer.GetContractState(new JArray(contractState.Hash.ToString()));
Assert.AreEqual(contractState.ToJson().ToString(), result.ToString());

//Test Faild
//result = _rpcServer.GetContractState(new JArray(contractState.Id));
//Assert.AreEqual(contractState.ToJson().ToString(), result.ToString());
result = _rpcServer.GetContractState(new JArray(contractState.Id));
Assert.AreEqual(contractState.ToJson().ToString(), result.ToString());

var byId = _rpcServer.GetContractState(new JArray(-1));
var byName = _rpcServer.GetContractState(new JArray("ContractManagement"));
byId.ToString().Should().Be(byName.ToString());
}

[TestMethod]
Expand Down Expand Up @@ -224,6 +227,17 @@ public void TestFindStorage()
json["next"] = 1;
json["results"] = jarr;
Assert.AreEqual(json.ToString(), result.ToString());

var result2 = _rpcServer.FindStorage(new JArray(contractState.Hash.ToString(), Convert.ToBase64String(key), "x"));
var result3 = _rpcServer.FindStorage(new JArray(contractState.Hash.ToString(), Convert.ToBase64String(key)));
result2.ToString().Should().Be(result.ToString());
result3.ToString().Should().Be(result.ToString());

Enumerable.Range(0, 51).ToList().ForEach(i => TestUtils.StorageItemAdd(snapshot, contractState.Id, new byte[] { 0x01, (byte)i }, new byte[] { 0x02 }));
snapshot.Commit();
var result4 = _rpcServer.FindStorage(new JArray(contractState.Hash.ToString(), Convert.ToBase64String(new byte[] { 0x01 }), 0));
result4["next"].Should().Be(RpcServerSettings.Default.FindStoragePageSize);
(result4["truncated"]).AsBoolean().Should().Be(true);
}

[TestMethod]
Expand Down
5 changes: 5 additions & 0 deletions tests/Neo.UnitTests/Extensions/NativeContractExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract;
Expand Down Expand Up @@ -100,8 +101,12 @@ public static void DestroyContract(this DataCache snapshot, UInt160 callingScrip

public static void AddContract(this DataCache snapshot, UInt160 hash, ContractState state)
{
//key: hash, value: ContractState
var key = new KeyBuilder(NativeContract.ContractManagement.Id, 8).Add(hash);
snapshot.Add(key, new StorageItem(state));
//key: id, value: hash
var key2 = new KeyBuilder(NativeContract.ContractManagement.Id, 12).AddBigEndian(state.Id);
snapshot.Add(key2, new StorageItem(hash.ToArray()));
}

public static void DeleteContract(this DataCache snapshot, UInt160 hash)
Expand Down

0 comments on commit f0cceb5

Please sign in to comment.