Questions tagged [waffle]
The waffle tag has no usage guidance.
29
questions
0
votes
2
answers
217
views
Testing contract selfdestruct in Hardhat - Chai matchers
I'm writing unit tests for a solidity contract in a Hardhat project and I can't seem to find a selfdestruct matcher. Solidity Chai Matchers are a set of helper functions that make testing solidity ...
0
votes
0
answers
51
views
Sending eth while testing a smart contract
const sendEth = ethers.utils.parseUnits("0.1")
describe("fund", async function () {
it("update the amount funded data structure", async function () {
const ...
1
vote
1
answer
2k
views
Getting an error of : "TypeError: Cannot read properties of undefined (reading 'provider')"
I am getting this error
TypeError: Cannot read properties of undefined (reading 'provider')
Here is my code for buy-coffee.js inside of scripts.
// We require the Hardhat Runtime Environment ...
1
vote
1
answer
247
views
Testing BigNumber values in Hardhat unit tests the safest way?
I have seen at least three different ways to test two BigNumbers.
Using waffle BigNumber
Convert toString()
Cast to Number
As an example hardhat test with chai and waffle.
const sendValueBN = ethers....
1
vote
0
answers
27
views
Waffle revertedWith() matcher docs misleading?
In the Waffle documentation here, it shows that revertedWith() can be used with a regular expression. When used I am presented with an error claiming otherwise, already wasted too much time on this ...
0
votes
1
answer
443
views
Hardhat tests - deploy with arguments [typescript]
I am writing tests for my contract in typescript. I am deploying the contracts like this:
import { Contract } from "../typechain-types/index";
import ContractArtifact from "../artifacts/...
1
vote
1
answer
224
views
to.be.revertedWith("Error Message ") returning failed test despite custom error matching "Error Message"
I'm running tests on a raffle smart contract from Patrick Collin's tutorial. I have custom errors in my Solidity file.
When running tests that expect the transaction to be reverted, every single time ...
3
votes
2
answers
421
views
Override mock contracts's address in test
I have a smart contract that is dependent on a pre-deployed ERC-20 smart contract that is always deployed to the same address (in the local test network as well as public ones).
I want to override the ...
0
votes
1
answer
159
views
Migrating from Waffle
sorry for a newbie question. I have a file from my study with the following code:
const { expect, assert } = require("chai");
const { ethers } = require("hardhat");
const { ...
0
votes
1
answer
205
views
hardhat & waffle - deploy a contract from an address
I'm trying to test a factory contract using hardhat and waffle. I have a contract called Domain:
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
...
0
votes
1
answer
777
views
Unable to transfer eth into contract in hardhat
I am working on some ERC20 tokens in which user have to send it to get tokens,
i am getting some error while running it!!
i am stuck at the
const txHash = await addr1.sendTransaction({
to: ...
0
votes
1
answer
269
views
Solidity: Mock function return value
I'm writing an ERC-721 contract but I'm struggling to write a proper unit test when all token ids are minted.
Function I want to test:
uint256 public constant MAX_SUPPLY = 10000;
function ...
1
vote
2
answers
478
views
How do I tell hardhat and waffle where my test is?
I created a basic hardhat sample project. When I do npx hardhat test , Hardhat is running the out of the box test in
scripts/sample-script.js
(which supposedly is the deployment pipeline) and hardhat ...
4
votes
2
answers
3k
views
How to mock smart contract function for testing (in hardhat)
In my Test I want to mock an external function that I call inside my smart contract to test both conditions without writing and deploying an extra fake smart contract.
My Contract
//SPDX-License-...
1
vote
1
answer
2k
views
Hardhat + Waffle + Hardhat: Nonce has already been used
This week at a talking by our friend Patrick Collins during the Chainlink Spring 2022 Hackathon schedule, I took knowledge of the possibility of moving ahead of time on the blockchain during tests:
...
1
vote
1
answer
1k
views
Hardhat/Waffle/Chai : Display Revert Reason?
I'm testing a simple call and expect it to not revert
await expect(swapCall).to.not.be.reverted
The test fails currently and I get a
AssertionError: Expected transaction NOT to be reverted
How do I ...
0
votes
2
answers
133
views
Testing against local network vs testnet
I have a simple test to mint tokens on a newly deployed contract.
While developing, I was testing locally and the test never failed.
Now that the contract is deployed to the testnet, I get a 50% ...
8
votes
3
answers
6k
views
How to get more than 20 Signers with ethers.js / hardhat / waffles
I'm using Hardhat with the waffle plugin to test my smart contract.
To get Signers (ether.js) I'm using :
await ethers.getSigners();
This return an array with 20 signers.
If I call again, I get the ...
13
votes
3
answers
6k
views
Testing for custom error reverts in hardhat
I have a custom error described as such:
error AlreadyListed(address nftAddress, uint256 tokenId);
And in my tests, I'd like to check to see that it's thrown:
expect(await nftMarketplace.listItem(...
0
votes
1
answer
412
views
Can't install Waffle on M1: 'assert.h' file not found
I'm trying to install Waffle on an M1 Mac.
Per documentation, after creating a fresh new project with npx hardhat, I use npm like this: npm install --save-dev ethereum-waffle
This is the result:
npm ...
6
votes
3
answers
3k
views
Property 'revertedWith' does not exist on type 'Assertion'
I'm running a test using waffle in hardhat.
import { assert, expect } from "chai"
.
.
.
it("can only be changed through governance", async () => {
await expect(box.store(...
0
votes
1
answer
832
views
Hardhat Basic Test Fails
I had a few problems with testing smart contracts that seemed perfectly fine to me. I have reduced the repository further and further and am left with this.
MappingContract.sol
pragma solidity = 0.8....
0
votes
1
answer
110
views
Waffle Ethereum tests: advancing N blocks efficiently [duplicate]
Title really says it all. I am writing a test for a smart contract that needs to wait 200 blocks before something can happen. Is there any way I can advance forward 200 blocks in order to test the ...
0
votes
1
answer
537
views
Getting "Provider not found" while testing my contract with waffle
I am testing my contract using Waffle and I am following the documentation provided, using const provider = new MockProvider();
to get a provider for testing.
An error was raised in expect().catch() ...
0
votes
1
answer
701
views
Smart Contract Testing - ethereum-waffle expect function
Can someone please explain the significance of the location of the "await" keyword in the "expect" function from the waffle testing framework?
for example:
this passes (assume its ...
0
votes
2
answers
1k
views
How to use changeEtherBalance from waffle-hardhat?
I want to check if the ether balance of an account decreased after the transaction using changeEtherBalance I tried to follow the waffle docs but couldn't do it either.
await token.connect(...
3
votes
1
answer
348
views
Struggling with waffle - mock not initialized
I've got problem with mocking method call. Below is my solidity code and test.
I would like to pass mock into withdraw method and check if transfer function was called. But instead I am getting error &...
13
votes
3
answers
9k
views
Hardhat get last block timestamp, block number, block hash, nonce, gas limit, gas used
How to get last block information in a Hardhat Waffle test?
I checked here
https://hardhat.org/hardhat-network/#json-rpc-methods-support
And here
https://hardhat.org/hardhat-network/reference/
it ...
2
votes
1
answer
395
views
How to mock out a signed transaction w/ Waffle Mocks?
When applying Waffle mock to simulate a contract method that must be explicity signed an error is thrown:
Error: Contract with a Signer cannot override from (operation="overrides.from", code=...