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 crlf on neo.UnitTests and set all files to not use BOM (byte order mark) #1057

Merged
merged 43 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
82dd1b7
Check dotnet format in travis
shargon Aug 25, 2019
82967c2
Try to find the path
shargon Aug 25, 2019
14cab76
Update .travis.yml
shargon Aug 25, 2019
b3c3c9e
Update .travis.yml
shargon Aug 25, 2019
dce6a3f
Update .travis.yml
shargon Aug 25, 2019
ef80e6f
Format travis
shargon Aug 25, 2019
c958cfe
test and source
shargon Aug 25, 2019
aff81ba
test and source
shargon Aug 25, 2019
46d11a8
Move to before the script
shargon Aug 25, 2019
8612963
testing if CRLF format is respected
igormcoelho Aug 25, 2019
084d5b9
fix crlf on unit tests
igormcoelho Aug 25, 2019
857d9ff
testing for crlf on unit tests too
igormcoelho Aug 25, 2019
ae090da
all utf-8
igormcoelho Aug 25, 2019
4ed225a
neo/ on utf8 too
igormcoelho Aug 25, 2019
9d3b020
looks like sudo is needed by travis
igormcoelho Aug 25, 2019
b0cf66b
download dos2unix 7.4.0
igormcoelho Aug 25, 2019
37802ea
temporaly remove | test
igormcoelho Aug 26, 2019
3a5b0ae
back to | test
igormcoelho Aug 26, 2019
1e6d4a6
explicit test zero
igormcoelho Aug 26, 2019
349d4b0
no bom
igormcoelho Aug 26, 2019
543bb40
more non-boom to boom
igormcoelho Aug 26, 2019
d28a0d3
ensuring no_bom at all files
igormcoelho Aug 26, 2019
4ed4609
Printing files with bom prefix
igormcoelho Aug 26, 2019
bccdddd
Merge pull request #6 from neo-project/dotnet-format
igormcoelho Aug 26, 2019
f66daeb
Check both folders in one command
shargon Aug 26, 2019
038de69
Add verbosity
shargon Aug 26, 2019
aa388f7
Create .editorconfig
shargon Aug 26, 2019
e987065
Ensure the path of .editorconfig file
shargon Aug 26, 2019
7cc87ea
Update .editorconfig
shargon Aug 26, 2019
ebdb9ba
Update .editorconfig
shargon Aug 26, 2019
9cbc515
Update .editorconfig
shargon Aug 26, 2019
cba7633
use only dotnet-format
shargon Aug 26, 2019
59bcd28
basic formatting (just 5 files affected)
igormcoelho Aug 26, 2019
cac20af
dotnet version
igormcoelho Aug 26, 2019
548601e
new lines on end
igormcoelho Aug 26, 2019
88ffdb7
update travis
igormcoelho Aug 26, 2019
5e2362e
advice on auto crlf
igormcoelho Aug 26, 2019
e0242b1
Update .travis.yml
shargon Aug 26, 2019
f335eb0
Update .travis.yml
shargon Aug 26, 2019
bfdf67d
enforcing lf
igormcoelho Aug 26, 2019
ad7bac1
Fix dotnet format version
shargon Aug 26, 2019
7f9ab1a
removed dos2unix
igormcoelho Aug 26, 2019
45b2c3f
Merge branch 'master' into dotnet-format-tests
igormcoelho Aug 27, 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
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
###############################
# Core EditorConfig Options #
###############################

# dotnet-format requires version 3.1.37601
igormcoelho marked this conversation as resolved.
Show resolved Hide resolved
# dotnet tool update -g dotnet-format
# remember to have: git config --global core.autocrlf false #(which is usually default)

root = true

# Every file

[*]
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf
#indent_style = tab # TODO
16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ mono: none
dotnet: 2.2.300

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

before_install:
- cd neo.UnitTests
- 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
- 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: |
dotnet restore
if [[ "$TEST_SUITE" == cultures ]]; then
dotnet restore
dotnet test
else
dotnet restore
find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
dotnet test -v n --filter FullyQualifiedName!=Neo.UnitTests.UT_Culture.All_Tests_Cultures /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
fi
Expand Down
2 changes: 1 addition & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
Expand Down
306 changes: 153 additions & 153 deletions neo.UnitTests/Consensus/UT_ConsensusContext.cs
Original file line number Diff line number Diff line change
@@ -1,134 +1,134 @@
using Akka.TestKit.Xunit2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Consensus;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.Wallets;
using System;
using System.Linq;
namespace Neo.UnitTests.Consensus
{
[TestClass]
public class UT_ConsensusContext : TestKit
{
ConsensusContext _context;
KeyPair[] _validatorKeys;
[TestInitialize]
public void TestSetup()
{
TestBlockchain.InitializeMockNeoSystem();
var rand = new Random();
var mockWallet = new Mock<Wallet>();
mockWallet.Setup(p => p.GetAccount(It.IsAny<UInt160>())).Returns<UInt160>(p => new TestWalletAccount(p));
// Create dummy validators
_validatorKeys = new KeyPair[7];
for (int x = 0; x < _validatorKeys.Length; x++)
{
var pk = new byte[32];
rand.NextBytes(pk);
_validatorKeys[x] = new KeyPair(pk);
}
_context = new ConsensusContext(mockWallet.Object, TestBlockchain.GetStore())
{
Validators = _validatorKeys.Select(u => u.PublicKey).ToArray()
};
_context.Reset(0);
}
[TestCleanup]
public void Cleanup()
{
Shutdown();
}
[TestMethod]
public void TestMaxBlockSize_Good()
{
// Only one tx, is included
var tx1 = CreateTransactionWithSize(200);
_context.EnsureMaxBlockSize(new Transaction[] { tx1 });
EnsureContext(_context, tx1);
// All txs included
var max = (int)NativeContract.Policy.GetMaxTransactionsPerBlock(_context.Snapshot);
var txs = new Transaction[max];
for (int x = 0; x < max; x++) txs[x] = CreateTransactionWithSize(100);
_context.EnsureMaxBlockSize(txs);
EnsureContext(_context, txs);
}
[TestMethod]
public void TestMaxBlockSize_Exceed()
{
// Two tx, the last one exceed the size rule, only the first will be included
var tx1 = CreateTransactionWithSize(200);
var tx2 = CreateTransactionWithSize(256 * 1024);
_context.EnsureMaxBlockSize(new Transaction[] { tx1, tx2 });
EnsureContext(_context, tx1);
// Exceed txs number, just MaxTransactionsPerBlock included
var max = (int)NativeContract.Policy.GetMaxTransactionsPerBlock(_context.Snapshot);
var txs = new Transaction[max + 1];
for (int x = 0; x < max; x++) txs[x] = CreateTransactionWithSize(100);
_context.EnsureMaxBlockSize(txs);
EnsureContext(_context, txs.Take(max).ToArray());
}
private Transaction CreateTransactionWithSize(int v)
{
var r = new Random();
var tx = new Transaction()
{
Cosigners = new Cosigner[0],
Attributes = new TransactionAttribute[0],
NetworkFee = 0,
Nonce = (uint)Environment.TickCount,
Script = new byte[0],
Sender = UInt160.Zero,
SystemFee = 0,
ValidUntilBlock = (uint)r.Next(),
Version = 0,
Witnesses = new Witness[0],
};
// Could be higher (few bytes) if varSize grows
tx.Script = new byte[v - tx.Size];
return tx;
}
private Block SignBlock(ConsensusContext context)
{
context.Block.MerkleRoot = null;
for (int x = 0; x < _validatorKeys.Length; x++)
{
_context.MyIndex = x;
var com = _context.MakeCommit();
_context.CommitPayloads[_context.MyIndex] = com;
}
// Manual block sign
using Akka.TestKit.Xunit2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Neo.Consensus;
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.Wallets;
using System;
using System.Linq;

namespace Neo.UnitTests.Consensus
{

[TestClass]
public class UT_ConsensusContext : TestKit
{
ConsensusContext _context;
KeyPair[] _validatorKeys;

[TestInitialize]
public void TestSetup()
{
TestBlockchain.InitializeMockNeoSystem();

var rand = new Random();
var mockWallet = new Mock<Wallet>();
mockWallet.Setup(p => p.GetAccount(It.IsAny<UInt160>())).Returns<UInt160>(p => new TestWalletAccount(p));

// Create dummy validators

_validatorKeys = new KeyPair[7];
for (int x = 0; x < _validatorKeys.Length; x++)
{
var pk = new byte[32];
rand.NextBytes(pk);

_validatorKeys[x] = new KeyPair(pk);
}

_context = new ConsensusContext(mockWallet.Object, TestBlockchain.GetStore())
{
Validators = _validatorKeys.Select(u => u.PublicKey).ToArray()
};
_context.Reset(0);
}

[TestCleanup]
public void Cleanup()
{
Shutdown();
}

[TestMethod]
public void TestMaxBlockSize_Good()
{
// Only one tx, is included

var tx1 = CreateTransactionWithSize(200);
_context.EnsureMaxBlockSize(new Transaction[] { tx1 });
EnsureContext(_context, tx1);

// All txs included

var max = (int)NativeContract.Policy.GetMaxTransactionsPerBlock(_context.Snapshot);
var txs = new Transaction[max];

for (int x = 0; x < max; x++) txs[x] = CreateTransactionWithSize(100);

_context.EnsureMaxBlockSize(txs);
EnsureContext(_context, txs);
}

[TestMethod]
public void TestMaxBlockSize_Exceed()
{
// Two tx, the last one exceed the size rule, only the first will be included

var tx1 = CreateTransactionWithSize(200);
var tx2 = CreateTransactionWithSize(256 * 1024);
_context.EnsureMaxBlockSize(new Transaction[] { tx1, tx2 });
EnsureContext(_context, tx1);

// Exceed txs number, just MaxTransactionsPerBlock included

var max = (int)NativeContract.Policy.GetMaxTransactionsPerBlock(_context.Snapshot);
var txs = new Transaction[max + 1];

for (int x = 0; x < max; x++) txs[x] = CreateTransactionWithSize(100);

_context.EnsureMaxBlockSize(txs);
EnsureContext(_context, txs.Take(max).ToArray());
}

private Transaction CreateTransactionWithSize(int v)
{
var r = new Random();
var tx = new Transaction()
{
Cosigners = new Cosigner[0],
Attributes = new TransactionAttribute[0],
NetworkFee = 0,
Nonce = (uint)Environment.TickCount,
Script = new byte[0],
Sender = UInt160.Zero,
SystemFee = 0,
ValidUntilBlock = (uint)r.Next(),
Version = 0,
Witnesses = new Witness[0],
};

// Could be higher (few bytes) if varSize grows
tx.Script = new byte[v - tx.Size];
return tx;
}

private Block SignBlock(ConsensusContext context)
{
context.Block.MerkleRoot = null;

for (int x = 0; x < _validatorKeys.Length; x++)
{
_context.MyIndex = x;

var com = _context.MakeCommit();
_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++)
Expand All @@ -139,25 +139,25 @@ private Block SignBlock(ConsensusContext context)
}
context.Block.Witness = sc.GetWitnesses()[0];
context.Block.Transactions = context.TransactionHashes.Select(p => context.Transactions[p]).ToArray();
return context.Block;
}
private void EnsureContext(ConsensusContext context, params Transaction[] expected)
{
// Check all tx
Assert.AreEqual(expected.Length, context.Transactions.Count);
Assert.IsTrue(expected.All(tx => context.Transactions.ContainsKey(tx.Hash)));
Assert.AreEqual(expected.Length, context.TransactionHashes.Length);
Assert.IsTrue(expected.All(tx => context.TransactionHashes.Count(t => t == tx.Hash) == 1));
// Ensure length
var block = SignBlock(context);
Assert.AreEqual(context.GetExpectedBlockSize(), block.Size);
Assert.IsTrue(block.Size < NativeContract.Policy.GetMaxBlockSize(context.Snapshot));
}
}
}
return context.Block;
}

private void EnsureContext(ConsensusContext context, params Transaction[] expected)
{
// Check all tx

Assert.AreEqual(expected.Length, context.Transactions.Count);
Assert.IsTrue(expected.All(tx => context.Transactions.ContainsKey(tx.Hash)));

Assert.AreEqual(expected.Length, context.TransactionHashes.Length);
Assert.IsTrue(expected.All(tx => context.TransactionHashes.Count(t => t == tx.Hash) == 1));

// Ensure length

var block = SignBlock(context);

Assert.AreEqual(context.GetExpectedBlockSize(), block.Size);
Assert.IsTrue(block.Size < NativeContract.Policy.GetMaxBlockSize(context.Snapshot));
}
}
}
2 changes: 1 addition & 1 deletion neo.UnitTests/Consensus/UT_ConsensusServiceMailbox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Akka.TestKit;
using Akka.TestKit;
using Akka.TestKit.Xunit2;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down
4 changes: 2 additions & 2 deletions neo.UnitTests/Cryptography/ECC/UT_ECDsa.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.Wallets;
using System;
Expand Down Expand Up @@ -52,4 +52,4 @@ public void TestVerifySignature()
sa.VerifySignature(message, new BigInteger(-100), result[1]).Should().BeFalse();
}
}
}
}
2 changes: 1 addition & 1 deletion neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ public void TestToByteArray()
new ECFieldElement(BigInteger.Pow(new BigInteger(10), 77), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result3);
}
}
}
}
Loading