soltools

package
v0.0.0-...-e7f7a61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2022 License: BlueOak-1.0.0 Imports: 21 Imported by: 0

README

soltools

Go wrappers for 0x's suite of solidity tools.

We use sol-coverage to get coverage reports for our Solidity contracts. sol-coverage is written in JavaScript, and our tests are written in Go, so we need a way to bridge between the two languages. This package provides that bridge.

The bridge works by running the relevant 0x libraries in a node.js process, and communicating with the process using HTTP requests over localhost.

Documentation

Overview

Package soltools provides a Go-to-JavaScript bridge to use 0x's suite of sol-X tools from Go.

0x has a suite of tools for Solidity development:

https://sol-coverage.com/
https://sol-compiler.com/
https://sol-trace.com/
https://sol-profiler.com/

The tools are designed to be used from JavaScript. This package provides a bridge so they can be used from Go. The primary interface is Backend, which is a replacement for an *ethclient.Client that sends transactions and calls through a 0x library that adds tracing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	*ethclient.Client
	// contains filtered or unexported fields
}

Backend is a replacement for an *ethclient.Client that sends transactions through 0x's tracing library in JavaScript.

func NewBackend

func NewBackend(nodeAddress string) (*Backend, error)

NewBackend dials an ethereum node at nodeAddress and returns a *Backend client for that node.

NewBackend also starts a Node.js process, which the caller is responsible for closing by calling Backend.Close(). Example:

backend, err := NewBackend("http://localhost:8545", "project/artifacts", "project/contracts")
// handle err
defer backend.Close()

The client will add tracing to the Ethereum transactions and calls that are made through it. It can also write a coverage report, which requires passing paths to artifacts and contracts directories for the corresponding Solidity code.

func (*Backend) CallContract

func (b *Backend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract overrides the same method in *ethclient.Client (and satisfies CallContract from go-ethereum's bind.ContractCaller interface). Instead of sending the call through the underlying client, it sends it through 0x's library.

func (*Backend) Close

func (b *Backend) Close() error

Close frees resources associated with this Backend.

In particular, it closes the backing JavaScript process and a network connection to the Ethereum node.

func (*Backend) EstimateGas

func (b *Backend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

EstimateGas overrides the same method in *ethclient.Client (and satisfies EstimateGas from go-ethereum's bind.ContractTransactor interface). Instead of sending the call through the underlying client, it returns a hard-coded result.

The hard-coded result is used so that transactions never fail in the gas estimation stage. Instead they will fail when the transaction is mined. This is assumed to be desirable behavior because it causes the transaction to actually run, rather than not, which causes the corresponding code to get traced for code coverage, rather than not.

func (*Backend) SendTransaction

func (b *Backend) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction overrides the same method in *ethclient.Client (and satisfies SendTransaction from go-ethereum's bind.ContractTransactor interface). Instead of sending the call through the underlying client, it sends it through 0x's library.

func (*Backend) WriteCoverage

func (b *Backend) WriteCoverage() error

WriteCoverage writes a coverage report in Istanbul format to $PWD/coverage/coverage.json.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL