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

Fix RPC module UTs. #1

Merged
merged 1 commit into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/RpcClient/TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private long CalculateNetworkFee()
{
long networkFee = 0;
UInt160[] hashes = Tx.GetScriptHashesForVerifying(null);
int size = Transaction.HeaderSize + Tx.Attributes.GetVarSize() + Tx.Cosigners.GetVarSize() + Tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length);
int size = Transaction.HeaderSize + Tx.Attributes.GetVarSize() + Tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length);
foreach (UInt160 hash in hashes)
{
byte[] witness_script = null;
Expand Down
34 changes: 13 additions & 21 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Request": {
"jsonrpc": "2.0",
"method": "sendrawtransaction",
"params": [ "00b5077e7bb8cef712d3f9b3ec90d36e7bf8d50ac81718a3b000e1f5050000000080778e0600000000e31420000001b8cef712d3f9b3ec90d36e7bf8d50ac81718a3b0015c0300e40b54020000000c1400000000000000000000000000000000000000000c14b8cef712d3f9b3ec90d36e7bf8d50ac81718a3b013c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5201420c4077a5ffdc41dce3b06418879a26bac0fcea06af4a833446c90f63a3e80b85d13e07ca9084989e7c7e4535187409058dc7233ba8ee4638593605134e2c2c8f3c9f290c2102f9ec1fd0a98796cf75b586772a4ddd41a0af07a1dbdf86a7238f74fb725035750b410a906ad4" ],
"params": [ "00b5077e7bb8cef712d3f9b3ec90d36e7bf8d50ac81718a3b000e1f5050000000080778e0600000000e3142000005c0300e40b54020000000c1400000000000000000000000000000000000000000c14b8cef712d3f9b3ec90d36e7bf8d50ac81718a3b013c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5201420c4077a5ffdc41dce3b06418879a26bac0fcea06af4a833446c90f63a3e80b85d13e07ca9084989e7c7e4535187409058dc7233ba8ee4638593605134e2c2c8f3c9f290c2102f9ec1fd0a98796cf75b586772a4ddd41a0af07a1dbdf86a7238f74fb725035750b410a906ad4" ],
"id": 1
},
"Response": {
Expand Down Expand Up @@ -72,7 +72,7 @@
"id": 1,
"result": {
"hash": "0xe191fe1aea732c3e23f20af8a95e09f95891176f8064a2fce8571d51f80619a8",
"size": 171,
"size": 170,
"version": 0,
"previousblockhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"merkleroot": "0x735b68ca1bab490b8fd6166cba4c2ce76e97bedfe4d2df0c333970fc9862bb2b",
Expand All @@ -91,16 +91,15 @@
},
"tx": [
{
"hash": "0x019befa728a371a08fb0f78330b3c697ebc9d8bbf252bd173b17cc2bd6e97e9c",
"size": 57,
"hash": "0x55808e2014b486a607a4617c81a6f5060ec363eff6cfc80210221b2e8a1f1013",
"size": 56,
"version": 0,
"nonce": 0,
"sender": "NeN4xPMn4kHoj7G8Lciq9oorgLTvqt4qi1",
"sys_fee": "0",
"net_fee": "0",
"valid_until_block": 0,
"attributes": [],
"cosigners": [],
"script": "QRI+f+g=",
"witnesses": [
{
Expand Down Expand Up @@ -128,7 +127,7 @@
"id": 1,
"result": {
"hash": "0xe191fe1aea732c3e23f20af8a95e09f95891176f8064a2fce8571d51f80619a8",
"size": 171,
"size": 170,
"version": 0,
"previousblockhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"merkleroot": "0x735b68ca1bab490b8fd6166cba4c2ce76e97bedfe4d2df0c333970fc9862bb2b",
Expand All @@ -147,16 +146,15 @@
},
"tx": [
{
"hash": "0x019befa728a371a08fb0f78330b3c697ebc9d8bbf252bd173b17cc2bd6e97e9c",
"size": 57,
"hash": "0x55808e2014b486a607a4617c81a6f5060ec363eff6cfc80210221b2e8a1f1013",
"size": 56,
"version": 0,
"nonce": 0,
"sender": "NeN4xPMn4kHoj7G8Lciq9oorgLTvqt4qi1",
"sys_fee": "0",
"net_fee": "0",
"valid_until_block": 0,
"attributes": [],
"cosigners": [],
"script": "QRI+f+g=",
"witnesses": [
{
Expand Down Expand Up @@ -489,36 +487,30 @@
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": "004cdec1396925aa554712439a9c613ba114efa3fac23ddbca00e1f50500000000466a130000000000311d200000016925aa554712439a9c613ba114efa3fac23ddbca015d030010a5d4e80000000c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b523901420c401f85b40d7fa12164aa1d4d18b06ca470f2c89572dc5b901ab1667faebb587cf536454b98a09018adac72376c5e7c5d164535155b763564347aa47b69aa01b3cc290c2103aa052fbcb8e5b33a4eefd662536f8684641f04109f1d5e69cdda6f084890286a0b410a906ad4"
"result": "004cdec1396925aa554712439a9c613ba114efa3fac23ddbca00e1f50500000000466a130000000000311d2000005d030010a5d4e80000000c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b523901420c401f85b40d7fa12164aa1d4d18b06ca470f2c89572dc5b901ab1667faebb587cf536454b98a09018adac72376c5e7c5d164535155b763564347aa47b69aa01b3cc290c2103aa052fbcb8e5b33a4eefd662536f8684641f04109f1d5e69cdda6f084890286a0b410a906ad4"
}
},
{
"Name": "getrawtransaction",
"Request": {
"jsonrpc": "2.0",
"method": "getrawtransaction",
"params": [ "0x0cfd49c48306f9027dc71585589b6456bcc53567c359fb7858eabca482186b78", true ],
"params": [ "0x4d47255ff5564aaa73855068c3574f8f28e2bb18c7fb7256e58ae51fab44c9bc", true ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"hash": "0x0cfd49c48306f9027dc71585589b6456bcc53567c359fb7858eabca482186b78",
"size": 272,
"hash": "0x4d47255ff5564aaa73855068c3574f8f28e2bb18c7fb7256e58ae51fab44c9bc",
"size": 250,
"version": 0,
"nonce": 969006668,
"sender": "NVVwFw6XyhtRCFQ8SpUTMdPyYt4Vd9A1XQ",
"sys_fee": "100000000",
"net_fee": "1272390",
"valid_until_block": 2104625,
"attributes": [],
"cosigners": [
{
"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569",
"scopes": "CalledByEntry"
}
],
"script": "AwAQpdToAAAADBSZA7DD0pKYj+vl8wagL2VOousWKQwUaSWqVUcSQ5qcYTuhFO+j+sI928oTwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I5",
"witnesses": [
{
Expand Down Expand Up @@ -667,14 +659,14 @@
"Request": {
"jsonrpc": "2.0",
"method": "sendrawtransaction",
"params": [ "00142449186925aa554712439a9c613ba114efa3fac23ddbca00e1f50500000000a65a1300000000001d20200000016925aa554712439a9c613ba114efa3fac23ddbca01590200e1f5050c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b523901420c4076507ef5922e84aac57f09cb699ecbb10bc3d9c06ef908bed812c35fd2651531de27091f1e6e81566454fcc1c5f129d1051b08704c3fec3f6ed793563cfd30bb290c2103aa052fbcb8e5b33a4eefd662536f8684641f04109f1d5e69cdda6f084890286a0b410a906ad4" ],
"params": [ "00142449186925aa554712439a9c613ba114efa3fac23ddbca00e1f50500000000a65a1300000000001d20200000590200e1f5050c149903b0c3d292988febe5f306a02f654ea2eb16290c146925aa554712439a9c613ba114efa3fac23ddbca13c00c087472616e736665720c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b523901420c4076507ef5922e84aac57f09cb699ecbb10bc3d9c06ef908bed812c35fd2651531de27091f1e6e81566454fcc1c5f129d1051b08704c3fec3f6ed793563cfd30bb290c2103aa052fbcb8e5b33a4eefd662536f8684641f04109f1d5e69cdda6f084890286a0b410a906ad4" ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"hash": "0x32cda8771aca33da2f7a022b33468fd658abd2521b58dd6ba1ffb89883903405"
"hash": "0x4d47255ff5564aaa73855068c3574f8f28e2bb18c7fb7256e58ae51fab44c9bc"
}
}
},
Expand Down
13 changes: 8 additions & 5 deletions tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,34 @@ public void TestMakeTransaction()
{
new Cosigner
{
Scopes= WitnessScope.Global
Account = sender,
Scopes= WitnessScope.Global
}
};

byte[] script = new byte[1];
txManager.MakeTransaction(script, attributes);

var tx = txManager.Tx;
Assert.AreEqual(WitnessScope.Global, (tx.Attributes[0] as Cosigner));
Assert.AreEqual(WitnessScope.Global, (tx.Attributes[0] as Cosigner).Scopes);
}

[TestMethod]
public void TestSign()
{
txManager = new TransactionManager(rpcClientMock.Object, sender);

Cosigner[] cosigners = new Cosigner[1] {
new Cosigner{
var attributes = new TransactionAttribute[1]
{
new Cosigner
{
Account = sender,
Scopes = WitnessScope.Global
}
};

byte[] script = new byte[1];
txManager.MakeTransaction(script, cosigners)
txManager.MakeTransaction(script, attributes)
.AddSignature(keyPair1)
.Sign();

Expand Down