Skip to content

Commit

Permalink
Update oracles branch (#1242)
Browse files Browse the repository at this point in the history
* Fix GetTransactionFromBlock Syscall (#1170)

* Fix Syscall

* Fix

* Unit Test for Smartcontract Module (#1090)

* submit ut

* fix

* Enhance functions in TestDataCache

* git amend blockchain

* fix test related to TestDataCache

* dotnet format

* dotnet format

* add blank line

* fix test

* Optimize random

* Optimize Random

* fix test

* add decimal test

* fix

* 2019/9/25 16:54

change format

* Fixes events

* update assertion sentence

* update UT following code change

* format

* add type check

* recommit

* recommit

* Ensure txs are cleared before Blockchain actor (#1166)

* Unit Test For RPC Module (#1111)

* fix payload limits (#1194)

* Fix JsonSerializer (#1197)

* Fix #1128 (#1129)

* Fix #1128

* Update BlockBase.cs

* Add shutdown event for plugins (#1195)

* add shutdown event for plugins

* use IDisposable

* dispose plugins first

* Removing brackets

* Replace function exceptwith and unionwith with faster functions  (#1174)

* Replace ExceptWith & UnionWith with equal but faster functionality

* Optimization

* Optimization

* Optimize remove

* Update neo/Network/P2P/TaskManager.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Code optimization

* Update Helper.cs

* Small change

* Optimization

* Update Helper.cs

* Revert

* Optimization

* Optimize FIFOSet

* Rename

* Inline

* Update UT_FIFOSet.cs

* Fix

* Update UT_FIFOSet.cs

* Update FIFOSet.cs

* Update FIFOSet.cs

* Revert FIFOSet

* Update Helper.cs

* Optimize

* Reverting independet byte checks to SequenceEqual

* Unit tests for some auxiliary classes (#1192)

* Fix p2p filter unconnected peers (#1160)

* Remove the case of GetData in ProtocolHandlerMailbox#ShallDrop (#1201)

* Add GetFullBlocks P2P logic (enable fixing #522) (#1138)

* add GetFullBlocks P2P logic

* add missing new line

* allow request genesis block

* Optimization

* Update MessageCommand.cs

* - rename command
- fix protocol handler cast
- fix payload deserialization for default value

* change to ushort per review

* remove default count, rename class

* typo + failed refactor coverage ¯\_(ツ)_/¯

* Use base64 in JsonSerializer (#1199)

* Base64 Json

* No format

* Json Transaction optimization

* Change to Base64

* Revert some changes

* Revert

* Remove Helper.Base64

* Remove Base64FormattingOptions.None

* Optimize MerkleTree (3x) (#1203)

* Optimize MerkleTree

* Update MerkleTree.cs

* Update MerkleTree.cs

* Added more verbosity to CN logs (#1202)

* Add reason log for cn

* Update ConsensusService.cs

* Keep track of sender fee (#1183)

* Keep track of sender fee to avoid duplicate computation

* Code optimization

* Optimize

* Optimize

* Optimize

* Code optimization

* Correction

* Renaming currentFee to totalSenderFeeFromPool

* Renaming on Verify as well

* Add consideration for null Transactions

* Move sender fee recording systems to class SendersMonitor

* Code optimization

* Capitalize public items

* Code optimization

* Code optimization

* Optimization

* Code optimization

* Using problem description (#1214)

Using problem description helps problem grouping (people may propose different solutions for the same problem)

* Improve SYSCALLs: `Neo.Crypto.*` (#1190)

* Prevent XXE (3x) (#1229)

* Remove unnecessary logic from Mempool (#1216)

* Prevent remove storage flag when there are something stored (#1227)

* Add NeoAPI and update code after testing with NEO3 preview1 (#1150)
  • Loading branch information
shargon authored Nov 14, 2019
1 parent 4112df2 commit 72f50cb
Show file tree
Hide file tree
Showing 126 changed files with 6,285 additions and 296 deletions.
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

0 comments on commit 72f50cb

Please sign in to comment.