Skip to content

Commit

Permalink
fix getcontractstate (#3282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y authored May 28, 2024
1 parent 68005ba commit 7bb4900
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Plugins/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ protected virtual JToken GetContractState(JArray _params)
{
if (int.TryParse(_params[0].AsString(), out int contractId))
{
var contracts = NativeContract.ContractManagement.GetContractById(system.StoreView, contractId);
return contracts?.ToJson().NotNull_Or(RpcError.UnknownContract);
}
else
{
UInt160 script_hash = ToScriptHash(_params[0].AsString());
ContractState contract = NativeContract.ContractManagement.GetContract(system.StoreView, script_hash);
return contract?.ToJson().NotNull_Or(RpcError.UnknownContract);
var contractState = NativeContract.ContractManagement.GetContractById(system.StoreView, contractId);
return contractState.NotNull_Or(RpcError.UnknownContract).ToJson();
}

var scriptHash = ToScriptHash(_params[0].AsString());
var contract = NativeContract.ContractManagement.GetContract(system.StoreView, scriptHash);
return contract.NotNull_Or(RpcError.UnknownContract).ToJson();
}

private static UInt160 ToScriptHash(string keyword)
Expand Down
26 changes: 26 additions & 0 deletions tests/Neo.Plugins.RpcServer.Tests/UT_Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// UT_Result.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.SmartContract;

namespace Neo.Plugins.RpcServer.Tests;

[TestClass]
public class UT_Result
{
[TestMethod]
public void TestNotNull_Or()
{
ContractState? contracts = null;
Assert.ThrowsException<RpcException>(() => contracts.NotNull_Or(RpcError.UnknownContract).ToJson());
}
}

0 comments on commit 7bb4900

Please sign in to comment.