From 615b9743b19d52330138adada0dc067691054658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Thu, 17 Dec 2020 14:36:18 -0600 Subject: [PATCH] Transfer bug fix (#429) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) (#416) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * Nep17 (#412) * [RpcServer] Querying contracts by ID/name (#378) * fixed-bug-1021 * Update src/RpcServer/RpcServer.SmartContract.cs * 😂 * draft * draft * update * fixed bug with decimal of GAS consumed in invokefunction/invokescript * remove modify of invokescript * Querying contracts by ID/name, server side * update * Enable using native.name for search Enable using native.name for search * Using keyword instead of addressOrScriptHash * revert * _initialize * split * update * Update exception message in ApplicationLog * Update src/ApplicationLogs/LogReader.cs Co-authored-by: Luchuan * update * a * More fix * fix * Fixed UT * Simplify Code * Simplify Code 2 * Update RpcServer * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan * String Substitution * Modify filename and name methods * update * update * Update src/RpcClient/Models/RpcNep5TokenInfo.cs Co-authored-by: Vitor Nazário Coelho * Update src/RpcClient/Nep17API.cs Co-authored-by: Vitor Nazário Coelho * MPT in StateService from core (#410) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413) * Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal * fix * Fixed UT (Neo CI01089) * Update Nep17API.cs * Update README.md Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> * update filename * Fix UT * Format * fix * update * update UT * Add Unit Tests * update Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao * merge * fixed bug * clear * UT * Add a little code coverage Co-authored-by: Shargon Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Co-authored-by: superboyiii <573504781@qq.com> Co-authored-by: Vitor Nazário Coelho Co-authored-by: Luchuan Co-authored-by: ZhangTao --- src/Directory.Build.props | 2 +- src/RpcClient/Nep17API.cs | 4 ++-- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 8 ++++---- tests/Neo.Network.RPC.Tests/UT_Nep17API.cs | 10 +++++----- tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 1 + tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs | 6 +++--- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 7668491fb..ae97d5e4a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -15,7 +15,7 @@ - + \ No newline at end of file diff --git a/src/RpcClient/Nep17API.cs b/src/RpcClient/Nep17API.cs index 50650ade6..69a3b7d53 100644 --- a/src/RpcClient/Nep17API.cs +++ b/src/RpcClient/Nep17API.cs @@ -110,7 +110,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, KeyPair var sender = Contract.CreateSignatureRedeemScript(fromKey.PublicKey).ToScriptHash(); Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = data is null ? scriptHash.MakeScript("transfer", sender, to, amount) : scriptHash.MakeScript("transfer", sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); @@ -137,7 +137,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, int m, var sender = Contract.CreateMultiSigContract(m, pubKeys).ScriptHash; Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = data is null ? scriptHash.MakeScript("transfer", sender, to, amount) : scriptHash.MakeScript("transfer", sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index c6c2228b2..1e97c3832 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -433,7 +433,7 @@ "jsonrpc": "2.0", "id": 1, "method": "getcontractstate", - "params": [ "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64" ] + "params": [ "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6" ] }, "Response": { "jsonrpc": "2.0", @@ -441,10 +441,10 @@ "result": { "id": -1, "updatecounter": 0, - "hash": "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64", - "script": "DANORU9BGvd7Zw==", + "hash": "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6", + "script": "DAhOZW9Ub2tlbkEa93tn", "manifest": { - "name": "NEO", + "name": "NeoToken", "groups": [], "supportedstandards": [ "NEP-17" diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index f48a6eea4..a4f2d93f8 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -98,21 +98,21 @@ public async Task TestGetTokenInfo() .ReturnsAsync(test.Response.Result) .Verifiable(); - if (test.Request.Params[0].AsString() == "0xb399c051778cf37a1e4ef88509b2e054d0420a32") + if (test.Request.Params[0].AsString() == "0xa6a6c15dcdc9b997dac448b6926522d22efeedfb") { 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); + Assert.AreEqual("GasToken", result.Name); } - else if (test.Request.Params[0].AsString() == "0x74c21a1ca66b7a190bf2a65db83ba6fe550cea64") + else if (test.Request.Params[0].AsString() == "0x0a46e2e37c9987f570b4af253fb77e7eef0f72b6") { 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); + Assert.AreEqual("NeoToken", result.Name); } } } @@ -120,7 +120,7 @@ public async Task TestGetTokenInfo() [TestMethod] public async Task TestTransfer() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000)); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter()); var result = await nep17API.CreateTransferTxAsync(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000)); diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 69ba8caaf..f4f2f5c12 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -294,6 +294,7 @@ public async Task TestGetUnclaimedGas() { var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.GetUnclaimedGasAsync).ToLower()); var result = await rpc.GetUnclaimedGasAsync(test.Request.Params[0].AsString()); + Assert.AreEqual(result.ToJson().AsString(), RpcUnclaimedGas.FromJson(result.ToJson()).ToJson().AsString()); Assert.AreEqual(test.Response.Result["unclaimed"].AsString(), result.Unclaimed.ToString()); } diff --git a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs index 721b53fef..7ec348ebe 100644 --- a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs @@ -79,7 +79,7 @@ public async Task TestClaimGas() byte[] balanceScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, balanceScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); - byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", sender, sender, new BigInteger(1_00000000)); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", sender, sender, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -96,7 +96,7 @@ public async Task TestTransfer() byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, NativeContract.GAS.Factor * 100); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -118,7 +118,7 @@ public async Task TestTransferfromMultiSigAccount() byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject();