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

Add NeoAPI and update code after testing with NEO3 preview1 #1150

Merged
merged 175 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 172 commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
03c9a20
Add NEO SDK based on RPC client
chenquanyu Jun 17, 2019
4f84a63
add rpc interface methods for neo3
chenquanyu Jun 18, 2019
16c1471
update unit test
chenquanyu Jun 18, 2019
79523dd
add unit test
chenquanyu Jun 19, 2019
fe06992
Update TransactionHelper.cs
joeqian10 Jun 19, 2019
b5b2cd6
implement sdk rpc client methods
chenquanyu Jun 20, 2019
efd27a8
backup files
joeqian10 Jun 21, 2019
c78e965
change class name
chenquanyu Jun 21, 2019
cf7a184
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Jun 21, 2019
66b269c
remove uncompleted modules for pull request
chenquanyu Jun 21, 2019
26b4334
Merge branch 'master' of https://github.com/chenquanyu/neo
joeqian10 Jun 21, 2019
8c0c37f
Merge branch 'master' into dev
vncoelho Jun 21, 2019
b2705be
Merge branch 'master' into dev
chenquanyu Jun 24, 2019
3ae6480
change json deserialize method with Neo JObject
chenquanyu Jun 24, 2019
5de69a0
Merge remote-tracking branch 'erik/master'
chenquanyu Jun 24, 2019
ca1048e
modified JSON implementation, added FromJson()
joeqian10 Jun 26, 2019
af6d7e0
Merge remote-tracking branch 'erik/master'
chenquanyu Jun 26, 2019
2f58594
more RPC change
joeqian10 Jun 26, 2019
d5fa4a7
PR correction
chenquanyu Jun 26, 2019
90b225c
RPC module fix, remove newton.json
joeqian10 Jun 26, 2019
a08d5e9
fix
joeqian10 Jun 26, 2019
238abd5
Merge remote-tracking branch 'erik/master'
chenquanyu Jun 26, 2019
7c193b5
Merge branch 'dev' into master
chenquanyu Jun 26, 2019
71dad15
Merge pull request #2 from chenquanyu/master
chenquanyu Jun 26, 2019
e2b187b
fix getblock issue
chenquanyu Jun 27, 2019
0d58ad6
merge
chenquanyu Jun 27, 2019
0d5f720
Merge remote-tracking branch 'erik/master'
chenquanyu Jun 27, 2019
6ecf691
Merge pull request #3 from chenquanyu/master
chenquanyu Jun 27, 2019
cfa4622
Merge branch 'master' into dev
shargon Jun 28, 2019
663111e
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 1, 2019
a8df8e7
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 5, 2019
8cb2413
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 8, 2019
789eb26
Merge branch 'master' into dev
shargon Jul 8, 2019
3064b9e
PR correction
chenquanyu Jul 8, 2019
8d27ccb
Merge branch 'master' into dev
chenquanyu Jul 8, 2019
ad33da2
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 8, 2019
ec12ede
Merge branch 'dev' into master
chenquanyu Jul 8, 2019
afae7b1
Merge pull request #4 from chenquanyu/master
chenquanyu Jul 8, 2019
53d9ef3
PR Correction
chenquanyu Jul 12, 2019
dc46b10
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 12, 2019
058819b
Merge pull request #5 from chenquanyu/master
chenquanyu Jul 12, 2019
4fd233b
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 17, 2019
4710d14
PR Correction: rename RPC models
chenquanyu Jul 17, 2019
4b630b2
Merge pull request #6 from chenquanyu/master
chenquanyu Jul 17, 2019
403b38d
Merge branch 'master' into dev
vncoelho Jul 17, 2019
5920a48
Merge remote-tracking branch 'erik/master'
chenquanyu Jul 18, 2019
10a0597
PR Correction
chenquanyu Jul 18, 2019
a289067
Merge branch 'dev' into master
chenquanyu Jul 18, 2019
664ca6c
resolve conflicts
chenquanyu Jul 18, 2019
51088ee
Merge pull request #7 from chenquanyu/master
chenquanyu Jul 18, 2019
2442fe7
Clean code
shargon Jul 25, 2019
137ddb5
Clean code
shargon Jul 25, 2019
ac169c6
Clean code
shargon Jul 25, 2019
8ff77b6
Clean code
shargon Jul 25, 2019
4bc742d
Update RpcValidateAddressResult.cs
shargon Jul 25, 2019
b958970
Clean code
shargon Jul 25, 2019
ea0b6b4
Merge branch 'master' into dev
shargon Jul 25, 2019
b01b353
Merge pull request #8 from chenquanyu/dev
chenquanyu Jul 25, 2019
0d9b99a
PR correction
chenquanyu Jul 25, 2019
4d3e3a2
Merge pull request #9 from chenquanyu/master
chenquanyu Jul 25, 2019
73a53ac
Merge branch 'master' into dev
chenquanyu Jul 26, 2019
eee837a
Merge branch 'master' into dev
chenquanyu Jul 30, 2019
7da09eb
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Jul 30, 2019
2214846
Merge branch 'dev'
chenquanyu Jul 30, 2019
51e30f3
Merge branch 'master' into dev
erikzhang Jul 30, 2019
881af0b
Merge branch 'dev' of https://github.com/chenquanyu/neo into dev
chenquanyu Jul 30, 2019
b7403ec
Move test file to the right place
chenquanyu Jul 30, 2019
c5c0de1
Merge branch 'master' into dev
chenquanyu Jul 30, 2019
c6c0ffa
Merge remote-tracking branch 'erik/master'
chenquanyu Aug 1, 2019
f8a083a
Merge branch 'master' into dev
chenquanyu Aug 1, 2019
9332a33
Added SDK Transaction module.
joeqian10 Aug 2, 2019
24a1715
Merge branch 'dev' of https://github.com/chenquanyu/neo into dev
chenquanyu Aug 2, 2019
a2065a7
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Aug 5, 2019
04b5dbb
Add SDK SmartContract module
chenquanyu Aug 5, 2019
c257471
height = count - 1
joeqian10 Aug 5, 2019
6f4035e
Add sign function for TxManager
chenquanyu Aug 8, 2019
680c376
merge
chenquanyu Aug 8, 2019
389e8a4
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Aug 8, 2019
ad88a09
Add Deploy Contract
chenquanyu Aug 9, 2019
95f29ed
Add unit tests
chenquanyu Aug 12, 2019
5cf6095
Add Network Fee calculate for TxManager,
chenquanyu Aug 13, 2019
afd639b
merge
chenquanyu Aug 13, 2019
77b1fc3
Merge remote-tracking branch 'erik/master'
chenquanyu Aug 13, 2019
51a750b
adjust cosigners change
chenquanyu Aug 13, 2019
5a56d77
Merge branch 'dev'
chenquanyu Aug 13, 2019
1915d63
PR Correction
chenquanyu Aug 14, 2019
1acf3b8
Remove empty line
shargon Aug 14, 2019
b20b709
Rename TxManager to TransactionManager
chenquanyu Aug 15, 2019
f7b3593
PR correction
chenquanyu Aug 15, 2019
9af213e
PR correction
chenquanyu Aug 15, 2019
f74506b
change namespace
chenquanyu Aug 16, 2019
c00ae4f
Merge branch 'master' into master
erikzhang Aug 18, 2019
e61e764
Reorder methods
erikzhang Aug 18, 2019
32ee856
Remove TransactionContext
chenquanyu Aug 19, 2019
d6c1a21
fix unit test
chenquanyu Aug 19, 2019
d4945a8
Remove `virtual`
erikzhang Aug 19, 2019
9d66d1a
Remove virtuals
chenquanyu Aug 19, 2019
f3bfc67
Remove ScriptHash from KeyPair
chenquanyu Aug 19, 2019
8f7e82b
Merge branch 'master' into master
shargon Aug 19, 2019
3dfe49e
Add comments
chenquanyu Aug 20, 2019
e3dbb8f
Add comments
chenquanyu Aug 20, 2019
67bdbb3
Merge branch 'master' into master
chenquanyu Aug 21, 2019
ac9f1d7
Merge branch 'master' into master
chenquanyu Aug 26, 2019
83fe56a
Adjust to Neo_Contract_Create parameter
chenquanyu Aug 26, 2019
c44a5cf
use default mainfest
chenquanyu Aug 26, 2019
0c2c9eb
fix unit test
chenquanyu Aug 26, 2019
4a3e0fd
Fix typo
shargon Aug 26, 2019
6ce1e05
use manifest as parameter
chenquanyu Aug 27, 2019
cffe4d6
Merge branch 'master' into master
chenquanyu Aug 27, 2019
38f57e2
add cosigner for nep5 transfer
chenquanyu Aug 28, 2019
636b8dd
Merge branch 'master' into master
chenquanyu Aug 29, 2019
c1bda72
code clean
chenquanyu Aug 29, 2019
f930237
Update neo.UnitTests/Network/RPC/UT_RpcClient.cs
chenquanyu Aug 29, 2019
05d43c7
move MakeScript to VM.Helper
chenquanyu Aug 30, 2019
205dc2c
Merge branch 'master' into master
chenquanyu Sep 2, 2019
f243c88
Merge branch 'master' into master
chenquanyu Sep 9, 2019
e8c3efe
Add unit test for InteropInterface
chenquanyu Sep 10, 2019
42c418d
Merge branch 'master' into master
shargon Sep 11, 2019
971a1dd
PR Correction
chenquanyu Sep 11, 2019
cd985f0
Add unit test
chenquanyu Sep 11, 2019
6f1b250
Merge branch 'master' into master
shargon Sep 16, 2019
5e034f9
Merge remote-tracking branch 'erik/master'
chenquanyu Sep 23, 2019
5620f9c
Add NeoAPI for RPC module
chenquanyu Sep 23, 2019
3ee8e44
add methods
chenquanyu Sep 24, 2019
02457b2
change parameter type
chenquanyu Sep 24, 2019
8ad9541
Add hashes parameter for invokescript to pass CheckWitness
chenquanyu Sep 25, 2019
af2644e
add methods and unit tests
chenquanyu Sep 25, 2019
55d7e00
code format
chenquanyu Sep 25, 2019
6a49611
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Sep 25, 2019
47e4b83
code clean
chenquanyu Sep 26, 2019
0c2e028
expose RpcClient in NeoAPI
chenquanyu Sep 27, 2019
95a5e26
Merge remote-tracking branch 'erik/master' into dev
chenquanyu Sep 29, 2019
56dc96b
Merge remote-tracking branch 'erik/master'
chenquanyu Oct 8, 2019
3598afa
Merge branch 'master' of https://github.com/chenquanyu/neo
joeqian10 Oct 9, 2019
31089b9
pr correction
chenquanyu Oct 14, 2019
271564f
Merge branch 'master' of https://github.com/chenquanyu/neo
chenquanyu Oct 14, 2019
ca2e235
add overflow exception
chenquanyu Oct 14, 2019
b53d040
provide methods using real types in NeoAPI
chenquanyu Oct 16, 2019
cf6fe4e
Merge branch 'master' into master
chenquanyu Oct 16, 2019
82418e5
fix merge issues
chenquanyu Oct 16, 2019
3c69deb
Merge branch 'master' into master
vncoelho Oct 16, 2019
caced77
Merge branch 'master' into master
chenquanyu Oct 22, 2019
00b6a8c
pr correction
chenquanyu Oct 22, 2019
a40a8ee
Merge branch 'master' of https://github.com/chenquanyu/neo
chenquanyu Oct 22, 2019
f7d3dd6
rename NeoAPI to RpcClientTools
chenquanyu Oct 22, 2019
061ecef
Merge branch 'master' into master
chenquanyu Oct 23, 2019
a077b24
fix issue
chenquanyu Oct 23, 2019
2a7c879
Merge branch 'master' of https://github.com/chenquanyu/neo
chenquanyu Oct 23, 2019
636988b
make the code compatible with the old version
chenquanyu Oct 24, 2019
f824990
Merge branch 'master' into master
chenquanyu Oct 24, 2019
cc9cc3c
Merge branch 'master' of https://github.com/chenquanyu/neo
chenquanyu Oct 24, 2019
ff03536
decoupling the RpcClientTools with other APIs
chenquanyu Oct 24, 2019
8d8c1e8
Merge branch 'master' into master
chenquanyu Oct 24, 2019
8505999
pr correction
chenquanyu Oct 24, 2019
21cf27b
merge
chenquanyu Oct 24, 2019
41c738f
merge unit test
chenquanyu Oct 24, 2019
d330f51
wait transaction state
chenquanyu Oct 28, 2019
0541ca0
wait until confirmation
chenquanyu Oct 28, 2019
e42e38a
Merge branch 'master' into master
chenquanyu Nov 4, 2019
16f7d31
Merge branch 'master' into master
chenquanyu Nov 5, 2019
ace51b0
PR correction
chenquanyu Nov 5, 2019
79e74c6
Update Helper.cs
shargon Nov 6, 2019
4206aa6
Merge branch 'master' into master
shargon Nov 6, 2019
bd45a30
Merge branch 'master' into master
chenquanyu Nov 7, 2019
004fbbe
pr correction
chenquanyu Nov 7, 2019
e1f4483
Merge branch 'master' into master
shargon Nov 7, 2019
e280d37
Format
shargon Nov 7, 2019
4959114
Merge branch 'master' into master
shargon Nov 7, 2019
6abf3c2
pr correction
chenquanyu Nov 8, 2019
54f5a7b
Merge branch 'master' into master
chenquanyu Nov 11, 2019
a0409f0
Merge branch 'master' into master
erikzhang Nov 13, 2019
5bd5b21
Move methods
erikzhang Nov 13, 2019
404e654
Merge branch 'master' into master
shargon Nov 13, 2019
c2c2e47
Merge branch 'master' into master
chenquanyu Nov 14, 2019
3c2c265
Merge branch 'master' into master
erikzhang Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,4 @@ paket-files/
*.sln.iml

PublishProfiles
/.vscode
11 changes: 1 addition & 10 deletions neo.UnitTests/Network/RPC/UT_ContractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ public void TestSetup()
rpcClientMock = UT_TransactionManager.MockRpcClient(sender, new byte[0]);
}

[TestMethod]
public void TestMakeScript()
{
byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero);

Assert.AreEqual("14000000000000000000000000000000000000000051c10962616c616e63654f66142582d1b275e86c8f0e93a9b2facd5fdb760976a168627d5b52",
testScript.ToHexString());
}

[TestMethod]
public void TestInvoke()
{
Expand Down Expand Up @@ -60,7 +51,7 @@ public void TestDeployContract()
UT_TransactionManager.MockInvokeScript(rpcClientMock, script, new ContractParameter());

ContractClient contractClient = new ContractClient(rpcClientMock.Object);
var result = contractClient.DeployContract(new byte[1], manifest, keyPair1);
var result = contractClient.CreateDeployContractTx(new byte[1], manifest, keyPair1);

Assert.IsNotNull(result);
}
Expand Down
29 changes: 29 additions & 0 deletions neo.UnitTests/Network/RPC/UT_Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Network.RPC;
using System;
using System.Numerics;

namespace Neo.UnitTests.Network.RPC
{
[TestClass]
public class UT_Helper
{
[TestMethod]
public void TestToBigInteger()
{
decimal amount = 1.23456789m;
uint decimals = 9;
var result = amount.ToBigInteger(decimals);
Assert.AreEqual(1234567890, result);

amount = 1.23456789m;
decimals = 18;
result = amount.ToBigInteger(decimals);
Assert.AreEqual(BigInteger.Parse("1234567890000000000"), result);

amount = 1.23456789m;
decimals = 4;
Assert.ThrowsException<OverflowException>(() => result = amount.ToBigInteger(decimals));
}
}
}
25 changes: 24 additions & 1 deletion neo.UnitTests/Network/RPC/UT_Nep5API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System.Linq;
using System.Numerics;

namespace Neo.UnitTests.Network.RPC
Expand Down Expand Up @@ -76,13 +77,35 @@ public void TestGetTotalSupply()
Assert.AreEqual(1_00000000, (int)result);
}

[TestMethod]
public void TestGetTokenInfo()
{
UInt160 scriptHash = NativeContract.GAS.Hash;
byte[] testScript = scriptHash.MakeScript("name")
.Concat(scriptHash.MakeScript("symbol"))
.Concat(scriptHash.MakeScript("decimals"))
.Concat(scriptHash.MakeScript("totalSupply"))
.ToArray(); ;
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript,
new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Name },
new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol },
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.GAS.Decimals) },
new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) });

var result = nep5API.GetTokenInfo(NativeContract.GAS.Hash);
Assert.AreEqual(NativeContract.GAS.Name, result.Name);
Assert.AreEqual(NativeContract.GAS.Symbol, result.Symbol);
Assert.AreEqual(8, (int)result.Decimals);
Assert.AreEqual(1_00000000, (int)result.TotalSupply);
}

[TestMethod]
public void TestTransfer()
{
byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000));
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter());

var result = nep5API.Transfer(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000));
var result = nep5API.CreateTransferTx(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000));
Assert.IsNotNull(result);
}
}
Expand Down
50 changes: 21 additions & 29 deletions neo.UnitTests/Network/RPC/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ public void TestGetBlockHex()
{
JObject response = CreateResponse(1);
response["result"] = "000000002deadfa82cbc4682f5800";

MockResponse(response.ToString());
var result = rpc.GetBlockHex("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual("000000002deadfa82cbc4682f5800", result);

MockResponse(response.ToString());
result = rpc.GetBlockHex("100");
var result = rpc.GetBlockHex("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual("000000002deadfa82cbc4682f5800", result);
}

Expand All @@ -134,20 +130,15 @@ public void TestGetBlock()
};

JObject json = block.ToJson();
json["confirmations"] = 20;
JObject response = CreateResponse(1);
response["result"] = json;

MockResponse(response.ToString());
var result = rpc.GetBlock("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual(block.Hash.ToString(), result.Block.Hash.ToString());
Assert.IsNull(result.Confirmations);
Assert.AreEqual(block.Transactions.Length, result.Block.Transactions.Length);
Assert.AreEqual(block.Transactions[0].Hash.ToString(), result.Block.Transactions[0].Hash.ToString());

MockResponse(response.ToString());
result = rpc.GetBlock("100");
var result = rpc.GetBlock("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual(block.Hash.ToString(), result.Block.Hash.ToString());
Assert.IsNull(result.Confirmations);
Assert.IsNull(result.NextBlockHash);
Assert.AreEqual(20, result.Confirmations);
Assert.AreEqual(block.Transactions.Length, result.Block.Transactions.Length);
Assert.AreEqual(block.Transactions[0].Hash.ToString(), result.Block.Transactions[0].Hash.ToString());

Expand All @@ -158,6 +149,7 @@ public void TestGetBlock()
result = rpc.GetBlock("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual(block.Hash.ToString(), result.Block.Hash.ToString());
Assert.AreEqual(20, result.Confirmations);
Assert.AreEqual("0x773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e", result.NextBlockHash.ToString());
Assert.AreEqual(block.Transactions.Length, result.Block.Transactions.Length);
Assert.AreEqual(block.Transactions[0].Hash.ToString(), result.Block.Transactions[0].Hash.ToString());
}
Expand Down Expand Up @@ -189,13 +181,9 @@ public void TestGetBlockHeaderHex()
{
JObject response = CreateResponse(1);
response["result"] = "0x4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2";

MockResponse(response.ToString());
var result = rpc.GetBlockHeaderHex("100");
Assert.AreEqual("0x4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2", result);

MockResponse(response.ToString());
result = rpc.GetBlockHeaderHex("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
var result = rpc.GetBlockHeaderHex("100");
Assert.AreEqual("0x4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2", result);
}

Expand All @@ -206,18 +194,15 @@ public void TestGetBlockHeader()
TestUtils.SetupHeaderWithValues(header, UInt256.Zero, out UInt256 _, out UInt160 _, out ulong _, out uint _, out Witness _);

JObject json = header.ToJson();
json["confirmations"] = 20;
JObject response = CreateResponse(1);
response["result"] = json;
MockResponse(response.ToString());

var result = rpc.GetBlockHeader("100");
Assert.AreEqual(header.Hash.ToString(), result.Header.Hash.ToString());
Assert.IsNull(result.Confirmations);

MockResponse(response.ToString());
result = rpc.GetBlockHeader("773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e");
Assert.AreEqual(header.Hash.ToString(), result.Header.Hash.ToString());
Assert.IsNull(result.Confirmations);
Assert.IsNull(result.NextBlockHash);
Assert.AreEqual(20, result.Confirmations);

json["confirmations"] = 20;
json["nextblockhash"] = "4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2";
Expand Down Expand Up @@ -373,9 +358,18 @@ public void TestGetRawTransaction()
Assert.AreEqual(transaction.Hash, result.Transaction.Hash);
Assert.AreEqual(json.ToString(), result.ToJson().ToString());

// make the code compatible with the old version
json["blockhash"] = UInt256.Zero.ToString();
json["confirmations"] = 100;
json["blocktime"] = 10;
MockResponse(response.ToString());

result = rpc.GetRawTransaction("0x9786cce0dddb524c40ddbdd5e31a41ed1f6b5c8a683c122f627ca4a007a7cf4e");
Assert.AreEqual(transaction.Hash, result.Transaction.Hash);
Assert.AreEqual(100, result.Confirmations);
Assert.AreEqual(null, result.VMState);
Assert.AreEqual(json.ToString(), result.ToJson().ToString());

json["vmState"] = VMState.HALT;
MockResponse(response.ToString());

Expand Down Expand Up @@ -472,8 +466,7 @@ public void TestInvokeFunction()
""type"": ""ByteArray"",
""value"": ""262bec084432""
}
],
""tx"":""d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000""
]
}");
JObject response = CreateResponse(1);
response["result"] = json;
Expand All @@ -496,8 +489,7 @@ public void TestInvokeScript()
""type"": ""ByteArray"",
""value"": ""262bec084432""
}
],
""tx"":""d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000""
]
}");
JObject response = CreateResponse(1);
response["result"] = json;
Expand Down
5 changes: 2 additions & 3 deletions neo.UnitTests/Network/RPC/UT_TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ public static void MockInvokeScript(Mock<RpcClient> mockClient, byte[] script, p
Stack = parameters,
GasConsumed = "100",
Script = script.ToHexString(),
State = "",
Tx = ""
State = ""
};

