Questions tagged [mocha]

Mocha is a JavaScript test framework for Node.js programs.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 views

Hardhat impersonateAccount returns an empty "whale" wallet

I am impersonating a whale wallet so that I transfer ETH from that wallet to my flashloan contract for the sake of performing an example flash loan using my test script. I check the address to make ...
ChewyCorndog's user avatar
0 votes
0 answers
30 views

How to run a hardhat node in the cloud

I have a set of tests i run locally using hardhat and mocha. However, I would like to run these tests on every push to prod. How can I start a hardhat node in the cloud for the testing.
Ibra's user avatar
  • 71
1 vote
0 answers
32 views

How to fix `Invalid callback object specfied` error when deploying a smart contract?

My smart contract: // SPDX-License-Identifier: MIT pragma solidity 0.8.19; contract Inbox { string public message; constructor (string memory initiialMessage) { message = ...
Jyobala's user avatar
  • 11
0 votes
2 answers
27 views

Trying to deploy simple smart contract in a local nodejs, mocha environment but receiving error from: 'npm run test'

I am trying to deploy a simple smart contract for testing. Attached are the output of: 'npm run test' as well as my test.js file and my package.json file I hope its something obvious sorry if this is ...
bakayaro's user avatar
2 votes
1 answer
242 views

TypeError: Cannot read properties of undefined (reading 'checkUpkeep')

i'm getting this error while testing patrick collins smart-contract-lottery project, below is the part where the error coming from. describe("checkUpkeep", async function () { ...
Gautam's user avatar
  • 33
0 votes
0 answers
22 views

logging events while testing

In Current Version of ethers v6 ., once the event is emitted how we should log them ., because the older method of logging from transaction receipt is not working " for example this is my ...
jeevan siddu's user avatar
1 vote
1 answer
132 views

Hardhat Errors: Invalid value null supplied to : QUANTITY

Getting this error some times while testing a Hardhat file. But when I cancel that script and run that same script again, it works. The complete error is here: "before each" hook: Before ...
Pankaj Jagtap's user avatar
0 votes
0 answers
50 views

Burn ERC1155 from ERC721 Contract

Would like to understand on how burn mechanism works on ERC1155, the ERC1155 is an airdrop token that will be use on GeneratedNFT.sol mint function so that it will to mint an ERC721 token and burn the ...
0xhaz's user avatar
  • 3
0 votes
2 answers
536 views

Testing ERC20 Token: Unable to cover Transfer and Approve from null/zero address

I'm working on a project using Hardhat and OpenZeppelin library for an ERC20 token. I've been able to achieve almost 100% coverage, but there are two lines that I'm struggling to cover: transfer ...
Mati's user avatar
  • 121
0 votes
0 answers
289 views

Cannot read properties of undefined (reading '0')

I am following FreeCodeCamp's javascript Blockchain/SmartContract course. Facing issue at lesson 9 staging test. Contract deployment and unit tests are running fine. Running mocha test on sepolia ...
mohmaya's user avatar
1 vote
1 answer
328 views

Testing for success (no revert) in Hardhat

I'm using hardhat with mocha and chai to write tests for a contract. I'm trying to write a test that will expect a function call to be successful (not to revert); the function does not emit any events....
Origin's user avatar
  • 133
1 vote
2 answers
1k views

How to create a raw ERC-4337 UserOperation from scratch and then send it to bundler?

I want to create a raw ERC-4337 UserOperation. I am using ethers library to write the test cases . According to ERC-4337 official documentation , the UserOperation is a struct with many fields . ...
Gaurav Pant's user avatar
0 votes
2 answers
81 views

How do I test burning tokens in my ICO contract?

I'm writing tests for the burn func in ICO.sol The first two tests are passing, but when I come to test where the tokens are indeed burned, the state of the ICO seems to change. To burn tokens, the ...
kihiuFrank's user avatar
0 votes
0 answers
84 views

Mocha Tests unexpected error

