-
Notifications
You must be signed in to change notification settings - Fork 23
Configuration
Create an app.config
file in your project directory (next to your .csproj
file). See the following example for the xml format and the available options:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!-- Specify which version of solc to use. See docs below about specifying solc version. -->
<add key="SolcVersion" value="0.4.24"/>
<!-- See https://solidity.readthedocs.io/en/v0.4.25/using-the-compiler.html for information on this solc optimizer setting. A value of "0" means default / no optimization. -->
<add key="SolcOptimizer" value="0" />
<!-- Specify this options to use your own test node. Requires using the [ParallelTestClass] attribute on test classes. Warning: the test node must support the special "snapshot" and "revert" RPC calls, such as Ganache. -->
<add key="ExternalNodeHost" value="localhost:7545"/>
<!-- By default if an external node host is provided, then tests will be ran against both Meadow's own test RPC node, as well as the externally specified one. Set this to "True" to disable. -->
<add key="OnlyUseExternalNode" value="False"/>
<!-- Specify the default gas limit in wei. -->
<add key="DefaultGasLimit" value="6000000" />
<!-- Specify how many accounts for the Meadow test RPC node to generate. -->
<add key="AccountCount" value="120" />
<!-- The balance given to each account, specified in ether (not wei). -->
<add key="AccountBalance" value="2300" />
<!-- The BIP39/BIP44 mnemonic to use for account generation. If not specified a random mnemonic will be generated for each test suite run. -->
<add key="AccountMnemonic" value="lift kiwi blossom catalog around oxygen unknown cousin road usage warrior silk eye game universe" />
</appSettings>
</configuration>
A specific version of solc is required if a .sol
file specifies a Solidity version without the caret (see https://solidity.readthedocs.io/en/v0.4.25/layout-of-source-files.html#version-pragma).
For example: pragma solidity 0.4.22;
The latest solc version is included in the Meadow test harness by default. If a .sol
is hard targeting an older version then you must include the SolcNet.Legacy package in your project.
Example of how to add this package to your project from the command line: dotnet add package SolcNet.Legacy
The solc version must then be specified in the project's app.config
file (see above example). Note: the solc version setting is evaluated during build time and thus cannot be set programmatically (see below), it must be set in the app.config
.
Settings can be specified in code by changing properties on the Meadow.UnitTestTemplate.Global
object. This should be done before tests are ran, so place them in a method with the [AssemblyInitialize]
attribute, inside a class with the [TestClass]
attribute.
Example:
using Meadow.UnitTestTemplate;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
[TestClass]
public static class GlobalSetup
{
[AssemblyInitialize]
public static void Init()
{
// Exclude .sol files from the html coverage report.
// Directories or exact files can be excluded.
Global.HideSolidityFromReport(
"Migrations.sol",
"lib/TestContracts",
"lib/ignore.sol"
);
// Gas limit in wei.
Global.DefaultGasLimit = 6000000;
// Account balance in ether.
Global.AccountBalance = 2300;
// Number of accounts to be generated for use.
Global.AccountCount = 120;
}
}
Use the MSTest Parallelize attribute to control whether tests are ran one at a time, or parallel, or to what level of parallelism. For example, at the top of one of your class files, add the following:
[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)]
Workers = 0
specified no maximum number of threads so around 1 thread per logical CPU core will be spawned to run tests.
Scope = ExecutionScope.MethodLevel
specifies that all tests in all classes can be ran in parallel.