mockClient.Setup(p => p.RpcSend("invokescript", It.Is<JObject>(j => j.AsString() == script.ToHexString())))
mockClient.Setup(p => p.RpcSend("invokescript", It.Is<JObject[]>(j => j[0].AsString() == script.ToHexString())))
.Returns(result.ToJson())
.Verifiable();
}
Expand Down
116 changes: 116 additions & 0 deletions neo.UnitTests/Network/RPC/UT_WalletAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.IO.Json;
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC;
using Neo.Network.RPC.Models;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System.Numerics;

namespace Neo.UnitTests.Network.RPC
{
[TestClass]
public class UT_WalletAPI
{
Mock<RpcClient> rpcClientMock;
KeyPair keyPair1;
string address1;
UInt160 sender;
WalletAPI walletAPI;

[TestInitialize]
public void TestSetup()
{
keyPair1 = new KeyPair(Wallet.GetPrivateKeyFromWIF("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"));
sender = Contract.CreateSignatureRedeemScript(keyPair1.PublicKey).ToScriptHash();
address1 = Neo.Wallets.Helper.ToAddress(sender);
rpcClientMock = UT_TransactionManager.MockRpcClient(sender, new byte[0]);
walletAPI = new WalletAPI(rpcClientMock.Object);
}

[TestMethod]
public void TestGetUnclaimedGas()
{
byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", sender, 99);
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) });

