Questions tagged [mocha]

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

30 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
1answer
137 views

Test contract internal functions

I'd like to test a contract internal functions. I used to inherit the contract and test it with truffle but that involved Solidity test files. Can I do the same with my current stack (hardhat/mocha/...
3
votes
0answers
105 views

Truffle - Stub contract functions in Mocha

How do I stub out contract functions while testing in truffle in javascript. Normally in mocha I would import sinon and do a sinon.stub command. It doesnt seem that I can import npm modules into the ...
3
votes
0answers
387 views

Unit testing with chai-as-promised: how to test for two possible errors with rejectedWith()?

I am new to asking questions here and I am sorry if my question is not correctly asked! I am currently testing some smart contracts with truffle and have some problems with testing for exceptions. ...
2
votes
1answer
170 views

Trying to understand why my test.js fails

I have a function that is not passing my tests in JS but the function works as expected in Remix. Can you help me contract.sol function test1 () public view returns(bool){ return(true); } ...
2
votes
0answers
607 views

Truffle test - No events were emitted + TypeError: test.titlePath is not a function

1) test_initial_badge_creation > No events were emitted 2 passing (2s) 1 failing /usr/local/lib/node_modules/truffle/node_modules/mocha/lib/reporters/base.js:178 failures.forEach(...
2
votes
0answers
50 views

Configure Truffle to automatically run tests before contract deployment

How do I configure Truffle to automatically carry out all my tests before it deploys the smart contract? Ideally, it should also halt deployment in case of any test errors.
2
votes
1answer
448 views

How do I close web3 such that mocha tests exit properly?

I'm writing a simple NodeJS (Node 9.4.0) server that's using web3 (1 beta) to interact with Ethereum. I've created a simple utility web3 as follows: const Web3 = require('web3') const url = process....
1
vote
1answer
15 views

How to test ether value in truffle test script using Mocha and chai

I'm having a method inside my contract which return a variable having value is 100 ether for example. E.g: uint256 private baseline constructor() { baseline = 100 ether; } function getBaseline() ...
1
vote
0answers
18 views

Cannot call method with mocha

I am running some test in my first smart contract called Inbox.sol. I Want to call the method .message in order to see if it is equal to the default variable I use when I deploy the contract with web3....
1
vote
0answers
376 views

Mocha timeout when running truffle test. Works fine on ganache, not on public networks

This is the error I get when running truffle test --network kovan: 1) "before all" hook: prepare suite Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if ...
1
vote
1answer
164 views

Unable to install Mocha Web3 and Ganache-cli

I have been trying to install mocha,Web3 and ganache all through one command but I am facing an issue while installing can someone help me in sorting our this error. Quick response will be appreciated ...
1
vote
0answers
366 views

Mocha timeout, not resolving promise of large array from method.mymethod.call()

I'm trying to test a contract getter method that returns a large array. I am testing using the web3 library in Mocha with ganache-cli provider. My contract deploys alright, but trying to call the ...
1
vote
0answers
278 views

Invalid number of arguments to Solidity function when calling call from unit test

I have a problematic unit test in a suite. It's pretty simple: it("SapienToken deployed with SPN symbol", async function() { let SPN = await SapienToken.new(TokenController.address, Owned.address)...
1
vote
0answers
275 views

Adding payable to my contract constructor causes the contract deployment cost to be really high ~100 Ether

Here is an abstract/interface contract I created because I want to call this contract which will be deployed before my other contracts. It just holds the addresses of all the contracts I have deployed....
1
vote
0answers
83 views

how to use the contract instance for multiple functions?

I am trying to test the exchange where two types of tokens are trading. I want to set those tokens in exchange and trying to trade them between two accounts, but i am unable to get the updated ...
0
votes
0answers
33 views

How to write Test case for Internal functions in solidity which inherits the ERC721

**This is my Smart Contract code which has inherited the ERC721 and I want to write the test case for _setTokenURI ** contract ProductNFT is ERC721 { constructor () public ERC721(_tokenName,...
0
votes
1answer
97 views

Is it possible to send ether to a contract after deployment inside a hardhat test?

This is using Hardhat with ethers.js: My test wants to deploy a contract and then I want to send ether to it: const { ethers } = require("hardhat"); describe("HandleEther contract",...
0
votes
0answers
71 views

Use contract from outside contract folder in hardhat test

When I try to import a contract from other artifacts folders or node modules into the dapp test using this.LinkToken = await ethers.getContractFactory('@chainlink/contracts/src/v0.4/LinkToken.sol') ...
0
votes
1answer
12 views

Unit testing does not fail when I add 1 to the variables to be equated to

Just started with unit testing after creating my token, but the test cases are passing even if I add a number in the equals bracket. In test one, if I change to expect(await instance.balanceOf(...
0
votes
1answer
17 views

Aave Flashloan `reverted with reason '73'`

I'm getting an error when attempting to execute an Aave V2 Flashloan within a Hardhat-mocha test while connected to a fork of the Kovan network. It's unclear to me what revert reason "73" ...
0
votes
0answers
17 views

How to test multiple contracts?

I have created a Ethereum dapp that has multiple contracts that access one another and use methods within each other. I would like to create a Javascript test which would emulate a use-case for this ...
0
votes
0answers
13 views

Testing a smart contract with Truffle

so I'm testing a smart contract a js framework called mocha and running the test through truffle. require('chai') .use(require('chai-as-promised')) .should() contract('Token', (accounts) => { ...
0
votes
0answers
38 views

Withdraw funds from contract

I made the following withdraw function in my smart contract: function withdraw() public onlyOwner { (bool success, ) = msg.sender.call{value: address(this).balance}(""); } I call ...
0
votes
0answers
156 views

How do I write a unit test with Mocha/Waffle to see if the transaction sends the correct amount of tokens to each person?

Intro Basically I have a contract that overrides the transfer function in IERC20. Contract TokenA is IERC20{ function transfer(address recipient, uint256 amount) public override returns (bool) { ...
0
votes
0answers
25 views

error.message.indexOf is not a function truffle ganache

for truffle developers var Election = artifacts.require('./Election.sol'); contract("Election",function(accounts){ var electionInstance; it("throws an exception for double voting"...
0
votes
0answers
6 views

Truffle testing:How to convert from Mocha to Solidity

I am following the tutorial at: truffle- Mocha It shows a mocha code for testing. I want to do the testing in Solidity. const SimpleContract = artifacts.require("SimpleContract"); contract(...
0
votes
1answer
31 views

Error while testing a smart contract functionality with Mocha

I wanted to test my code functionality with the Mocha Framework, but every time it responded me with an error, not an assertion. The specific error was: Error:cannot find module "ganache-cli&...
0
votes
0answers
40 views

How to use Mocha reporter in Truffle console?

I work with Truffle and Windows Powershell. I set Mocha in truffle-config.js like: module.exports = { . . . mocha: { reporter: '...
0
votes
1answer
145 views

Solc-js: error "before each" hook for "deploys a contract": ReferenceError: accounts is not defined

I have just started building contracts. Kindly help me in resolving this error. Attached image of error. Lottery/contract/Lottery.sol: pragma solidity ^0.4.17; contract Lottery{ address public ...
0
votes
1answer
242 views

I have written a javascript code for compiling the solidity code but it's showing error

I was trying to compile my contract using solc compiler but it returning me some errors. I will place my solidity code along with the error that I am getting here. Please help me out to sort this ...