My tests where running well but not when I run yarn hardhat test, I get the error below. Error An unexpected error occurred: TypeError: describe is not a function at Object.<anonymous> (/...
kihiuFrank's user avatar
1 vote
1 answer
50 views

why do i get the GS200 error when setting up safe?

I'm trying to set up a gnosis safe with two owners and threshold of two but i keep getting this error and i'm not sure why. I checked my inputs with other scripts the have the same type of inputs ...
user120185's user avatar
1 vote
0 answers
20 views

Trying to run a javascript test through Truffle. Truffle is not able to read the javascript file or I cannot understand the issue here

I am trying to run truffle test to test a javascript file on windows through powershell. The results keep showing a syntax error on the first character of the .js test file after compiling all ...
GimmeGinNtonic's user avatar
4 votes
2 answers
2k views

How to work with block timestamps in ethers and hardhat?

I have a time-dependent contract that has two require statements function launch(uint256 _goal, uint32 _startAt, uint32 _endAt) external { require(_startAt >= block.timestamp, "...
Kate Johnson's user avatar
0 votes
0 answers
22 views

Accessing the "accounts" variables of the local blockchain

here's the following code : const Vault = artifacts.require("Vault"); describe("Write features of vault", function (accounts) { it("able to receive money", async ...
Raphael's user avatar
  • 41
0 votes
1 answer
26 views

Is there any method in web3js library to know if a given address is a contract address or an wallet's account address?

I am writing solidity tests . I am using JS for testing . Is there any method in web3js library to know that a certain address is a contract's address or not ?
Gaurav Pant's user avatar
0 votes
1 answer
1k views

Getting "Runtime error: code size to deposit exceeds maximum code size" when deploying contract with web3 on ganache

I'm new to blockchain. I'm trying to deploying a contract through web3 on ganache (the npm version) for testing purpose with mocha. During the deployment attempt, ganache returns with the following ...
yanosh's user avatar
  • 1
0 votes
1 answer
159 views

Time based contract testing on Hardhat

So I have this function that will cancel the campaign for my crowdfund contract. I have created a test script for this but doesnt seems to work. Please have a look at my syntax below CrowdFund.sol // ...
0xhaz's user avatar
  • 3
1 vote
1 answer
1k views

AssertionError: expected Promise{…} to equal 1

Code: describe("uploading post", async () => { let result, postCounter const hash = "whatever" before(async () => { result = await ...
Sina Blank's user avatar
0 votes
1 answer
114 views

Testing Struct Data

I have a struct and getter function that should return the id to zero when I delete it from my function but I dont know on how to return from my testing script Here is my struct, mapping & ...
0xhaz's user avatar
  • 3
0 votes
1 answer
31 views

Trying to test a simple contract but failing

I am currently following my first Ethereum course, and I am trying to test the a very simple contract, but it keeps failing. When I run the contract on Remix, everything seems to be working fine, so I'...
Yotam's user avatar
  • 103
1 vote
1 answer
54 views

Principles of Testing Smart Contracts

Generally, when writing tests for smart contracts, how comprehensive do the tests have to be? Also, how does one know what to test (e.g., which line in the function in the original contract file the ...
Will-Up-Vote-If-Good's user avatar
0 votes
0 answers
157 views

got this error while deploying my contract

please help me what is error in above code... this is my code.and it is exact same code what my course teaher taught. compile.js const path = require('path'); const fs = require('fs'); const ...
shivam kumar's user avatar
1 vote
0 answers
606 views

How to load proxy contract's address on implementation contract?

I am learning about Proxy contract . I have been writing contracts in Remix from the day I started learning Solidity . I will explain my problem statement in some points . CounterV1 is implementation ...
Gaurav Pant's user avatar
0 votes
1 answer
82 views

No events emitted when running test in mocha

Good day, I'm new to blockchain and doing a university project. my contract file seems to be compiling but all my test cases are failing, saying no events emitted. I've included the test case and ...
Ash420's user avatar
  • 1
0 votes
1 answer
42 views

nested mapping not working during test

I have a function that have a modifier that it must be the owner before it can cancel the order and I'm using the nested mapping that i've created for this struct as below //mapping mapping(bytes32 =&...
0xhaz's user avatar
  • 3
0 votes
1 answer
34 views

Event test failing because of address's casing

I am trying to test if the event is emitted with the correct arguments however my tests are failing because of some casing issue. What is the best away to overcome this issue?
maxime's user avatar
  • 96
0 votes
0 answers
42 views

Custom error not working during test

I tried to use custom error instead of using a require in modifier like so: modifier tokenExist(bytes32 ticker) { if(tokens[ticker].tickerAddress != address(0)) revert Exchange__TokenNotExist()...
0xhaz's user avatar
  • 3
1 vote
0 answers
122 views

Mocha Testing timeout in package.json or Hardhat Config file?

i have a conflicting question. Where should I put the mocha implementation in package.json or hardhat config file? i would assume that if i put "mocha":{ "timeout" : x} in package....
Laurent Knauss's user avatar
2 votes
1 answer
44 views

How do you know when an operation should be performed synchronously or asynchronously in smart contract tests?

What operations are usually perform asynchronously in smart contract tests, and what operations are usually performed synchronously in smart contract tests? When are each of these usually used?
Will-Up-Vote-If-Good's user avatar
2 votes
1 answer
133 views

How do mocha and chai work?

I got this snippet from: https://hardhat.org/tutorial/testing-contracts In this test, what does const { expect } = require("chai") mean? Also, I thought describe() is from the Mocha ...
Will-Up-Vote-If-Good's user avatar
1 vote
0 answers
22 views

How does describe() in mocha work here?

I got this snippet from: https://hardhat.org/tutorial/testing-contracts In this test, what does const { expect } = require("chai") mean? Also, I thought describe() is from the Mocha ...
Will-Up-Vote-If-Good's user avatar
3 votes
1 answer
789 views

Why are there so many async and await in smart contract tests?

What’s the use of async and await and why are there so many of them in smart contact tests?
Will-Up-Vote-If-Good's user avatar
2 votes
1 answer
308 views

What is a good way to learn Solidity? [duplicate]

I’ve been watching YouTube videos and learning from Udemy on solidity for a year. I have basic understanding of blockchain. My problem is that although the instructors show the what to do and how to ...
Will-Up-Vote-If-Good's user avatar
1 vote
0 answers
64 views

Hardhat: Report tests without executing them

according to mocha docs there is --dry-run flag that does it, but it does not work with hardhat: Error HH305: Unrecognized param --dry-run when running yarn hardhat test
Peersky's user avatar
  • 46
1 vote
1 answer
608 views

How to cause a .call to revert in hardhat test

I am trying to cover all of my lines in my smart contract unit tests with hardhat, and I am not sure how to test the Raffle__TransferFailed() error. Is there some way to force this transaction to fail?...
Rohan Nero's user avatar
  • 1,577
1 vote
1 answer
762 views

How to use variables set inside a beforeEach with hardhat testing

describe("func", function () { let owner beforeEach(async function () { const [owner] = await ethers.getSigners() }) it.only("should correctly set the address", ...
Rohan Nero's user avatar
  • 1,577
0 votes
2 answers
1k views

Exceeds block gas limit or base fee exceeds gas limit

I am learning web3, and a person is using solidity ^0.4.5, and I am adapting his code to solidity ^0.8.9, and I am facing this problem when if I have 1000 here: factory = await new web3.eth.Contract(...
Efim Rubin's user avatar
0 votes
1 answer
115 views

Chain tests in mocha framework with smart contract testing

I am doing smart contract testing with hardat and mocha framework. Suppose I have two following it blocks testing contract A. it('test1', () => { contractA.updateValue(val); // some other ...
Tahlil's user avatar
  • 218
1 vote
0 answers
708 views

Promise is returning timeout error [Timeout of 20000ms exceeded]

Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/hh-fcc/hardhat-smartContract-lottery-fcc/test/...
DorianDaSilva's user avatar
0 votes
1 answer
154 views

How should I approach testing functions that call already deployed contracts? [ethers.js] [chai] [mocha]

Suppose my contract utilizes the WETH contract (address 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2) in some manner. I can write test cases with Chai/Mocha just fine for most cases (they're "...
greentriangles1's user avatar
2 votes
1 answer
134 views

Truffle contract factory test with Javascript

Here is my smart contract source code. // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract CampaignFactory { address[] public deployedCampaigns; function createCampaign(uint ...
enthusiastic's user avatar
1 vote
1 answer
123 views

How to write the javascript test code on whether a smart contract function is successfully executed or not?

I wrote a lottery smart contract and gonna to test an "enter" functionality of the smart contract. The below code is javascript test code for the "enter" function of the smart ...
enthusiastic's user avatar
0 votes
1 answer
29 views

Hi,I had written the code for voting purpose.Can you guys help me out to write a truffle testing code for this?

// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract voting{ address private onlyowner; uint private Virat =0; uint private Rohit =0; constructor(){ onlyowner = msg.sender; } ...
Wiswa's user avatar
  • 11
0 votes
1 answer
2k views

solidity function functionCall from openzeppelin-contracts-accounts reverted

I was calling flashLoan function using following parameters for hardhat testing expect( await this.pool.flashLoan(100, attacker.address, this.token.address, 0x00) ).to.be.not.reverted; This is ...
Tanjin Alam's user avatar
0 votes
2 answers
139 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% ...
Adam's user avatar
  • 103
0 votes
2 answers
1k views

How to test if msg.value is 1 ether in test

I have a function which mints when 1 eth is send to it. The function is function _mint() public payable{ require(msg.value == 1 ether , "Send more ethers: 1 ether is required"...
Haris's user avatar
  • 123