var balance = walletAPI.GetUnclaimedGas(address1);
Assert.AreEqual(1.1m, balance);
}

[TestMethod]
public void TestGetNeoBalance()
{
byte[] testScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender);
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) });

var balance = walletAPI.GetNeoBalance(address1);
Assert.AreEqual(1_00000000u, balance);
}

[TestMethod]
public void TestGetGasBalance()
{
byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", sender);
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) });

var balance = walletAPI.GetGasBalance(address1);
Assert.AreEqual(1.1m, balance);
}

[TestMethod]
public void TestGetTokenBalance()
{
byte[] testScript = UInt160.Zero.MakeScript("balanceOf", sender);
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) });

var balance = walletAPI.GetTokenBalance(UInt160.Zero.ToString(), address1);
Assert.AreEqual(1_10000000, balance);
}

[TestMethod]
public void 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));
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) });

rpcClientMock.Setup(p => p.RpcSend("sendrawtransaction", It.IsAny<JObject>())).Returns(true);

var tranaction = walletAPI.ClaimGas(keyPair1.Export());
Assert.AreEqual(testScript.ToHexString(), tranaction.Script.ToHexString());
}

[TestMethod]
public void 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);
UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) });

rpcClientMock.Setup(p => p.RpcSend("sendrawtransaction", It.IsAny<JObject>())).Returns(true);

var tranaction = walletAPI.Transfer(NativeContract.GAS.Hash.ToString(), keyPair1.Export(), UInt160.Zero.ToAddress(), 100, 1.1m);
Assert.AreEqual(testScript.ToHexString(), tranaction.Script.ToHexString());
}

[TestMethod]
public void TestWaitTransaction()
{
Transaction transaction = TestUtils.GetTransaction();
rpcClientMock.Setup(p => p.RpcSend("getrawtransaction", It.Is<JObject[]>(j => j[0].AsString() == transaction.Hash.ToString())))
.Returns(new RpcTransaction { Transaction = transaction, VMState = VMState.HALT, BlockHash = UInt256.Zero, BlockTime = 100, Confirmations = 1 }.ToJson());

var tx = walletAPI.WaitTransaction(transaction).Result;
Assert.AreEqual(VMState.HALT, tx.VMState);
Assert.AreEqual(UInt256.Zero, tx.BlockHash);
}
}
}
Loading