Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethereum-waffle/provider

Package Overview
Dependencies
Maintainers
1
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereum-waffle/provider

A mock provider for your blockchain testing needs.

  • 4.0.4-dev.e22c4e6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
66K
increased by21.59%
Maintainers
1
Weekly downloads
 
Created
Source

CI

Ethereum Waffle

@ethereum-waffle/provider

A mock provider for your blockchain testing needs.

Installation

In the current version of waffle (v2.x.x) you will install this package as a dependency of the main waffle package - ethereum-waffle.

yarn add --dev ethereum-waffle
npm install --save-dev ethereum-waffle

If you want to use this package directly please install it via:

yarn add --dev @ethereum-waffle/provider
npm install --save-dev @ethereum-waffle/provider

Feature overview

NOTE: You do not need to use this package directly. You can install it through the main package (ethereum-waffle) and use it instead.

MockProvider

The MockProvider class is the main way of interacting with the blockchain in your waffle tests.

It wraps ganache-core in an ethers provider and extends it with useful functionality.

You can learn more about it in the documentation.

Usage

Examples of creating MockProvider and usage getWallets function:

import {expect} from 'chai';
import {MockProvider} from '@ethereum-waffle/provider';

describe('waffle tests', async () => {
  it('wallets have non-zero balance', async () => {
    const provider = new MockProvider();
    const wallets = provider.getWallets();
    const balance = await wallets[0].getBalance();
    expect(balance.gt(0)).to.equal(true)
  })
})

Use setupENS function to set up your ens and setting ens address to the provider's networks. The function accepts the wallet as an argument, and if you call it without an argument, it will use the last wallet from MockProvider.

import {expect} from 'chai';
import {MockProvider} from '@ethereum-waffle/provider';
describe('waffle tests', async () => {
  it('setup ens', async () => {
    const provider = new MockProvider();
    await provider.setupENS();
    expect(provider.network.ensAddress).to.eq(provider.ens.ens.address);
  });
});

Fixtures

Fixtures are an advanced concept that you can use to make your tests run faster. They take advantage of the snapshot mechanism in Ganache.

You can learn more about it in the documentation.

Legacy API

  • createMockProvider - this was the old way to construct a MockProvider instance
  • getGanacheOptions - previously it was possible to load the options from the waffle config file
  • getWallets - this was the old way to get wallets from a provider

Keywords

FAQs

Package last updated on 05 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc