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
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.EmitAppCall(NativeContract.Management.Hash, "deploy", contractScript, manifest.ToString());
sb.EmitAppCall(NativeContract.Management.Hash, "deploy", nefFile, manifest.ToString());
script = sb.ToArray();
}
UInt160 sender = Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash();
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static Signers SignersFromJson(JArray _params)
private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signers signers = null)
{
var snapshot = Blockchain.Singleton.GetSnapshot();
var contract = snapshot.Contracts.TryGet(scriptHash);
var contract = NativeContract.Management.GetContract(snapshot, scriptHash);
if (contract is null)
{
throw new RpcException(-100, "Unknown contract");
Expand Down
210 changes: 210 additions & 0 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,216 @@
}
}
},
{
"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": "getCandidates",
"parameters": [],
"offset": 0,
"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",
"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": "getrawmempoolasync",
"Request": {
Expand Down
31 changes: 26 additions & 5 deletions tests/Neo.Network.RPC.Tests/UT_Nep17API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,39 @@ public async Task TestGetTokenInfo()
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.GAS.Decimals) },
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) });

scriptHash = NativeContract.NEO.Hash;
testScript = scriptHash.MakeScript("symbol")
.Concat(scriptHash.MakeScript("decimals"))
.Concat(scriptHash.MakeScript("totalSupply"))
.ToArray();
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript,
new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.NEO.Symbol },
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.NEO.Decimals) },
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) });

var tests = TestUtils.RpcTestCases.Where(p => p.Name == "getcontractstateasync");
foreach (var test in tests)
{
rpcClientMock.Setup(p => p.RpcSendAsync("getcontractstate", It.Is<JObject[]>(u => true)))
.ReturnsAsync(test.Response.Result)
.Verifiable();

var result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Hash);
Assert.AreEqual(NativeContract.GAS.Symbol, result.Symbol);
Assert.AreEqual(8, (int)result.Decimals);
Assert.AreEqual(1_00000000, (int)result.TotalSupply);
Assert.AreEqual("GAS", result.Name);
if (test.Request.Params[0].AsString() == "0xb399c051778cf37a1e4ef88509b2e054d0420a32")
{
var result = await nep17API.GetTokenInfoAsync(NativeContract.GAS.Hash);
Assert.AreEqual(NativeContract.GAS.Symbol, result.Symbol);
Assert.AreEqual(8, (int)result.Decimals);
Assert.AreEqual(1_00000000, (int)result.TotalSupply);
Assert.AreEqual("GAS", result.Name);
}
else if (test.Request.Params[0].AsString() == "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64")
{
var result = await nep17API.GetTokenInfoAsync(NativeContract.NEO.Hash);
Assert.AreEqual(NativeContract.NEO.Symbol, result.Symbol);
Assert.AreEqual(0, (int)result.Decimals);
Assert.AreEqual(1_00000000, (int)result.TotalSupply);
Assert.AreEqual("NEO", result.Name);
}
}
}

Expand Down