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

Update oracles branch #1242

Merged
merged 23 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e53f533
Fix GetTransactionFromBlock Syscall (#1170)
shargon Oct 22, 2019
0ed69cd
Unit Test for Smartcontract Module (#1090)
eryeer Oct 23, 2019
ae7b319
Ensure txs are cleared before Blockchain actor (#1166)
vncoelho Oct 24, 2019
cd85039
Unit Test For RPC Module (#1111)
eryeer Oct 24, 2019
c9e8532
fix payload limits (#1194)
ixje Oct 29, 2019
0aed29f
Fix JsonSerializer (#1197)
erikzhang Oct 30, 2019
1b7d1ec
Fix #1128 (#1129)
igormcoelho Oct 30, 2019
b7be2c7
Add shutdown event for plugins (#1195)
ixje Oct 31, 2019
1c84f7c
Replace function exceptwith and unionwith with faster functions (#1174)
Qiao-Jin Nov 5, 2019
0a7cba7
Unit tests for some auxiliary classes (#1192)
eryeer Nov 6, 2019
425fd73
Fix p2p filter unconnected peers (#1160)
Nov 7, 2019
4aff0d3
Remove the case of GetData in ProtocolHandlerMailbox#ShallDrop (#1201)
doubiliu Nov 7, 2019
87aed99
Add GetFullBlocks P2P logic (enable fixing #522) (#1138)
ixje Nov 7, 2019
1dc262f
Use base64 in JsonSerializer (#1199)
shargon Nov 7, 2019
85c0013
Optimize MerkleTree (3x) (#1203)
shargon Nov 7, 2019
f70a76d
Added more verbosity to CN logs (#1202)
shargon Nov 8, 2019
f1d6434
Keep track of sender fee (#1183)
Qiao-Jin Nov 10, 2019
c7a7de7
Using problem description (#1214)
lock9 Nov 12, 2019
927683d
Improve SYSCALLs: `Neo.Crypto.*` (#1190)
erikzhang Nov 13, 2019
0d18b34
Prevent XXE (3x) (#1229)
shargon Nov 13, 2019
7c6a147
Remove unnecessary logic from Mempool (#1216)
vncoelho Nov 13, 2019
69f3f15
Prevent remove storage flag when there are something stored (#1227)
shargon Nov 14, 2019
72be7f6
Add NeoAPI and update code after testing with NEO3 preview1 (#1150)
chenquanyu 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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-or-enhancement-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ labels: discussion
assignees: ''
---

**Summary**
**Summary or problem description**
A summary of the problem you want to solve or metric you want to improve

**Do you have any solution you want to propose?**
Expand Down
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
18 changes: 18 additions & 0 deletions neo.UnitTests/IO/Caching/UT_FIFOSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public void TestExceptWith()
};
set.ExceptWith(new UInt256[] { b, c });
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a });

set = new FIFOSet<UInt256>(10)
{
a,
b,
c
};
set.ExceptWith(new UInt256[] { a });
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { b, c });

set = new FIFOSet<UInt256>(10)
{
a,
b,
c
};
set.ExceptWith(new UInt256[] { c });
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, b });
}
}
}
27 changes: 27 additions & 0 deletions neo.UnitTests/IO/UT_ByteArrayComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;

namespace Neo.UnitTests.IO
{
[TestClass]
public class UT_ByteArrayComparer
{
[TestMethod]
public void TestCompare()
{
ByteArrayComparer comparer = new ByteArrayComparer();
byte[] x = new byte[0], y = new byte[0];
comparer.Compare(x, y).Should().Be(0);

x = new byte[] { 1 };
comparer.Compare(x, y).Should().Be(1);
y = x;
comparer.Compare(x, y).Should().Be(0);

x = new byte[] { 1 };
y = new byte[] { 2 };
comparer.Compare(x, y).Should().Be(-1);
}
}
}
6 changes: 3 additions & 3 deletions neo.UnitTests/Ledger/UT_Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public void TestContainsTransaction()
[TestMethod]
public void TestGetCurrentBlockHash()
{
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb"));
Blockchain.Singleton.CurrentBlockHash.Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c"));
}

[TestMethod]
public void TestGetCurrentHeaderHash()
{
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb"));
Blockchain.Singleton.CurrentHeaderHash.Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c"));
}

[TestMethod]
Expand All @@ -88,7 +88,7 @@ public void TestGetBlock()
[TestMethod]
public void TestGetBlockHash()
{
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("5662a113d8fa9532ea9c52046a463e2e3fcfcdd6192d99cad805b376fb643ceb"));
Blockchain.Singleton.GetBlockHash(0).Should().Be(UInt256.Parse("0x0d492ce0f38090a65b2b01af50f7a6d685b6b76fbc41672762e96b05d15d742c"));
Blockchain.Singleton.GetBlockHash(10).Should().BeNull();
}

Expand Down
4 changes: 2 additions & 2 deletions neo.UnitTests/Ledger/UT_ContractState.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
using Neo.IO.Json;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void TestToJson()
{
JObject json = contract.ToJson();
json["hash"].AsString().Should().Be("0x820944cfdc70976602d71b0091445eedbc661bc5");
json["script"].AsString().Should().Be("01");
json["script"].AsString().Should().Be("AQ==");
json["manifest"].AsString().Should().Be(manifest.ToJson().AsString());
}
}
Expand Down
5 changes: 3 additions & 2 deletions neo.UnitTests/Ledger/UT_MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace Neo.UnitTests.Ledger
{
Expand Down Expand Up @@ -73,8 +74,8 @@ private Transaction CreateTransactionWithFee(long fee)
var randomBytes = new byte[16];
random.NextBytes(randomBytes);
Mock<Transaction> mock = new Mock<Transaction>();
mock.Setup(p => p.Reverify(It.IsAny<Snapshot>(), It.IsAny<IEnumerable<Transaction>>())).Returns(true);
mock.Setup(p => p.Verify(It.IsAny<Snapshot>(), It.IsAny<IEnumerable<Transaction>>())).Returns(true);
mock.Setup(p => p.Reverify(It.IsAny<Snapshot>(), It.IsAny<BigInteger>())).Returns(true);
mock.Setup(p => p.Verify(It.IsAny<Snapshot>(), It.IsAny<BigInteger>())).Returns(true);
mock.Object.Script = randomBytes;
mock.Object.Sender = UInt160.Zero;
mock.Object.NetworkFee = fee;
Expand Down
56 changes: 56 additions & 0 deletions neo.UnitTests/Ledger/UT_SendersFeeMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using System;
using System.Numerics;

namespace Neo.UnitTests.Ledger
{
[TestClass]
public class UT_SendersFeeMonitor
{
private Transaction CreateTransactionWithFee(long networkFee, long systemFee)
{
Random random = new Random();
var randomBytes = new byte[16];
random.NextBytes(randomBytes);
Mock<Transaction> mock = new Mock<Transaction>();
mock.Setup(p => p.Reverify(It.IsAny<Snapshot>(), It.IsAny<BigInteger>())).Returns(true);
mock.Setup(p => p.Verify(It.IsAny<Snapshot>(), It.IsAny<BigInteger>())).Returns(true);
mock.Object.Script = randomBytes;
mock.Object.Sender = UInt160.Zero;
mock.Object.NetworkFee = networkFee;
mock.Object.SystemFee = systemFee;
mock.Object.Attributes = new TransactionAttribute[0];
mock.Object.Cosigners = new Cosigner[0];
mock.Object.Witnesses = new[]
{
new Witness
{
InvocationScript = new byte[0],
VerificationScript = new byte[0]
}
};
return mock.Object;
}

[TestMethod]
public void TestMemPoolSenderFee()
{
Transaction transaction = CreateTransactionWithFee(1, 2);
SendersFeeMonitor sendersFeeMonitor = new SendersFeeMonitor();
sendersFeeMonitor.GetSenderFee(transaction.Sender).Should().Be(0);
sendersFeeMonitor.AddSenderFee(transaction);
sendersFeeMonitor.GetSenderFee(transaction.Sender).Should().Be(3);
sendersFeeMonitor.AddSenderFee(transaction);
sendersFeeMonitor.GetSenderFee(transaction.Sender).Should().Be(6);
sendersFeeMonitor.RemoveSenderFee(transaction);
sendersFeeMonitor.GetSenderFee(transaction.Sender).Should().Be(3);
sendersFeeMonitor.RemoveSenderFee(transaction);
sendersFeeMonitor.GetSenderFee(transaction.Sender).Should().Be(0);
}
}
}
2 changes: 1 addition & 1 deletion neo.UnitTests/Network/P2P/Payloads/UT_Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void ToJson()

JObject scObj = ((JArray)jObj["witnesses"])[0];
scObj["invocation"].AsString().Should().Be("");
scObj["verification"].AsString().Should().Be("51");
scObj["verification"].AsString().Should().Be("UQ==");

jObj["tx"].Should().NotBeNull();
JArray txObj = (JArray)jObj["tx"];
Expand Down
35 changes: 17 additions & 18 deletions neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ public void FeeIsMultiSigContract()
}

var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
Assert.AreEqual(verificationGas, 2000540);
Assert.AreEqual(sizeGas, 358000);
Assert.AreEqual(verificationGas + sizeGas, 2358540);
Assert.AreEqual(tx.NetworkFee, 2358540);
Assert.AreEqual(verificationGas, 2000570);
Assert.AreEqual(sizeGas, 359000);
Assert.AreEqual(tx.NetworkFee, 2359570);
}
}

Expand Down Expand Up @@ -214,7 +213,7 @@ public void FeeIsSignatureContractDetailed()
Assert.IsNull(tx.Witnesses);

// check pre-computed network fee (already guessing signature sizes)
tx.NetworkFee.Should().Be(1257240);
tx.NetworkFee.Should().Be(1258270);

// ----
// Sign
Expand Down Expand Up @@ -251,12 +250,12 @@ public void FeeIsSignatureContractDetailed()
verificationGas += engine.GasConsumed;
}
}
Assert.AreEqual(verificationGas, 1000240);
Assert.AreEqual(verificationGas, 1000270);

// ------------------
// check tx_size cost
// ------------------
Assert.AreEqual(tx.Size, 257);
Assert.AreEqual(tx.Size, 258);

// will verify tx size, step by step

Expand All @@ -272,16 +271,16 @@ public void FeeIsSignatureContractDetailed()
// Part III
Assert.AreEqual(tx.Script.GetVarSize(), 82);
// Part IV
Assert.AreEqual(tx.Witnesses.GetVarSize(), 107);
Assert.AreEqual(tx.Witnesses.GetVarSize(), 108);
// I + II + III + IV
Assert.AreEqual(tx.Size, 45 + 23 + 82 + 107);
Assert.AreEqual(tx.Size, 45 + 23 + 82 + 108);

Assert.AreEqual(NativeContract.Policy.GetFeePerByte(snapshot), 1000);
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
Assert.AreEqual(sizeGas, 257000);
Assert.AreEqual(sizeGas, 258000);

// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1257240);
Assert.AreEqual(verificationGas + sizeGas, 1258270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -372,7 +371,7 @@ public void FeeIsSignatureContract_TestScope_Global()
// get sizeGas
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1257240);
Assert.AreEqual(verificationGas + sizeGas, 1258270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -464,7 +463,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_GAS()
// get sizeGas
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1278240);
Assert.AreEqual(verificationGas + sizeGas, 1279270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -559,7 +558,7 @@ public void FeeIsSignatureContract_TestScope_CalledByEntry_Plus_GAS()
// get sizeGas
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1278240);
Assert.AreEqual(verificationGas + sizeGas, 1279270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -714,7 +713,7 @@ public void FeeIsSignatureContract_TestScope_CurrentHash_NEO_GAS()
// get sizeGas
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1298240);
Assert.AreEqual(verificationGas + sizeGas, 1299270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -798,7 +797,7 @@ public void Transaction_Reverify_Hashes_Length_Unequal_To_Witnesses_Length()
};
UInt160[] hashes = txSimple.GetScriptHashesForVerifying(snapshot);
Assert.AreEqual(2, hashes.Length);
Assert.IsFalse(txSimple.Reverify(snapshot, new Transaction[0]));
Assert.IsFalse(txSimple.Reverify(snapshot, BigInteger.Zero));
}

[TestMethod]
Expand Down Expand Up @@ -1062,7 +1061,7 @@ public void FeeIsSignatureContract_TestScope_Global_Default()
// get sizeGas
var sizeGas = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot);
// final check on sum: verification_cost + tx_size
Assert.AreEqual(verificationGas + sizeGas, 1257240);
Assert.AreEqual(verificationGas + sizeGas, 1258270);
// final assert
Assert.AreEqual(tx.NetworkFee, verificationGas + sizeGas);
}
Expand Down Expand Up @@ -1093,7 +1092,7 @@ public void ToJson()
((JArray)jObj["attributes"]).Count.Should().Be(0);
((JArray)jObj["cosigners"]).Count.Should().Be(0);
jObj["net_fee"].AsString().Should().Be("0");
jObj["script"].AsString().Should().Be("4220202020202020202020202020202020202020202020202020202020202020");
jObj["script"].AsString().Should().Be("QiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA=");
jObj["sys_fee"].AsString().Should().Be("4200000000");
}
}
Expand Down
8 changes: 4 additions & 4 deletions neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public void MaxSize_OK()

// Check max size

witness.Size.Should().Be(1003);
witness.Size.Should().Be(1004);
witness.InvocationScript.GetVarSize().Should().Be(653);
witness.VerificationScript.GetVarSize().Should().Be(350);
witness.VerificationScript.GetVarSize().Should().Be(351);

Assert.IsTrue(witness.Size <= 1024);

Expand Down Expand Up @@ -146,8 +146,8 @@ public void ToJson()
JObject json = uut.ToJson();
Assert.IsTrue(json.ContainsProperty("invocation"));
Assert.IsTrue(json.ContainsProperty("verification"));
Assert.AreEqual(json["invocation"].AsString(), "2020");
Assert.AreEqual(json["verification"].AsString(), "202020");
Assert.AreEqual(json["invocation"].AsString(), "ICA=");
Assert.AreEqual(json["verification"].AsString(), "ICAg");
}
}
}
4 changes: 0 additions & 4 deletions neo.UnitTests/Network/P2P/UT_ProtocolHandlerMailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public void ProtocolHandlerMailbox_Test_ShallDrop()
msg = Message.Create(MessageCommand.Inv, s);
uut.ShallDrop(msg, emptyQueue).Should().Be(false);
uut.ShallDrop(msg, new object[] { msg }).Should().Be(false);
// GetData (drop)
msg = Message.Create(MessageCommand.GetData, s);
uut.ShallDrop(msg, emptyQueue).Should().Be(false);
uut.ShallDrop(msg, new object[] { msg }).Should().Be(true);
// NotFound (no drop)
msg = Message.Create(MessageCommand.NotFound, s);
uut.ShallDrop(msg, emptyQueue).Should().Be(false);
Expand Down
29 changes: 29 additions & 0 deletions neo.UnitTests/Network/RPC/Models/UT_RpcBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC.Models;
using System;

namespace Neo.UnitTests.Network.RPC.Models
{
[TestClass]
public class UT_RpcBlock
{
[TestMethod]
public void TestToJson()
{
var rpcBlock = new RpcBlock();
var block = new Block();
TestUtils.SetupBlockWithValues(block, UInt256.Zero, out UInt256 _, out UInt160 _, out ulong _, out uint _, out Witness _, out Transaction[] _, 1);
rpcBlock.Block = block;
var json = rpcBlock.ToJson();
json["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
json.Should().NotBeNull();

rpcBlock.Confirmations = 1;
rpcBlock.NextBlockHash = UInt256.Zero;
json = rpcBlock.ToJson();
json["confirmations"].AsNumber().Should().Be(1);
}
}
}
Loading