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 #1

Merged
merged 27 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3ef7b5e
Handles escape characters in JSON
erikzhang Jan 1, 2019
c0f1500
Pass ApplicationExecution to IPersistencePlugin (#531)
GulfOfAlaska Jan 1, 2019
338ab7a
Update dependencies: (#532)
erikzhang Jan 2, 2019
40ec6b2
change version to v2.9.4
erikzhang Jan 2, 2019
c16475e
Updating Unknown to Policy Fail (#533)
vncoelho Jan 7, 2019
b1311ba
Fix a dead lock in `WalletIndexer`
erikzhang Jan 9, 2019
8cecbbc
Downgrade Sqlite to 2.1.4 (#535)
vncoelho Jan 9, 2019
b9e38fc
RPC call gettransactionheight (#541)
vncoelho Jan 11, 2019
7488273
Allow to use the wallet inside a RPC plugin (#536)
shargon Jan 11, 2019
5222283
Improve Large MemoryPool Performance - Sort + intelligent TX reverifi…
jsolman Jan 13, 2019
ff174f7
Policy filter GetRelayResult message (#543)
vncoelho Jan 15, 2019
50a7a84
Add some initial MemoryPool unit tests. Fix bug when Persisting the G…
jsolman Jan 16, 2019
ab8bb4d
More MemoryPool Unit Tests. Improve Re-broadcast back-off to an incre…
jsolman Jan 17, 2019
0e5434c
Ensuring Object Reference check of SortedSets for speed-up (#557)
vncoelho Jan 17, 2019
1aeaf86
Minor comments update on Mempool class (#556)
vncoelho Jan 17, 2019
b222995
Update MemoryPool Unit Test to add random fees to Mock Transactions (…
vncoelho Jan 18, 2019
54ff67d
Add Unit Test for MemoryPool sort order. Fixed sort order to return d…
jsolman Jan 18, 2019
6849ac2
Benchmark structure for UInt classes (#553)
igormcoelho Jan 18, 2019
e5d012e
Treat lower hashes as higher priority. Fix MemoryPool UT for Hash ord…
jsolman Jan 18, 2019
370d7a2
Make PoolItem independent and add PoolItem tests (#562)
igormcoelho Jan 19, 2019
7f6e552
Treat Claim transactions as the highest low priority transactions. (#…
jsolman Jan 20, 2019
bbbc0cf
Allow persistence plugins to commit as a final step. (#568)
jsolman Jan 23, 2019
7cf2869
Add a Plugin type for observing transactions added or removed from th…
jsolman Feb 11, 2019
6ae3c6d
Correctly handle conversions between JSON objects (#586)
erikzhang Feb 17, 2019
48890b6
Fix neo-project/neo-cli#297 (#587)
im-kulikov Feb 18, 2019
d9fc9e9
Replace new JArray with .ToArray (AccountState) (#581)
im-kulikov Feb 19, 2019
2bff318
Ensure `LocalNode` to be stoped before shutting down the `NeoSystem`
erikzhang Feb 20, 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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dist: trusty
osx_image: xcode9.1

mono: none
dotnet: 2.0.0
dotnet: 2.1.502

before_install:
- cd neo.UnitTests
Expand Down
16 changes: 14 additions & 2 deletions neo.UnitTests/TestDataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public class TestDataCache<TKey, TValue> : DataCache<TKey, TValue>
where TKey : IEquatable<TKey>, ISerializable
where TValue : class, ICloneable<TValue>, ISerializable, new()
{
private readonly TValue _defaultValue;

public TestDataCache()
{
_defaultValue = null;
}

public TestDataCache(TValue defaultValue)
{
this._defaultValue = defaultValue;
}
public override void DeleteInternal(TKey key)
{
}
Expand All @@ -25,12 +36,13 @@ protected override void AddInternal(TKey key, TValue value)

protected override TValue GetInternal(TKey key)
{
throw new NotImplementedException();
if (_defaultValue == null) throw new NotImplementedException();
return _defaultValue;
}

protected override TValue TryGetInternal(TKey key)
{
return null;
return _defaultValue;
}

protected override void UpdateInternal(TKey key, TValue value)
Expand Down
401 changes: 401 additions & 0 deletions neo.UnitTests/UT_MemoryPool.cs

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions neo.UnitTests/UT_PoolItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Ledger;
using FluentAssertions;
using Neo.Network.P2P.Payloads;

namespace Neo.UnitTests
{
[TestClass]
public class UT_PoolItem
{
//private PoolItem uut;
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism

[TestInitialize]
public void TestSetup()
{
var timeValues = new[] {
new DateTime(1968, 06, 01, 0, 0, 1, DateTimeKind.Utc),
};

var timeMock = new Mock<TimeProvider>();
timeMock.SetupGet(tp => tp.UtcNow).Returns(() => timeValues[0])
.Callback(() => timeValues[0] = timeValues[0].Add(TimeSpan.FromSeconds(1)));
TimeProvider.Current = timeMock.Object;
}

[TestCleanup]
public void TestCleanup()
{
// important to leave TimeProvider correct
TimeProvider.ResetToDefault();
}

[TestMethod]
public void PoolItem_CompareTo_ClaimTx()
{
var tx1 = GenerateClaimTx();
// Non-free low-priority transaction
var tx2 = MockGenerateInvocationTx(new Fixed8(99999), 50).Object;

var poolItem1 = new PoolItem(tx1);
var poolItem2 = new PoolItem(tx2);
poolItem1.CompareTo(poolItem2).Should().Be(1);
poolItem2.CompareTo(poolItem1).Should().Be(-1);
}

[TestMethod]
public void PoolItem_CompareTo_Fee()
{
int size1 = 50;
int netFeeSatoshi1 = 1;
var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshi1), size1);
int size2 = 50;
int netFeeSatoshi2 = 2;
var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshi2), size2);

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

Console.WriteLine($"item1 time {pitem1.Timestamp} item2 time {pitem2.Timestamp}");
// pitem1 < pitem2 (fee) => -1
pitem1.CompareTo(pitem2).Should().Be(-1);
// pitem2 > pitem1 (fee) => 1
pitem2.CompareTo(pitem1).Should().Be(1);
}

[TestMethod]
public void PoolItem_CompareTo_Hash()
{
int sizeFixed = 50;
int netFeeSatoshiFixed = 1;

for (int testRuns = 0; testRuns < 30; testRuns++)
{
var tx1 = GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(0x80, new Fixed8(netFeeSatoshiFixed), sizeFixed);
var tx2 = GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(0x79,new Fixed8(netFeeSatoshiFixed), sizeFixed);

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

// pitem2 < pitem1 (fee) => -1
pitem2.CompareTo(pitem1).Should().Be(-1);

// pitem1 > pitem2 (fee) => 1
pitem1.CompareTo(pitem2).Should().Be(1);
}

// equal hashes should be equal
var tx3 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
var tx4 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
PoolItem pitem3 = new PoolItem(tx3.Object);
PoolItem pitem4 = new PoolItem(tx4.Object);

pitem3.CompareTo(pitem4).Should().Be(0);
pitem4.CompareTo(pitem3).Should().Be(0);
}

[TestMethod]
public void PoolItem_CompareTo_Equals()
{
int sizeFixed = 500;
int netFeeSatoshiFixed = 10;
var tx1 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});
var tx2 = MockGenerateInvocationTx(new Fixed8(netFeeSatoshiFixed), sizeFixed, new byte[] {0x13, 0x37});

PoolItem pitem1 = new PoolItem(tx1.Object);
PoolItem pitem2 = new PoolItem(tx2.Object);

// pitem1 == pitem2 (fee) => 0
pitem1.CompareTo(pitem2).Should().Be(0);
pitem2.CompareTo(pitem1).Should().Be(0);
}

public Mock<InvocationTransaction> GenerateMockTxWithFirstByteOfHashGreaterThanOrEqualTo(byte firstHashByte, Fixed8 networkFee, int size)
{
Mock<InvocationTransaction> mockTx;
do
{
mockTx = MockGenerateInvocationTx(networkFee, size);
} while (mockTx.Object.Hash >= new UInt256(TestUtils.GetByteArray(32, firstHashByte)));

return mockTx;
}

public Mock<InvocationTransaction> GenerateMockTxWithFirstByteOfHashLessThanOrEqualTo(byte firstHashByte, Fixed8 networkFee, int size)
{
Mock<InvocationTransaction> mockTx;
do
{
mockTx = MockGenerateInvocationTx(networkFee, size);
} while (mockTx.Object.Hash <= new UInt256(TestUtils.GetByteArray(32, firstHashByte)));

return mockTx;
}

public static Transaction GenerateClaimTx()
{
var mockTx = new Mock<ClaimTransaction>();
mockTx.CallBase = true;
mockTx.SetupGet(mr => mr.NetworkFee).Returns(Fixed8.Zero);
mockTx.SetupGet(mr => mr.Size).Returns(50);
var tx = mockTx.Object;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];
return mockTx.Object;
}

// Generate Mock InvocationTransaction with different sizes and prices
public static Mock<InvocationTransaction> MockGenerateInvocationTx(Fixed8 networkFee, int size, byte[] overrideScriptBytes=null)
{
var mockTx = new Mock<InvocationTransaction>();
mockTx.CallBase = true;
mockTx.SetupGet(mr => mr.NetworkFee).Returns(networkFee);
mockTx.SetupGet(mr => mr.Size).Returns(size);

var tx = mockTx.Object;
// use random bytes in the script to get a different hash since we cannot mock the Hash
byte[] randomBytes;
if (overrideScriptBytes != null)
randomBytes = overrideScriptBytes;
else
{
randomBytes = new byte[16];
TestRandom.NextBytes(randomBytes);
}
tx.Script = randomBytes;
tx.Attributes = new TransactionAttribute[0];
tx.Inputs = new CoinReference[0];
tx.Outputs = new TransactionOutput[0];
tx.Witnesses = new Witness[0];
return mockTx;
}
}
}
Loading