Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mocha]

The tag has no usage guidance.

1
vote
1answer
45 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 () { ...
0
votes
1answer
55 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
21 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
84 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 ...
1
vote
2answers
176 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
79 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
52 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
46 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
103 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
107 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
92 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
39 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 ...
1
vote
1answer
173 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
78 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
114 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
150 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
384 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
86 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
395 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....
2
votes
2answers
1k 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
322 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
618 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
93 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 ...
1
vote
0answers
40 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.
1
vote
0answers
71 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 ...
7
votes
1answer
565 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
1answer
199 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
147 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
491 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....
1
vote
1answer
344 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
0answers
195 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)...
5
votes
2answers
312 views

Skipping blocks when using testing with Mocha on Truffle and testrpc?

I have a contract that requires that things only happen at certain block numbers. I was wondering if there was a way to "skip" a set number of blocks?
0
votes
1answer
88 views

Where do i define the test contract params?

lets say i have this code (taken from here) // Specifically request an abstraction for MetaCoin var MetaCoin = artifacts.require("MetaCoin"); contract('MetaCoin', function(accounts) { it("should put ...
1
vote
1answer
150 views

How can I get the value of an account created in mocha test?

I am new to ethereum and am using truffle and mocha for development. I am writing an app that is sending ethereum to a contract. The ether stored in the contract is then used later. I have a function ...
1
vote
0answers
252 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....
2
votes
2answers
369 views

unit test with truffle, solidity or mocha?

Truffle allows either one or the other. Now I wonder which I shall use to test my code. I'm not a big fan of mocha. When I see code like contract('MetaCoin', function(accounts) { it("should put ...
2
votes
1answer
526 views

Problems with UINT values when testing with mocha/chai

I am testing at the moment some smart contracts with truffle(mocha/chai/chai-as-promised) and have the following problem: I have a getter, and this getter delivers an UINT value, then when I try to ...
3
votes
0answers
317 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
536 views

Modifier causing “invalid opcode” in TestRPC

I have a token and crowdfund that works fine, except in tests. I can use all the methods, but I get invalid opcode on any of them that have a call to another contract that has a modifier on that ...
11
votes
3answers
7k views

“SyntaxError: Unexpected token import” on truffle test

I get an "SyntaxError: Unexpected token import" error when I do 'truffle test'. I am trying to import a function declared in another file into the java-script test file. I have been searching about ...
2
votes
1answer
194 views

How would one use stubs for unit testing solidity code?

Given some contract A, that depends on another contract B, what would be the best way to unit test functions from A without inadvertently testing code from B. Normally, we could use stubs to return ...
7
votes
3answers
2k views

How to set the timeout for truffle test's before block?

I'm running my tests on a private chain and some of them times out: 1) "before all" hook: Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning ...
4
votes
1answer
485 views

Truffle: How to detect test environment while running smart contract test cases?

I'm trying to run some test cases in Travis CI using truffle but I want some of them not to run if the test environment(localhost:8545) is running via "testrpc" because some of my test cases only ...
1
vote
0answers
81 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 ...
6
votes
2answers
2k views

Truffle test with async/await

Has anyone got Truffle tests to work with async/await? My sample code for testing require('babel-polyfill'); var ERCToken = artifacts.require("./ERCToken.sol"); var Proxy = artifacts.require("./...
4
votes
1answer
630 views

Is the address used to deploy contracts in JS tests in truffle always accounts[0]

I've noticed that the deploying address in my truffle .js tests is equal to the address at accounts[0]. Since it's important to me to test the ownership of a contract, I'd like to know if it's ...
5
votes
3answers
1k views

How to properly catch events using MochaJs

Good day, I'm using mochajs to test my Solidity code using truffle and testrpc. In my contract I got the following event and function: contract store{ event MoneyIn (address _from, uint256 ...
5
votes
2answers
239 views

Sending ethers with mocha.js and truffle might result in larger sums than intended

Good day, I have a contract General and a library GenLib. library GenLib{ event MoneyIn (address _from, uint256 _amount); function moneyIn() { MoneyIn(msg.sender, msg.value); <- ...