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

Fixed UT #420

Merged
merged 15 commits into from
Dec 14, 2020
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01091" />
<PackageReference Include="Neo" Version="3.0.0-CI01097" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/RpcClient/ContractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public Task<RpcInvokeResult> TestInvokeAsync(UInt160 scriptHash, string operatio
/// <param name="manifest">contract manifest</param>
/// <param name="key">sender KeyPair</param>
/// <returns></returns>
public async Task<Transaction> CreateDeployContractTxAsync(byte[] contractScript, ContractManifest manifest, KeyPair key)
public async Task<Transaction> CreateDeployContractTxAsync(byte[] nefFile, ContractManifest manifest, KeyPair key)
{
byte[] script;
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitSysCall(ApplicationEngine.System_Contract_Create, contractScript, manifest.ToString());
sb.EmitSysCall(ApplicationEngine.System_Contract_Call, SmartContract.Native.NativeContract.Management.Hash, "deploy", nefFile, manifest.ToString());
script = sb.ToArray();
}
UInt160 sender = Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash();
Expand Down
1 change: 1 addition & 0 deletions src/RpcClient/Models/RpcContractState.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo;
using Neo.IO.Json;
using Neo.Ledger;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using System;

Expand Down
4 changes: 3 additions & 1 deletion src/RpcNep17Tracker/RpcNep17Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ public JObject GetNep17Balances(JArray _params)
foreach (var (key, value) in dbCache.Find(prefix))
{
JObject balance = new JObject();
if (Blockchain.Singleton.View.Contracts.TryGet(key.AssetScriptHash) is null)

var contract = NativeContract.Management.GetContract(Blockchain.Singleton.GetSnapshot(), key.AssetScriptHash);
if (contract is null)
continue;
balance["assethash"] = key.AssetScriptHash.ToString();
balance["amount"] = value.Balance.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected virtual JObject GetBlockHeader(JArray _params)
protected virtual JObject GetContractState(JArray _params)
{
UInt160 script_hash = ToScriptHash(_params[0].AsString());
ContractState contract = Blockchain.Singleton.View.Contracts.TryGet(script_hash);
var contract = NativeContract.Management.GetContract(Blockchain.Singleton.GetSnapshot(), script_hash);
return contract?.ToJson() ?? throw new RpcException(-100, "Unknown contract");
}

Expand Down Expand Up @@ -167,7 +167,7 @@ protected virtual JObject GetStorage(JArray _params)
if (!int.TryParse(_params[0].AsString(), out int id))
{
UInt160 script_hash = UInt160.Parse(_params[0].AsString());
ContractState contract = Blockchain.Singleton.View.Contracts.TryGet(script_hash);
var contract = NativeContract.Management.GetContract(Blockchain.Singleton.GetSnapshot(), script_hash);
if (contract == null) return null;
id = contract.Id;
}
Expand Down
243 changes: 220 additions & 23 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@
"Name": "getcontractstateasync",
"Request": {
"jsonrpc": "2.0",
"id": 1,
"method": "getcontractstate",
"params": [ "0x36a019d836d964c438c573f78badf79b9e7eebdd" ],
"id": 1
"params": [ "0xb399c051778cf37a1e4ef88509b2e054d0420a32" ]
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"id": -2,
"updatecounter": 0,
"hash": "0x36a019d836d964c438c573f78badf79b9e7eebdd",
"script": "DANHQVNBa2d4Cw==",
"hash": "0xb399c051778cf37a1e4ef88509b2e054d0420a32",
"script": "DANHQVNBGvd7Zw==",
"manifest": {
"name": "GAS",
"groups": [],
Expand All @@ -337,17 +337,12 @@
],
"abi": {
"methods": [
{
"name": "onPersist",
"parameters": [],
"offset": 0,
"returntype": "Void"
},
{
"name": "totalSupply",
"parameters": [],
"offset": 0,
"returntype": "Integer"
"returntype": "Integer",
"safe": true
},
{
"name": "balanceOf",
Expand All @@ -358,7 +353,8 @@
}
],
"offset": 0,
"returntype": "Integer"
"returntype": "Integer",
"safe": true
},
{
"name": "transfer",
Expand All @@ -381,25 +377,232 @@
}
],
"offset": 0,
"returntype": "Boolean"
"returntype": "Boolean",
"safe": false
},
{
"name": "symbol",
"parameters": [],
"offset": 0,
"returntype": "String",
"safe": true
},
{
"name": "decimals",
"parameters": [],
"offset": 0,
"returntype": "Integer",
"safe": true
}
],
"events": [
{
"name": "Transfer",
"parameters": [
{
"name": "from",
"type": "Hash160"
},
{
"name": "to",
"type": "Hash160"
},
{
"name": "amount",
"type": "Integer"
}
]
}
]
},
"permissions": [
{
"contract": "*",
"methods": "*"
}
],
"trusts": [],
"extra": null
}
}
}
},
{
"Name": "getcontractstateasync",
"Request": {
"jsonrpc": "2.0",
"id": 1,
"method": "getcontractstate",
"params": [ "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64" ]
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"id": -1,
"updatecounter": 0,
"hash": "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64",
"script": "DANORU9BGvd7Zw==",
"manifest": {
"name": "NEO",
"groups": [],
"supportedstandards": [
"NEP-17"
],
"abi": {
"methods": [
{
"name": "totalSupply",
"parameters": [],
"offset": 0,
"returntype": "Integer",
"safe": true
},
{
"name": "setGasPerBlock",
"parameters": [
{
"name": "gasPerBlock",
"type": "Integer"
}
],
"offset": 0,
"returntype": "Boolean",
"safe": false
},
{
"name": "getGasPerBlock",
"parameters": [],
"offset": 0,
"returntype": "Integer",
"safe": true
},
{
"name": "unclaimedGas",
"parameters": [
{
"name": "account",
"type": "ByteArray"
},
{
"name": "end",
"type": "Integer"
}
],
"offset": 0,
"returntype": "Integer",
"safe": true
},
{
"name": "registerCandidate",
"parameters": [
{
"name": "pubkey",
"type": "ByteArray"
}
],
"offset": 0,
"returntype": "Boolean",
"safe": false
},
{
"name": "unregisterCandidate",
"parameters": [
{
"name": "pubkey",
"type": "ByteArray"
}
],
"offset": 0,
"returntype": "Boolean",
"safe": false
},
{
"name": "vote",
"parameters": [
{
"name": "account",
"type": "ByteArray"
},
{
"name": "voteTo",
"type": "ByteArray"
}
],
"offset": 0,
"returntype": "Boolean",
"safe": false
},
{
"name": "postPersist",
"name": "getCandidates",
"parameters": [],
"offset": 0,
"returntype": "Void"
"returntype": "Array",
"safe": true
},
{
"name": "getCommittee",
"parameters": [],
"offset": 0,
"returntype": "Array",
"safe": true
},
{
"name": "getNextBlockValidators",
"parameters": [],
"offset": 0,
"returntype": "Array",
"safe": true
},
{
"name": "balanceOf",
"parameters": [
{
"name": "account",
"type": "ByteArray"
}
],
"offset": 0,
"returntype": "Integer",
"safe": true
},
{
"name": "transfer",
"parameters": [
{
"name": "from",
"type": "ByteArray"
},
{
"name": "to",
"type": "ByteArray"
},
{
"name": "amount",
"type": "Integer"
},
{
"name": "data",
"type": "Any"
}
],
"offset": 0,
"returntype": "Boolean",
"safe": false
},
{
"name": "symbol",
"parameters": [],
"offset": 0,
"returntype": "String"
"returntype": "String",
"safe": true
},
{
"name": "decimals",
"parameters": [],
"offset": 0,
"returntype": "Integer"
"returntype": "Integer",
"safe": true
}
],
"events": [
Expand Down Expand Up @@ -429,12 +632,6 @@
}
],
"trusts": [],
"safemethods": [
"totalSupply",
"balanceOf",
"symbol",
"decimals"
],
"extra": null
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Neo.Network.RPC.Tests/UT_ContractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ public async Task TestDeployContract()
Methods = new ContractMethodDescriptor[0]
},
Groups = new ContractGroup[0],
SafeMethods = WildcardContainer<string>.Create(),
Trusts = WildcardContainer<UInt160>.Create(),
SupportedStandards = new string[] { "NEP-10" },
Extra = null,
};
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitSysCall(ApplicationEngine.System_Contract_Create, new byte[1], manifest.ToString());
sb.EmitSysCall(ApplicationEngine.System_Contract_Call, NativeContract.Management.Hash, "deploy", new byte[1], manifest.ToString());
script = sb.ToArray();
}

Expand Down
Loading