Skip to content

Commit

Permalink
Merge branch 'master' into manifest_update
Browse files Browse the repository at this point in the history
  • Loading branch information
lock9 committed Nov 25, 2019
2 parents 3320b89 + a891796 commit 55c69db
Show file tree
Hide file tree
Showing 70 changed files with 491 additions and 455 deletions.
20 changes: 7 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@ language: csharp

os:
- linux
- osx

dist: bionic
osx_image: xcode9.1

mono: none
dotnet: 2.2.402
dotnet: 3.0.100

env:
- TEST_SUITE="without-cultures"
- TEST_SUITE="cultures"

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ulimit -n 2048; fi
install:
- dotnet tool install -g dotnet-format --version 4.0.40103 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
- dotnet tool install -g dotnet-format
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet-format --version
before_script:
- echo "Checking format..."
- dotnet format --check --dry-run -w . -v diagnostic # check C# formatting for neo.sln
- cd neo.UnitTests
script: |
echo "Checking format..."
dotnet format --check --dry-run -w . -v diagnostic # check C# formatting for neo.sln
cd neo.UnitTests
if [[ "$TEST_SUITE" == "cultures" ]]; then
dotnet test -v m --filter FullyQualifiedName=Neo.UnitTests.UT_Culture.All_Tests_Cultures
else
if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then
if [[ "$TEST_SUITE" == "without-cultures" ]]; then
# Test & Calculate coverage
find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
dotnet test -v m --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
Expand All @@ -38,7 +32,7 @@ script: |
fi
fi
after_success: |
if [[ "$TEST_SUITE" == "without-cultures" && "$TRAVIS_OS_NAME" == "linux" ]]; then
if [[ "$TEST_SUITE" == "without-cultures" ]]; then
# Send coverage
echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
bash <(curl -s https://codecov.io/bash) -v
Expand Down
1 change: 0 additions & 1 deletion neo.UnitTests/Consensus/UT_Consensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

namespace Neo.UnitTests.Consensus
{

[TestClass]
public class ConsensusTests : TestKit
{
Expand Down
17 changes: 3 additions & 14 deletions neo.UnitTests/Consensus/UT_ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Neo.Consensus;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.Wallets;
using System;
Expand Down Expand Up @@ -119,6 +118,8 @@ private Block SignBlock(ConsensusContext context)
{
context.Block.MerkleRoot = null;

// Fake commits

for (int x = 0; x < _validatorKeys.Length; x++)
{
_context.MyIndex = x;
Expand All @@ -127,19 +128,7 @@ private Block SignBlock(ConsensusContext context)
_context.CommitPayloads[_context.MyIndex] = com;
}

// Manual block sign

Contract contract = Contract.CreateMultiSigContract(context.M, context.Validators);
ContractParametersContext sc = new ContractParametersContext(context.Block);
for (int i = 0, j = 0; i < context.Validators.Length && j < context.M; i++)
{
if (context.CommitPayloads[i]?.ConsensusMessage.ViewNumber != context.ViewNumber) continue;
sc.AddSignature(contract, context.Validators[i], context.CommitPayloads[i].GetDeserializedMessage<Commit>().Signature);
j++;
}
context.Block.Witness = sc.GetWitnesses()[0];
context.Block.Transactions = context.TransactionHashes.Select(p => context.Transactions[p]).ToArray();
return context.Block;
return context.CreateBlock();
}

private void EnsureContext(ConsensusContext context, params Transaction[] expected)
Expand Down
49 changes: 34 additions & 15 deletions neo.UnitTests/Cryptography/UT_Base58.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,49 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
using System;
using System.Collections.Generic;

namespace Neo.UnitTests.Cryptography
{
[TestClass]
public class UT_Base58
{
byte[] decoded1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
string encoded1 = "1kA3B2yGe2z4";
byte[] decoded2 = { 0, 0, 0, 0, 0 };
string encoded2 = "1111";

[TestMethod]
public void TestEncode()
public void TestEncodeDecode()
{
Base58.Encode(decoded1).Should().Be(encoded1);
}
var bitcoinTest = new Dictionary<string, string>()
{
// Tests from https://github.com/bitcoin/bitcoin/blob/46fc4d1a24c88e797d6080336e3828e45e39c3fd/src/test/data/base58_encode_decode.json

[TestMethod]
public void TestDecode()
{
Base58.Decode(encoded1).Should().BeEquivalentTo(decoded1);
Base58.Decode(encoded2).Should().BeEquivalentTo(decoded2);
Action action = () => Base58.Decode(encoded1 + "l").Should().BeEquivalentTo(decoded1);
action.Should().Throw<FormatException>();
{"", ""},
{"61", "2g"},
{"626262", "a3gV"},
{"636363", "aPEr"},
{"73696d706c792061206c6f6e6720737472696e67", "2cFupjhnEsSn59qHXstmK2ffpLv2"},
{"00eb15231dfceb60925886b67d065299925915aeb172c06647", "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"},
{"516b6fcd0f", "ABnLTmg"},
{"bf4f89001e670274dd", "3SEo3LWLoPntC"},
{"572e4794", "3EFU7m"},
{"ecac89cad93923c02321", "EJDM8drfXA6uyA"},
{"10c8511e", "Rt5zm"},
{"00000000000000000000", "1111111111"},
{"000111d38e5fc9071ffcd20b4a763cc9ae4f252bb4e48fd66a835e252ada93ff480d6dd43dc62a641155a5", "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},
{"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "1cWB5HCBdLjAuqGGReWE3R3CguuwSjw6RHn39s2yuDRTS5NsBgNiFpWgAnEx6VQi8csexkgYw3mdYrMHr8x9i7aEwP8kZ7vccXWqKDvGv3u1GxFKPuAkn8JCPPGDMf3vMMnbzm6Nh9zh1gcNsMvH3ZNLmP5fSG6DGbbi2tuwMWPthr4boWwCxf7ewSgNQeacyozhKDDQQ1qL5fQFUW52QKUZDZ5fw3KXNQJMcNTcaB723LchjeKun7MuGW5qyCBZYzA1KjofN1gYBV3NqyhQJ3Ns746GNuf9N2pQPmHz4xpnSrrfCvy6TVVz5d4PdrjeshsWQwpZsZGzvbdAdN8MKV5QsBDY"},

// Extra tests

{"00", "1"},
{"00010203040506070809", "1kA3B2yGe2z4"},
};

foreach (var entry in bitcoinTest)
{
Base58.Encode(entry.Key.HexToBytes()).Should().Be(entry.Value);
Base58.Decode(entry.Value).Should().BeEquivalentTo(entry.Key.HexToBytes());

Action action = () => Base58.Decode(entry.Value + "l");
action.Should().Throw<FormatException>();
}
}
}
}
1 change: 1 addition & 0 deletions neo.UnitTests/Extensions/NativeContractExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;
using System;

namespace Neo.UnitTests.Extensions
Expand Down
9 changes: 4 additions & 5 deletions neo.UnitTests/Extensions/Nep5NativeContractExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace Neo.UnitTests.Extensions
{
Expand Down Expand Up @@ -65,7 +64,7 @@ public static bool Transfer(this NativeContract contract, Persistence.Snapshot s
var result = engine.ResultStack.Pop();
result.Should().BeOfType(typeof(VM.Types.Boolean));

return (result as VM.Types.Boolean).GetBoolean();
return result.ToBoolean();
}

public static string[] SupportedStandards(this NativeContract contract)
Expand All @@ -86,7 +85,7 @@ public static string[] SupportedStandards(this NativeContract contract)
result.Should().BeOfType(typeof(VM.Types.Array));

return (result as VM.Types.Array).ToArray()
.Select(u => Encoding.ASCII.GetString(u.GetByteArray()))
.Select(u => u.GetString())
.ToArray();
}

Expand Down Expand Up @@ -168,7 +167,7 @@ public static string Symbol(this NativeContract contract)
var result = engine.ResultStack.Pop();
result.Should().BeOfType(typeof(VM.Types.ByteArray));

return Encoding.UTF8.GetString((result as VM.Types.ByteArray).GetByteArray());
return result.GetString();
}

public static string Name(this NativeContract contract)
Expand All @@ -188,7 +187,7 @@ public static string Name(this NativeContract contract)
var result = engine.ResultStack.Pop();
result.Should().BeOfType(typeof(VM.Types.ByteArray));

return Encoding.UTF8.GetString((result as VM.Types.ByteArray).GetByteArray());
return result.GetString();
}
}
}
51 changes: 24 additions & 27 deletions neo.UnitTests/IO/Caching/UT_ReflectionCache.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using System.IO;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO;
using Neo.IO.Caching;
using System;

namespace Neo.UnitTests.IO.Caching
{
public class TestItem { }
public class TestItem : ISerializable
{
public int Size => 0;
public void Deserialize(BinaryReader reader) { }
public void Serialize(BinaryWriter writer) { }
}

public class TestItem1 : TestItem { }

Expand All @@ -25,55 +31,46 @@ public enum MyEmptyEnum : byte { }
[TestClass]
public class UT_ReflectionCache
{
ReflectionCache<byte> reflectionCache;

[TestInitialize]
public void SetUp()
{
reflectionCache = ReflectionCache<byte>.CreateFromEnum<MyTestEnum>();
}

[TestMethod]
public void TestCreateFromEnum()
public void TestCreateFromEmptyEnum()
{
reflectionCache.Should().NotBeNull();
ReflectionCache<MyEmptyEnum>.Count.Should().Be(0);
}

[TestMethod]
public void TestCreateFromObjectNotEnum()
public void TestCreateInstance()
{
Action action = () => ReflectionCache<byte>.CreateFromEnum<int>();
action.Should().Throw<ArgumentException>();
}
object item1 = ReflectionCache<MyTestEnum>.CreateInstance(MyTestEnum.Item1, null);
(item1 is TestItem1).Should().BeTrue();

[TestMethod]
public void TestCreateFromEmptyEnum()
{
reflectionCache = ReflectionCache<byte>.CreateFromEnum<MyEmptyEnum>();
reflectionCache.Count.Should().Be(0);
object item2 = ReflectionCache<MyTestEnum>.CreateInstance(MyTestEnum.Item2, null);
(item2 is TestItem2).Should().BeTrue();

object item3 = ReflectionCache<MyTestEnum>.CreateInstance((MyTestEnum)0x02, null);
item3.Should().BeNull();
}

[TestMethod]
public void TestCreateInstance()
public void TestCreateSerializable()
{
object item1 = reflectionCache.CreateInstance((byte)MyTestEnum.Item1, null);
object item1 = ReflectionCache<MyTestEnum>.CreateSerializable(MyTestEnum.Item1, new byte[0]);
(item1 is TestItem1).Should().BeTrue();

object item2 = reflectionCache.CreateInstance((byte)MyTestEnum.Item2, null);
object item2 = ReflectionCache<MyTestEnum>.CreateSerializable(MyTestEnum.Item2, new byte[0]);
(item2 is TestItem2).Should().BeTrue();

object item3 = reflectionCache.CreateInstance(0x02, null);
object item3 = ReflectionCache<MyTestEnum>.CreateSerializable((MyTestEnum)0x02, new byte[0]);
item3.Should().BeNull();
}

[TestMethod]
public void TestCreateInstance2()
{
TestItem defaultItem = new TestItem1();
object item2 = reflectionCache.CreateInstance((byte)MyTestEnum.Item2, defaultItem);
object item2 = ReflectionCache<MyTestEnum>.CreateInstance(MyTestEnum.Item2, defaultItem);
(item2 is TestItem2).Should().BeTrue();

object item1 = reflectionCache.CreateInstance(0x02, new TestItem1());
object item1 = ReflectionCache<MyTestEnum>.CreateInstance((MyTestEnum)0x02, new TestItem1());
(item1 is TestItem1).Should().BeTrue();
}
}
Expand Down
Loading

0 comments on commit 55c69db

Please sign in to comment.