@ethereum-waffle/mock-contract
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -58,3 +58,3 @@ "use strict"; | ||
} | ||
const tx = await contract.populateTransaction[functionName](params); | ||
const tx = await contract.populateTransaction[functionName](...params); | ||
const data = tx.data; | ||
@@ -70,3 +70,3 @@ let result; | ||
mockedContract.call = async (contract, functionName, ...params) => { | ||
const tx = await contract.populateTransaction[functionName](params); | ||
const tx = await contract.populateTransaction[functionName](...params); | ||
const data = tx.data; | ||
@@ -73,0 +73,0 @@ return mockContractInstance.__waffle__call(contract.address, data); |
@@ -53,3 +53,3 @@ import { Contract, ContractFactory, utils } from 'ethers'; | ||
} | ||
const tx = await contract.populateTransaction[functionName](params); | ||
const tx = await contract.populateTransaction[functionName](...params); | ||
const data = tx.data; | ||
@@ -65,3 +65,3 @@ let result; | ||
mockedContract.call = async (contract, functionName, ...params) => { | ||
const tx = await contract.populateTransaction[functionName](params); | ||
const tx = await contract.populateTransaction[functionName](...params); | ||
const data = tx.data; | ||
@@ -68,0 +68,0 @@ return mockContractInstance.__waffle__call(contract.address, data); |
{ | ||
"name": "@ethereum-waffle/mock-contract", | ||
"description": "Mock smart contracts in a smart way.", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"author": "Marek Kirejczyk <account@ethworks.io> (http://ethworks.io)", | ||
@@ -47,5 +47,5 @@ "repository": "git@github.com:EthWorks/Waffle.git", | ||
"devDependencies": { | ||
"@ethereum-waffle/chai": "^3.1.1", | ||
"@ethereum-waffle/compiler": "^3.1.1", | ||
"@ethereum-waffle/provider": "^3.1.1", | ||
"@ethereum-waffle/chai": "^3.1.2", | ||
"@ethereum-waffle/compiler": "^3.1.2", | ||
"@ethereum-waffle/provider": "^3.1.2", | ||
"@types/chai": "^4.2.3", | ||
@@ -52,0 +52,0 @@ "@types/chai-as-promised": "^7.1.2", |
@@ -11,3 +11,3 @@ ![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png) | ||
## 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`. | ||
In the current version of waffle (v3.x.x) you will install this package as a dependency of the main waffle package - `ethereum-waffle`. | ||
@@ -124,3 +124,3 @@ ``` | ||
function setRichness(uint256 _richness) { | ||
function setRichness(uint256 _richness) public { | ||
richness = _richness; | ||
@@ -134,10 +134,10 @@ } | ||
```js | ||
const {use, expect} = require('chai'); | ||
const {ContractFactory, utils} = require('ethers'); | ||
const {MockProvider} = require('@ethereum-waffle/provider'); | ||
const {waffleChai} = require('@ethereum-waffle/chai'); | ||
const {deployMockContract} = require('@ethereum-waffle/mock-contract'); | ||
import {use, expect} from 'chai'; | ||
import {Contract, ContractFactory, utils, Wallet} from 'ethers'; | ||
import {MockProvider} from '@ethereum-waffle/provider'; | ||
import {waffleChai} from '@ethereum-waffle/chai'; | ||
import {deployMockContract} from '@ethereum-waffle/mock-contract'; | ||
const IERC20 = require('../build/IERC20'); | ||
const AmIRichAlready = require('../build/AmIRichAlready'); | ||
import IERC20 from './helpers/interfaces/IERC20.json'; | ||
import AmIRichAlready from './helpers/interfaces/AmIRichAlready.json'; | ||
@@ -147,12 +147,16 @@ use(waffleChai); | ||
describe('Am I Rich Already', () => { | ||
async function setup() { | ||
const [sender, receiver] = new MockProvider().getWallets(); | ||
const mockERC20 = await deployMockContract(sender, IERC20.abi); | ||
const contractFactory = new ContractFactory(AmIRichAlready.abi, AmIRichAlready.bytecode, sender); | ||
const contract = await contractFactory.deploy(mockERC20.address); | ||
return {sender, receiver, contract, mockERC20}; | ||
} | ||
let contractFactory: ContractFactory; | ||
let sender: Wallet; | ||
let receiver: Wallet; | ||
let mockERC20: Contract; | ||
let contract: Contract; | ||
beforeEach(async () => { | ||
[sender, receiver] = new MockProvider().getWallets(); | ||
mockERC20 = await deployMockContract(sender, IERC20.abi); | ||
contractFactory = new ContractFactory(AmIRichAlready.abi, AmIRichAlready.bytecode, sender); | ||
contract = await contractFactory.deploy(mockERC20.address); | ||
}); | ||
it('returns false if the wallet has less then 1000000 coins', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.returns(utils.parseEther('999999')); | ||
@@ -163,3 +167,2 @@ expect(await contract.check()).to.be.equal(false); | ||
it('returns true if the wallet has at least 1000000 coins', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.returns(utils.parseEther('1000001')); | ||
@@ -170,3 +173,2 @@ expect(await contract.check()).to.equal(true); | ||
it('reverts if the ERC20 reverts', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.reverts(); | ||
@@ -177,3 +179,2 @@ await expect(contract.check()).to.be.revertedWith('Mock revert'); | ||
it('returns 1000001 coins for my address and 0 otherwise', async () => { | ||
const {contract, mockERC20, sender, receiver} = await setup(); | ||
await mockERC20.mock.balanceOf.returns('0'); | ||
@@ -180,0 +181,0 @@ await mockERC20.mock.balanceOf.withArgs(sender.address).returns(utils.parseEther('1000001')); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
185
151692