Questions tagged [mocha]
Mocha is a JavaScript test framework for Node.js programs.
69
questions
0
votes
1answer
13 views
Truffle test: Problem with understanding the test
I am trying to understand the test provided at:
Tutorial
("Test balance after deposit", function() {
return SimpleBank.deployed().then(function(instance) {
sb = instance;
...
0
votes
1answer
21 views
Perimeter of mocha, waffle and chai
Here is what i've understood (please tell me if i am wrong):
Mocha (mochajs.org) is a testing framework
Waffle (getwaffle.io) is another testing framework
chai: This is not a framework, this is a ...
0
votes
0answers
4 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(...
1
vote
1answer
17 views
How to resolve the issue while trying to test my contract
I'm new to blockchain development and can't figure out what I have done wrong. This is my smart contract Election :
pragma solidity ^0.5.0;
contract Election {
struct Candidate {
uint ...
0
votes
1answer
23 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
1answer
19 views
Synchronizing test and web3 enabled nodejs service
I have a test suite running in truffle, and an external web3 connected node service running - both connected to a ganache-cli network.
My problem is: my tests are supposed to pick up an event ...
0
votes
0answers
25 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
0answers
37 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 ...
1
vote
2answers
127 views
solc-js error: “before each” hook for “deploys a contract”: SyntaxError: Unexpected token u in JSON at position 0
The issue is probably here: const { interface, bytecode } = require('../compile');.
interface in the test file is undefined.
inbox/contracts/Inbox.sol:
pragma solidity ^0.7.0;
contract Inbox {
...
1
vote
1answer
53 views
Get contract's balance in js test
When getting contract's balance on Remix, it returns the correct answer.
But when the same function is called with JS Test, it returns a lot of junk.
I referred to How to get a contract's balance ...
2
votes
1answer
1k views
Error: you must provide the json interface of the contract when instantiating a contract object
That's the error that occurs when I try to test my contract.
Can someone tell me what the problem is?
That's the code for the test:
const assert = require('assert');
const fs = require('fs');
const ...
2
votes
1answer
1k views
When testing a contract, NodeJS returns: “SyntaxError: Unexpected token u in JSON at position 0”
My NodeJS script gives me this error:
1)"before each" hook for "deploy a factory and a lottery"
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse((anonymous))
at Context.(anonymous) ...
1
vote
2answers
213 views
Mocha assertions not returning correctly on assert.equal with BN
Is this an issue with deep matching/object identity?
AssertionError: expected <BN: 204fce5e3e25026110000000> to equal <BN: 204fce5e3e25026110000000>
It seems strange that chai.should ...
2
votes
1answer
225 views
Getting an 'invalid opcode' calling a solidty function from test file
im in the process of learning about ethereum and Solidity, and im having a problem calling a payable function from a test file.
This is my contract
pragma solidity >=0.4.22 <0.6.0;
//pragma ...
1
vote
0answers
236 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
121 views
I got this error during truffle testing. AssertionError: it returns true: expected { Object (tx, receipt, …) } to equal true
DappToken.sol
function transfer(address _to, uint256 _value) public returns (bool success){
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
balanceOf[...
1
vote
2answers
358 views
How to test a custom fallback function using web3.js?
I am trying to implement a proxy pattern. I have a proxy contract and a lottery contract, and I would like the proxy contract to delegate calls to the lottery contract.
To test that the function ...
0
votes
1answer
205 views
__callback was called after the specified delay
My smart contract should return the ETH rate from Coinbase api .. So i'm using Provable engine and i'm testing my smart contract locally using ganache and ethereum-bridge .
It's expected that result ...
0
votes
2answers
223 views
Timeout w/ Mocha on deploying a contract
Starting to build the following test suite for a contract. It deploys fine on Remix.
I get the following error message.
1) "before each" hook for "deploys a contract":
Error: Timeout of 20000ms ...
0
votes
1answer
155 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 ...
1
vote
1answer
114 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
1answer
161 views
Mocha and web3.js without await [closed]
Awaiting the resolution of calls to a node works for me, like this example:
describe('some contract', async function () {
...
it('data should be written correctly', async function () {
...
1
vote
2answers
1k views
How to access in JavaScript multiple return values returned from a solidity function
My contract function returns two values. How to access the multiple return values in JavaScript from a mocha testcase?
contract X {
function a() pure public returns(uint,uint) {
uint p=10;
...
2
votes
1answer
101 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);
}
...
0
votes
1answer
270 views
Solidity: How are multiple return values returned?
Working in truffle with TDD testing and am getting some errors when evaluating the return values of some functions.
If a function is returning multiple values in Solidity, how are they presented? Is ...
2
votes
3answers
551 views
Choosing between Javascript and Solidity for testing smart contracts
Truffle offers two ways to test smart contracts: either using test files written as Solidity contracts, or Javascript/Mocha.
https://truffleframework.com/docs/truffle/testing/writing-tests-in-...
0
votes
1answer
364 views
How to define a function inside a truffle contract test [closed]
Is that possible to define a function inside a truffle contract test?
There is a repetitive yet complicated step in truffle test scenario I am working on and wondering would it be possible to ...
0
votes
1answer
223 views
Testing promise in solidity [closed]
}).then(assert.fail).catch (function(error){
assert(error.message.indexOf('revert') >= 0,'msg.value must be less than tokens tokenAvaliable')
})
I have the following code in the test ...
1
vote
1answer
92 views
fromAccount and web3.js
This is my function in solidity
function transferForm(address _from, address _to, uint256 _value) public returns (bool success) {
}
Now i am calling the same function in test file for testing my ...
0
votes
1answer
478 views
Accessing Contract Variables from JS Unit Tests
I am having trouble unit testing my contracts: I am using Mocha, Chai and calling truffle test
I am testing LoanRecord.sol
contract LoanRecord {
public bool on;
...
constructor(...){
...
...
0
votes
1answer
563 views
Too many decimal places error
So I am putting together a test for my contract and this is the it() statement:
it('allows one account to enter', async () => {
await lottery.methods.enter().send({
from: accounts[0],
...
0
votes
1answer
561 views
Testing balance of a contract
I'm trying to test the balance of the contract with truffle, but I'm obviously doing something wrong as the test passes.
it("should check balance", function() {
Lottery.deployed().then(function(...
0
votes
1answer
65 views
Assert(false) not executing
I am running a mocha test for a solidity SC. One of my test function should pass and then, just after that i am calling assert(false), but it is not executing.
it('only manager can call the ...
3
votes
2answers
404 views
How can we compile multiple smart contracts by compile.js file?
My compile.js file is below
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const ballotPath = path.resolve(__dirname, 'contracts', 'blocktitans_ballot.sol');
...
1
vote
1answer
153 views
Testing in solidity with npm not work correctly?
I have a problem like this. I am new to solidity development. I have created a contract like this.
pragma solidity ^0.4.17;
contract Lottery {
address public manager;
address[] public ...
0
votes
2answers
222 views
Mocha test at kill() function
How to test with Mocha and Chai that a call at the kill() function of a Smart Contract (i.e., which does the selfdestruct) has gone right?
1
vote
0answers
325 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 ...
2
votes
0answers
553 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(...
3
votes
2answers
141 views
How to create more test account when using Mocha to test Solidity smart contract?
By default there are only 10 test accounts being created, how do I create more when using Mocha to test smart contract?
I assume Mocha creates a testRPC instance somehow, there must be a way to ...
-2
votes
1answer
883 views
Test in Mocha failing [closed]
I am getting the following error on running the test.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! inbox@1.0.0 test: mocha
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the inbox@1.0....
5
votes
2answers
4k views
Solidity Exceeds block gas limit during Mocha Tests with Ganache-cli
How can I increase the gas limit in this case? The error message is "n: Exceeds block gas limit" or "base fee exceeds gas limit".
I think there is some kind of api I need to set the block gas limit ...
0
votes
1answer
369 views
Solidity Ganache/Mocha test error: base fee exceeds gas limit
I got this when I was running the Mocha test with Ganache package to test the Solidity smart contracts. Then I got base fee exceeds gas limit error. Is that because my contracts are too large? Should ...
1
vote
3answers
1k views
Using ganache-cli provider causes “Error: Provider not set or invalid”
I'm trying to write and run tests for my smart contract and I get this error: "Error: Provider not set or invalid"
Smart contract code:
const assert = require('assert');
const ganache = require('...
1
vote
0answers
112 views
Why would you use promises over async when writing JS unit tests in truffle? [closed]
I'm getting started with writing JS unit tests in the Truffle framework. I'm curious to learn when to use promises over async? On the surface, async seems a lot cleaner and easier to use for testing ...
2
votes
0answers
49 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.
3
votes
0answers
96 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 ...
9
votes
2answers
1k views
How can I debug a truffle JS unit test with vscode?
I am using visual studio code and truffle and would like to easily debug my JavaScript tests.
A similar question has been asked here: how can I run a truffle test in a debugger?. This has been ...
3
votes
2answers
388 views
How can I pass Mocha switches when calling Truffle?
When calling truffle test some_test.js, I would like to pass Mocha switches.
For example: truffle --no-colors test some_test.js works fine.
However: truffle --reporter json-streams test some_test.js ...
0
votes
1answer
214 views
Truffle test with non-standard deployment
I have a few contracts that I wanted to test using Mocha (that comes with Truffle). These contracts all require parameters in their constructor. I have modified the "2_deploy_contracts.js" file and it ...
1
vote
1answer
663 views
New Ganache (1.1.0-beta.0) Causes Invalid JSON RPC response
Hey I'm running a test where I expect a transaction to throw. Instead of successfully returning a receipt with a status of 0, or throwing a revert error, it throws this invalid JSON RPC response error....