Skip to content

Commit 5bc6f2a

Browse files
committed
* Add more tests for TestNode.Server.
* Exclude some classes from code coverage reporting for purposes of either: tests disabled, or impractical end-to-end coverage. * Re-disable pow mining tests (still kills CI servers).
1 parent 4c29d15 commit 5bc6f2a

File tree

10 files changed

+167
-16
lines changed

10 files changed

+167
-16
lines changed

src/Meadow.DebugAdapterServer/MeadowSolidityDebugAdapter.cs

+17-13
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,31 @@
1818
using Meadow.JsonRpc.Client;
1919
using System.Text;
2020

21+
2122
namespace Meadow.DebugAdapterServer
2223
{
23-
class ExampleCustomRequestWithResponse : DebugRequestWithResponse<ExampleRequestArgs, ExampleRequestResponse>
24+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
25+
public class MeadowSolidityDebugAdapter : DebugAdapterBase
2426
{
25-
public ExampleCustomRequestWithResponse() : base("customRequestExample")
27+
28+
class ExampleCustomRequestWithResponse : DebugRequestWithResponse<ExampleRequestArgs, ExampleRequestResponse>
2629
{
30+
public ExampleCustomRequestWithResponse() : base("customRequestExample")
31+
{
32+
}
2733
}
28-
}
2934

30-
class ExampleRequestArgs
31-
{
32-
public string SessionID { get; set; }
33-
}
35+
class ExampleRequestArgs
36+
{
37+
public string SessionID { get; set; }
38+
}
39+
40+
class ExampleRequestResponse : ResponseBody
41+
{
42+
public string Response { get; set; }
43+
}
3444

35-
class ExampleRequestResponse : ResponseBody
36-
{
37-
public string Response { get; set; }
38-
}
3945

40-
public class MeadowSolidityDebugAdapter : DebugAdapterBase
41-
{
4246
#region Constants
4347
private string _contractsDirectory = "Contracts";
4448
private const int SIMULTANEOUS_TRACE_COUNT = 1;

src/Meadow.EVM.Test/PowMiningTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private void AssertSHA1(string expectedHash, Span<byte> data, bool matches = tru
2727
}
2828
}
2929

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

52-
[Fact]
52+
[Fact(Skip = "Too intensive for build server")]
5353
public void TestPartialDataSet()
5454
{
5555
// 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.

src/Meadow.EVM/Data Types/Chain/PoW/ChainPoW.cs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Meadow.EVM.Data_Types.Chain.PoW
1313
{
14+
// Code coverage disabled while tests are disabled for performance reasons.
15+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1416
public class ChainPoW
1517
{
1618
#region Constants

src/Meadow.EVM/Data Types/Chain/PoW/ConsensusPoW.cs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
1313
/// <summary>
1414
/// Ethereum proof-of-work consensus mechamism state transition and helper functions implementation.
1515
/// </summary>
16+
// Code coverage disabled while tests are disabled for performance reasons.
17+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1618
public class ConsensusPoW : ConsensusBase
1719
{
1820
#region Functions

src/Meadow.EVM/Data Types/Chain/PoW/Ethash.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
1515
/// <summary>
1616
/// 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.
1717
/// </summary>
18+
// Code coverage disabled while tests are disabled for performance reasons.
19+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1820
public abstract class Ethash
1921
{
2022
// Source: https://github.com/ethereum/wiki/wiki/Ethash

src/Meadow.EVM/Data Types/Chain/PoW/MiningPoW.cs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace Meadow.EVM.Data_Types.Chain.PoW
1616
/// <summary>
1717
/// Ethereum proof of work validation and proof of work calculation routines.
1818
/// </summary>
19+
// Code coverage disabled while tests are disabled for performance reasons.
20+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1921
public abstract class MiningPoW
2022
{
2123
#region Functions

src/Meadow.JsonRpc.Server.Proxy/RpcServerProxy.cs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Meadow.JsonRpc.Server.Proxy
1515
{
16+
17+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1618
public class RpcServerProxy : IRpcController, IDisposable
1719
{
1820
readonly IJsonRpcClient _proxyClient;

src/Meadow.TestNode.Test/BasicTests.cs

+136
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using Xunit;
1111
using System.Globalization;
12+
using Meadow.Core.EthTypes;
1213

1314
[assembly: CollectionBehavior(DisableTestParallelization = true)]
1415

@@ -39,6 +40,140 @@ public void Dispose()
3940
_fixture.Dispose();
4041
}
4142

43+
[Fact]
44+
public async Task GetBalanceTest()
45+
{
46+
var accounts = await Client.Accounts();
47+
var balance = await Client.GetBalance(accounts[0], DefaultBlockParameter.Default);
48+
Assert.Equal(2e21, balance);
49+
}
50+
51+
[Fact]
52+
public async Task GetCodeTest()
53+
{
54+
var accounts = await Client.Accounts();
55+
var code = await Client.GetCode(accounts[0], DefaultBlockParameter.Default);
56+
57+
await Client.GetCode(accounts[0], 9999999);
58+
}
59+
60+
[Fact]
61+
public async Task IncreaseTimeTest()
62+
{
63+
ulong seconds = 1500;
64+
await _fixture.Client.Mine();
65+
var time1 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Timestamp;
66+
await _fixture.Client.IncreaseTime(seconds);
67+
await _fixture.Client.Mine();
68+
var time2 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Timestamp;
69+
var diff = time2 - time1;
70+
Assert.Equal(seconds, diff);
71+
}
72+
73+
[Fact]
74+
public async Task GasPriceTest()
75+
{
76+
var price = await Client.GasPrice();
77+
Assert.Equal(0, price);
78+
}
79+
80+
[Fact]
81+
public async Task CoinbaseTest()
82+
{
83+
var coinbase = await Client.Coinbase();
84+
Assert.Equal("0x7777777777777777777777777777777777777777", coinbase);
85+
}
86+
87+
[Fact]
88+
public async Task TestChainID()
89+
{
90+
var chainID = await Client.ChainID();
91+
Assert.Equal(77UL, chainID);
92+
}
93+
94+
[Fact]
95+
public async Task MineTest()
96+
{
97+
var blockNum1 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Number.Value;
98+
await _fixture.Client.Mine();
99+
var blockNum2 = (await Client.GetBlockByNumber(false, DefaultBlockParameter.Default)).Number.Value;
100+
Assert.Equal(1UL, blockNum2 - blockNum1);
101+
}
102+
103+
[Fact]
104+
public async Task GetBlockTest()
105+
{
106+
var blockNum = await Client.BlockNumber();
107+
var block1 = await Client.GetBlockByNumber(false, blockNum);
108+
var block2 = await Client.GetBlockByHash(block1.Hash.Value, false);
109+
Assert.Equal(block1.Hash.Value, block2.Hash.Value);
110+
}
111+
112+
[Fact]
113+
public async Task GetTransactionByHash()
114+
{
115+
var accounts = await Client.Accounts();
116+
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
117+
var txHash = await contract.getValCounter().SendTransaction();
118+
var tx = await Client.GetTransactionByHash(txHash);
119+
Assert.Equal(txHash, tx.Hash);
120+
}
121+
122+
[Fact]
123+
public async Task GetTransactionByBlockHashAndIndexTest()
124+
{
125+
var accounts = await Client.Accounts();
126+
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
127+
var txHash = await contract.getValCounter().SendTransaction();
128+
var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);
129+
var tx = await Client.GetTransactionByBlockHashAndIndex(curBlock.Hash.Value, 0);
130+
Assert.Equal(txHash, tx.Hash);
131+
}
132+
133+
134+
[Fact]
135+
public async Task GetBlockTransactionCountTest()
136+
{
137+
var accounts = await Client.Accounts();
138+
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
139+
var txHash = await contract.getValCounter().SendTransaction();
140+
141+
var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);
142+
143+
var count1 = await Client.GetBlockTransactionCountByHash(curBlock.Hash.Value);
144+
Assert.Equal(1UL, count1);
145+
146+
var count2 = await Client.GetBlockTransactionCountByNumber(curBlock.Number.Value);
147+
Assert.Equal(1UL, count2);
148+
}
149+
150+
[Fact]
151+
public async Task GetTransactionCountTest()
152+
{
153+
var accounts = await Client.Accounts();
154+
var contract = await BasicContract.New($"TestName", true, 34, Client, new TransactionParams { From = accounts[0], Gas = 4712388 }, accounts[0]);
155+
var txHash = await contract.getValCounter().SendTransaction(new TransactionParams(from: accounts[2]));
156+
157+
var curBlock = await Client.GetBlockByNumber(true, DefaultBlockParameter.Default);
158+
159+
var count = await Client.GetTransactionCount(accounts[2], DefaultBlockParameter.Default);
160+
Assert.Equal(1UL, count);
161+
}
162+
163+
[Fact]
164+
public async Task ClientVersionTest()
165+
{
166+
var version = await Client.ClientVersion();
167+
Assert.Contains("Meadow-TestServer", version, StringComparison.Ordinal);
168+
}
169+
170+
[Fact]
171+
public async Task SyncingTest()
172+
{
173+
var syncing = await Client.Syncing();
174+
Assert.False(syncing.IsSyncing);
175+
}
176+
42177
[Fact]
43178
public async Task SnapshotRevertWithCoverageTest()
44179
{
@@ -62,6 +197,7 @@ public async Task SnapshotRevertWithCoverageTest()
62197
await Client.Revert(snapshotID2);
63198

64199
var coverage = await Client.GetCoverageMap(contract.ContractAddress);
200+
await Client.ClearCoverage(contract.ContractAddress);
65201
}
66202

67203
#region Tests

src/Meadow.UnitTestTemplate/MSTestRunner.cs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Meadow.UnitTestTemplate
1616
{
17+
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1718
public class MSTestRunner
1819
{
1920
string[] _assemblies;

src/run-coverage-tests.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rmdir /s /q "report\"
55
mkdir "coverage\"
66
echo {}> "coverage\coverage.json"
77
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"
8-
dotnet tool install dotnet-reportgenerator-globaltool --version 4.0.0-rc4 --tool-path reportgenerator
8+
dotnet tool install dotnet-reportgenerator-globaltool --tool-path reportgenerator
99
reportgenerator\reportgenerator -reports:coverage\coverage.opencover.xml -targetdir:report "-reporttypes:HTML;Badges"
1010
rmdir /s /q "coverage\"
1111
rmdir /s /q "reportgenerator\"

0 commit comments

Comments
 (0)