Questions tagged [truffle-test]

The tag has no usage guidance.

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

Truffle test failing

i am learning solidity contracts and ethereum dapps. I have created a smart contract for creating a ERC20 token on using truffle dev environment. pragma solidity ^0.5.0; contract LearnTokens { ...
Saeedi's user avatar
  • 177
1 vote
1 answer
141 views

Truffle test failing due to different data type than expected

I am using truffle and ganache to make a token demo for myself. I'm following this guide then making my own changes according to my project. When I try running tests to verify that my contract is ...
Fortune's user avatar
  • 502
1 vote
1 answer
2k views

Error: Transaction:exited with an error (status 0) after consuming all gas

New to Ethereum and learning unit testing with Truffle. Here in smart contract function; function createAgreement( bytes32 _id, address _owner, string _fileHash, ...
Hina's user avatar
  • 265
1 vote
1 answer
506 views

Help with inheritance and Truffle tests

I have two contracts that both inherit from OpenZeppelin's Whitelist. After deploying both contracts, I use an instance of the first contract to add a "trusted" address to the whitelist. Since both ...
Mike's user avatar
  • 113
1 vote
1 answer
358 views

Truffle test seems to succeed, but then 'transaction wasn't processed in 240 seconds! '

I have 5 smart contract functions and 26 unit tests for them. If I run the tests together, they run green, however, in the end, I get a timeout error: The error message wasn't quite informative for ...
Antona's user avatar
  • 55
1 vote
1 answer
138 views

Why am I getting incorrect WBTC when swapping it with DAI using Uniswap?

Hi I created a smart contract but when I am swaping 1 Million DAI with WBTC tokens I am getting only ~3379786784 WEI (~34 WBTC) but when I am checking its value on UNISWAP website it is showing 43 ...
Vinay Kharayat's user avatar
1 vote
1 answer
2k views

why vs code not recognizing the node version

when I install a "truffle for vs code" extension in vs code and try to create a new solidity project then nodejs version is not recognized but I have installed nodejs's correct version.
Hitesh's user avatar
  • 21
1 vote
1 answer
71 views

Why Contract State not Persisted in Every Test Sequentially?

I have a smart contract in truffle project and want to test it. I have multiple tests sequentially which means contract's state after first test will be needed for the second test. The problem is, it ...
fahadh4ilyas's user avatar
1 vote
1 answer
787 views

Signing messages in Truffle tests

I use Truffle to develop locally and run tests with truffle test (letting it create a temporary local blockchain). In one of my tests I need to sign a message and for that I need the test wallet's ...
G.G.'s user avatar
  • 133
1 vote
2 answers
3k views

truffle test - Error: Contract has not been deployed to detected network (network/artifact mismatch)

As I excessively read all posts given and none solved my problem I'm opening this thread. Please don't consider every test useful as I'm in the development of useful tests. As mentioned it is about ...
Ndrslmpk's user avatar
  • 112
1 vote
1 answer
415 views

smart contract how link libraries to child contract under factory pattern

I am trying to create a factory and I can not find a way to link libraries to the child contract. I am trying to create a contract factory that create child contracts. the problem is that the child ...
GrailsBeginner98's user avatar
1 vote
1 answer
138 views

Testing address(this) generates exception, how to obtain the correct value for address(this)

I have modified the following code from a michalzalecki website https://michalzalecki.com/ethereum-test-driven-introduction-to-solidity/ to test address(this): pragma solidity 0.5.16; import "...
zak100's user avatar
  • 1,406
1 vote
1 answer
32 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 ...
Vasvi Sood's user avatar
1 vote
1 answer
376 views

Truffle test: "Cannot read property 'gasUsed' of null" error. Truffle migrate works fine

Whenever I try and do truffle test I get the error Cannot read property 'gasUsed' of null But truffle migrate --reset works fine More confusingly, to rule out something in one of my tests that is ...
Andrew Stanger's user avatar
1 vote
1 answer
44 views

Different behavior of the same contract between JavaScript and Solidity tests with Truffle

I have a simple contract that functions as a ratekeeper - it is constructed with a capacity and time_frame (in blocks) parameters and makes sure we never add more than $capacity payments in any given ...
Vaultsmith's user avatar
1 vote
1 answer
66 views

Does truffle test mimic the exact network state of an actual migration?

I've defined a truffle migration step as follows: Deploy my 'main' smart contract, nothing out of the ordinary: var UniversityVoting = artifacts.require('./UniversityVoting.sol'); module....
E. Rowlands's user avatar
1 vote
2 answers
1k views

invalid number value (arg="_goal", coderType="uint256", value=2000000000000000000)

i am following a tutorial from here. And upon running truffle test. It produces following error. 2_HashnodeCrowdsale.js ====================== Deploying 'HashnodeCrowdsale' ------...
Saeedi's user avatar
  • 177
1 vote
1 answer
631 views

Debugging a VM error in solidity

I'm getting the following error while running a test in truffle: Error: Returned error: VM Exception while processing transaction: revert Now, the code is simply to big and complicated to run ...
Lucas Rodriguez Benitez's user avatar
1 vote
1 answer
160 views

Issue with Contract function return value data type

I am using a simple contract Contract code contract Bank { address public owner; mapping(address => uint) private customerBalance; event fallbackCalled(address, uint256); event ...
CaptPython's user avatar
1 vote
1 answer
726 views

"truffle test" says "assert.rejects" is not a function even it is Node 10

As per the official documentation, assert.rejects was added since Node v10.0.0. Also, the node console confirms that: even though, truffle test throws this error: TypeError: assert.rejects is ...
Abdennour TOUMI's user avatar
1 vote
1 answer
132 views

Truffle Test: How to Run n times the same function

Since I have to study the variation of the gasUsed of a function, using Truffle Test is it possible to do a test that runs n times the same function without going out of gas or exceding the block gas ...
Stefano Angieri's user avatar
1 vote
1 answer
383 views

How do OpenZeppelin ERC721 tests pass?

I don't understand how the following test can pass. I tried it in my application and it fails. The entry point is the description 'when called by the owner'. In this function two test cases are ...
MarcS82's user avatar
  • 323
1 vote
1 answer
734 views

Truffle TypeError: Member "error" not found or not visible after argument-dependent lookup in type(library Assert)

Trying to test my Solidity contract for errors using Truffle test. TestSafeMath.sol function test_add_10_and_max_should_return_err() { uint256 max = 2**256 - 1; Assert.error(SafeMathExt....
Senju's user avatar
  • 701
1 vote
1 answer
284 views

Contract not found during truffle test

I created and deployed two contracts successfully (with confirmation) using truffle migrate like so: module.exports = function(deployer) { deployer.deploy(ReentrancyPot).then(async () => { ...
Peteris's user avatar
  • 1,005
1 vote
0 answers
17 views

Can't pass Truffle test with an uint256 array as event property

I have this simple test in truffle: it("should emit the correct Transfer event", async function() { await this.contractNFT.multiSafeMint(accounts[0], "CID/metadata.json", 3, {...
viac92's user avatar
  • 33
1 vote
0 answers
25 views

Deactivate clean-room environment in truffle

Everything is in the question, does anyone have a way to prevent the redeployment of the contract every time you run a test and keep using the same "contract" feature ? Edit : I've found it, ...
Raphael's user avatar
  • 41
1 vote
1 answer
43 views

What are the Solidity contracts that the Infura NFT SDK uses? How can one test these contracts?

I am trying to make use of the Infura NFT SDK that would work with another contract that I developed. I wanted to make some unit tests locally, however, searching on their documentation and on the ...
PensoGlide's user avatar
1 vote
1 answer
288 views

Error: *** Deployment Failed *** "Migrations" -- Returned error: no pending block

When i run "truffle test" in VS on my basic helloworld smart contract, i get the error message: "Error: *** Deployment Failed *** "Migrations" -- Returned error: no pending ...
Golanger's user avatar
1 vote
0 answers
59 views

Unit testing a double mapping

How to call a double mapping in unit tests? Here is an extract of our contrat: contract StackingPool { struct Staker { uint128 amount; // Amount token stake uint256 date; // Date ...
Jean's user avatar
  • 21
1 vote
1 answer
19 views

Passing an error testing suite in contract

hello how do i make a proper testing suite for error? the contract has this modifier for freeMint() fn modifier protectTier(uint256 _level) { require( _level != privateTier, &...
Dell Watson's user avatar
1 vote
0 answers
11 views

Truffle test, is it possible and useful to test types?

All is in the question : is it possible and useful and to test types ? Or don't need to test it because Solidity is a statically typed programming language (it's already done). I did many researches ...
Jean's user avatar
  • 21
1 vote
1 answer
122 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
1 vote
1 answer
341 views

truffle installed but not working

I'm using node version 12.20.2 and npm version 6.14.11 and installed truffle with cmd as administrator, the truffle framework version 5.5.12 has been installed but when I run any command in the vs ...
Prabhat Dongare's user avatar
1 vote
0 answers
99 views

Truffle test throws an error in "before each" hook

Developing a flash loan which i use truffle to test my code, david@LAPTOP-3KIH2P0K:/mnt/c/pr0/flash/FlashloanLeveragedYieldFarm$ truffle test Using network 'development'. Compiling your contracts... =...
Soyaya's user avatar
  • 31
1 vote
0 answers
105 views

Truffle Testing, Javascript & Solidity Testing Use Case

I’ve been studying the truffle documentation and saw how little differences were detected between the way solidity testing and javascript testing works. This confuses me as a developer, the ...
Munkh-Od Ganzorigt's user avatar
1 vote
0 answers
493 views

Sign Transaction with Zero Address

I am writing and testing a smart contract. Using web3, I could not send a transaction from a Zero Address (0x0). I was wondering if it is ever possible to sign and send a transaction using the zero ...
Rachit Anand's user avatar
1 vote
0 answers
489 views

How to test with existing ERC20 tokens on local tests

I have a Solidity smart contract for NFTs that I need to test using Truffle Suite. While deploying the contract on Rinkeby, I provide it with an existing ERC20 token contract address that I use for ...
Rachit Anand's user avatar
1 vote
1 answer
711 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() ...
Toan Quoc Ho's user avatar
1 vote
0 answers
1k views

Run truffle test, returns TypeError: Cannot read property '0' of null

after deleting several unnescesary smart contracts I was able to run npx Truffle Test and this is what my console returns... sing gas limit: 6500 K Using gas price: 10 Gwei Optimizer enabled: true ...
Kaleb Amarante's user avatar
1 vote
1 answer
179 views

Explore transaction from truffle test file

I have create this test: const { expectEvent } = require('@openzeppelin/test-helpers'); const MyContract = artifacts.require('MyContract'); contract('MyContract', function (accounts) { const [...
Bob5421's user avatar
  • 1,457
1 vote
0 answers
365 views

Owner of contract is set to contract address?

I just testing a contract with truffle and Im wondering why the owner of the contract is set to the contract address itself. Migrations: const contractA= artifacts.require("ContractA"); ...
MaTok's user avatar
  • 321
1 vote
0 answers
39 views

Is Truffle test useful?

Hi there I came across "Truffle test". As a developer I feel like it's better to test code on remix for unit testing rather than wasting time on writing truffle test in javascript. What do ...
Haseeb Saeed's user avatar
1 vote
0 answers
108 views

Using privateFor in truffle test

Using truffle , I am able to deploy private smart contracts using privateFor clause. However, I am not able to use in truffle test. I get the following error. Is there a way we can use privateFor ? ...
sun's user avatar
  • 545
1 vote
1 answer
573 views

Solidity test fails when testing onlyOwner functions

I have a contract where some functions can be called only by the owner of the contract and I want to test it with a solidity test in truffle. The contract looks like this: contract owned { ...
David's user avatar
  • 405
1 vote
1 answer
490 views

Testing solidity transfer method not transferring tokens

I have this solidity contract: contract Token { mapping(address => uint256) public balanceOf; event Transfer( address indexed _from, address indexed _to, uint256 _value ); ...
user avatar
1 vote
1 answer
554 views

How to use solidity library with truffle

I'm using truffle V5.1.13 and when I run truffle test the res variable contains a transaction receipt rather than the expected 2. I notice if I remove everything that has to do with the library things ...
Conviley's user avatar
  • 390
1 vote
0 answers
680 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 ...
Andrew Stanger's user avatar
1 vote
0 answers
562 views

Truffle test including mainnet contract - Error: Cannot create instance of Whitelist; no code at address

Problem with the error Error: Cannot create instance of Whitelist; no code at address 0x6198149b79AFE8114dc07b46A01d94a6af304ED9 How do I have to setup truffle so that I can run a test which includes ...
Senju's user avatar
  • 701
1 vote
0 answers
287 views

What is the easiest way to write truffle tests in typescript?

I read about Typechain, but the configuration is rather verbose and generally feels like a very custom solution: Everytime you change contracts you need to run yarn generate.
Paul Razvan Berg's user avatar
1 vote
1 answer
1k views

Error when testing the contract

ApprovalContract.sol pragma solidity ^0.5.1; contract ApprovalContract{ address public sender; address payable public reciever; address public constant approver=...
neha agarwal's user avatar