Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
* Add more tests for TestNode.Server.

See merge request company-projects/Meadow!59
  • Loading branch information
zone117x committed Oct 23, 2018
2 parents 2ac4e8b + 5bc6f2a commit f6ccdb5
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 16 deletions.
30 changes: 17 additions & 13 deletions src/Meadow.DebugAdapterServer/MeadowSolidityDebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,31 @@
using Meadow.JsonRpc.Client;
using System.Text;


namespace Meadow.DebugAdapterServer
{
class ExampleCustomRequestWithResponse : DebugRequestWithResponse<ExampleRequestArgs, ExampleRequestResponse>
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class MeadowSolidityDebugAdapter : DebugAdapterBase
{
public ExampleCustomRequestWithResponse() : base("customRequestExample")

class ExampleCustomRequestWithResponse : DebugRequestWithResponse<ExampleRequestArgs, ExampleRequestResponse>
{
public ExampleCustomRequestWithResponse() : base("customRequestExample")
{
}
}
}

class ExampleRequestArgs
{
public string SessionID { get; set; }
}
class ExampleRequestArgs
{
public string SessionID { get; set; }
}

class ExampleRequestResponse : ResponseBody
{
public string Response { get; set; }
}

class ExampleRequestResponse : ResponseBody
{
public string Response { get; set; }
}

public class MeadowSolidityDebugAdapter : DebugAdapterBase
{
#region Constants
private string _contractsDirectory = "Contracts";
private const int SIMULTANEOUS_TRACE_COUNT = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/Meadow.EVM.Test/PowMiningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void AssertSHA1(string expectedHash, Span<byte> data, bool matches = tru
}
}

[Fact]
[Fact(Skip = "Too intensive for build server")]
public void TestCacheGenerationSmall()
{
// Generate a cache for our future block.
Expand All @@ -49,7 +49,7 @@ public void TestCacheGeneration()
AssertSHA1("CBFD542DF1457676C766997504074B7FB126C05C", cache.Span);
}

[Fact]
[Fact(Skip = "Too intensive for build server")]
public void TestPartialDataSet()
{
// This is based off a cut-up version of the full set generator. Thus if that is updated, this should be too! Look at the Full Data Set Test for more info about how full data sets are generated.
Expand Down
2 changes: 2 additions & 0 deletions src/Meadow.EVM/Data Types/Chain/PoW/ChainPoW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Meadow.EVM.Data_Types.Chain.PoW
{
// Code coverage disabled while tests are disabled for performance reasons.
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class ChainPoW
{
#region Constants
Expand Down
2 changes: 2 additions & 0 deletions src/Meadow.EVM/Data Types/Chain/PoW/ConsensusPoW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
/// <summary>
/// Ethereum proof-of-work consensus mechamism state transition and helper functions implementation.
/// </summary>
// Code coverage disabled while tests are disabled for performance reasons.
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class ConsensusPoW : ConsensusBase
{
#region Functions
Expand Down
2 changes: 2 additions & 0 deletions src/Meadow.EVM/Data Types/Chain/PoW/Ethash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
/// <summary>
/// Ethereum hash implementation used for hashing blocks and proof of work. Increased difficulty and use of memory/storage to avoid Application Specific Integrated Circuit ("ASIC") hashing advantages.
/// </summary>
// Code coverage disabled while tests are disabled for performance reasons.
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public abstract class Ethash
{
// Source: https://github.com/ethereum/wiki/wiki/Ethash
Expand Down
2 changes: 2 additions & 0 deletions src/Meadow.EVM/Data Types/Chain/PoW/MiningPoW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
/// <summary>
/// Ethereum proof of work validation and proof of work calculation routines.
/// </summary>
// Code coverage disabled while tests are disabled for performance reasons.
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public abstract class MiningPoW
{
#region Functions
Expand Down
2 changes: 2 additions & 0 deletions src/Meadow.JsonRpc.Server.Proxy/RpcServerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Meadow.JsonRpc.Server.Proxy
{

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class RpcServerProxy : IRpcController, IDisposable
{
readonly IJsonRpcClient _proxyClient;
Expand Down
136 changes: 136 additions & 0 deletions src/Meadow.TestNode.Test/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Xunit;
using System.Globalization;
using Meadow.Core.EthTypes;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

Expand Down Expand Up @@ -39,6 +40,140 @@ public void Dispose()
_fixture.Dispose();
}

[Fact]
public async Task GetBalanceTest()
{
var accounts = await Client.Accounts();
var balance = await Client.GetBalance(accounts[0], DefaultBlockParameter.Default);
Assert.Equal(2e21, balance);
}

[Fact]
public async Task GetCodeTest()
{
var accounts = await Client.Accounts();
var code = await Client.GetCode(accounts[0], DefaultBlockParameter.Default);

await Client.GetCode(accounts[0], 9999999);
}

[Fact]
public async Task IncreaseTimeTest()
{
ulong seconds = 1500;
await _fixture.Client.Mine();
var time1 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Timestamp;
await _fixture.Client.IncreaseTime(seconds);
await _fixture.Client.Mine();
var time2 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Timestamp;
var diff = time2 - time1;
Assert.Equal(seconds, diff);
}

[Fact]
public async Task GasPriceTest()
{
var price = await Client.GasPrice();
Assert.Equal(0, price);
}

[Fact]
public async Task CoinbaseTest()
{
var coinbase = await Client.Coinbase();
Assert.Equal("0x7777777777777777777777777777777777777777", coinbase);
}

[Fact]
public async Task TestChainID()
{
var chainID = await Client.ChainID();
Assert.Equal(77UL, chainID);
}

[Fact]
public async Task MineTest()
{
var blockNum1 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Number.Value;
await _fixture.Client.Mine();
var blockNum2 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Number.Value;
Assert.Equal(1UL, blockNum2 - blockNum1);
}

[Fact]
public async Task GetBlockTest()
{
var blockNum = await Client.BlockNumber();
var block1 = await Client.GetBlockByNumber(false, blockNum);
var block2 = await Client.GetBlockByHash(block1.Hash.Value, false);
Assert.Equal(block1.Hash.Value, block2.Hash.Value);
}

[Fact]
public async Task GetTransactionByHash()
{
var accounts = await Client.Accounts();
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
var txHash = await contract.getValCounter().SendTransaction();
var tx = await Client.GetTransactionByHash(txHash);
Assert.Equal(txHash, tx.Hash);
}

[Fact]
public async Task GetTransactionByBlockHashAndIndexTest()
{
var accounts = await Client.Accounts();
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
var txHash = await contract.getValCounter().SendTransaction();
var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);
var tx = await Client.GetTransactionByBlockHashAndIndex(curBlock.Hash.Value, 0);
Assert.Equal(txHash, tx.Hash);
}


[Fact]
public async Task GetBlockTransactionCountTest()
{
var accounts = await Client.Accounts();
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
var txHash = await contract.getValCounter().SendTransaction();

var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);

var count1 = await Client.GetBlockTransactionCountByHash(curBlock.Hash.Value);
Assert.Equal(1UL, count1);

var count2 = await Client.GetBlockTransactionCountByNumber(curBlock.Number.Value);
Assert.Equal(1UL, count2);
}

[Fact]
public async Task GetTransactionCountTest()
{
var accounts = await Client.Accounts();
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
var txHash = await contract.getValCounter().SendTransaction(new TransactionParams(from: accounts[2]));

var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);

var count = await Client.GetTransactionCount(accounts[2], DefaultBlockParameter.Default);
Assert.Equal(1UL, count);
}

[Fact]
public async Task ClientVersionTest()
{
var version = await Client.ClientVersion();
Assert.Contains("Meadow-TestServer", version, StringComparison.Ordinal);
}

[Fact]
public async Task SyncingTest()
{
var syncing = await Client.Syncing();
Assert.False(syncing.IsSyncing);
}

[Fact]
public async Task SnapshotRevertWithCoverageTest()
{
Expand All @@ -62,6 +197,7 @@ public async Task SnapshotRevertWithCoverageTest()
await Client.Revert(snapshotID2);

var coverage = await Client.GetCoverageMap(contract.ContractAddress);
await Client.ClearCoverage(contract.ContractAddress);
}

#region Tests
Expand Down
1 change: 1 addition & 0 deletions src/Meadow.UnitTestTemplate/MSTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Meadow.UnitTestTemplate
{
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class MSTestRunner
{
string[] _assemblies;
Expand Down
2 changes: 1 addition & 1 deletion src/run-coverage-tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rmdir /s /q "report\"
mkdir "coverage\"
echo {}> "coverage\coverage.json"
dotnet test -c Debug --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=\"json,opencover\" /p:CoverletOutput="%cd%\coverage\coverage" /p:MergeWith="%cd%\coverage\coverage.json"
dotnet tool install dotnet-reportgenerator-globaltool --version 4.0.0-rc4 --tool-path reportgenerator
dotnet tool install dotnet-reportgenerator-globaltool --tool-path reportgenerator
reportgenerator\reportgenerator -reports:coverage\coverage.opencover.xml -targetdir:report "-reporttypes:HTML;Badges"
rmdir /s /q "coverage\"
rmdir /s /q "reportgenerator\"

0 comments on commit f6ccdb5

Please sign in to comment.