Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic Smart Contracts mocking #109

Closed
sz-piotr opened this issue Jun 10, 2019 · 1 comment
Closed

Add dynamic Smart Contracts mocking #109

sz-piotr opened this issue Jun 10, 2019 · 1 comment
Labels
waffle-3.0.0 Part of the improvements for Waffle 3

Comments

@sz-piotr
Copy link
Contributor

sz-piotr commented Jun 10, 2019

Motivation:

Common pattern in Smart Contract testing is to create mock smart contracts for testing.
Examples can be found here:

Outside of the blockchain space it is common to use dynamic mocking instead. This reduces amount of code and allow to avoid context switching when writing and reading tests.

An example:

import { createMock } from '@ethereum-waffle/mock';

// setup mock

const tokenMock = await createMock(wallet, [
  'function balanceOf(address holder) view returns (uint)',
]);
const someContract = someContractFactory.deploy(tokenMock.address);

// test against it

it('reverts if no balance', async () => {
  await tokenMock.balanceOf.returns('0'); 
  await expect(someContract.check()).to.be.revertedWith('Not enough balance');
});

it('returns true if positive balance', async () => {
  await tokenMock.balanceOf.returns('1000000')); 
  expect(await someContract.check()).to.equal(true);
});

Related feature: #229

The code will be based on Doppelganger, but will come with a range of novel features and improvements. The result should also include better documentation and tutorial.

@sz-piotr sz-piotr added waffle-3.0.0 Part of the improvements for Waffle 3 and removed enhancement labels Dec 20, 2019
@sz-piotr sz-piotr mentioned this issue Dec 20, 2019
33 tasks
@marekkirejczyk marekkirejczyk changed the title Integrate Doppleganger into waffle Add dynamic Smart Contracts mocking Mar 4, 2020
@marekkirejczyk
Copy link
Contributor

Released in Waffle 3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waffle-3.0.0 Part of the improvements for Waffle 3
Projects
None yet
Development

No branches or pull requests

2 participants