Skip to content

Configuration

Matthew Little edited this page Oct 20, 2018 · 7 revisions

Configuration

Create an app.config file in your project directory (next to your .csproj file). Specify configuration values with the following format:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="SolcVersion" value="0.4.24"/>
    <add key="SolcOptimizer" value="0" />
    <add key="ExternalNodeHost" value="localhost:7545"/>
    <add key="OnlyUseExternalNode" value="False"/>
    <add key="DefaultGasLimit" value="6000000" />
    <add key="AccountCount" value="120" />
    <add key="AccountBalance" value="2300"/>
  </appSettings>
</configuration>

Specifying Solc Version

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.

Programmatic Configuration

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()
    {
        // Directories or exact contract files can be excluded.
        Global.HideSolidityFromReport(
            "Migrations.sol", 
            "lib_example/TestContracts", 
            "lib_example/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;
    }
}

Unit Test Parallelism

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.

Clone this wiki locally