Questions tagged [truffle-test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
353 views

1) "before all" hook: prepare suite for " "

I am trying to create an Integrated test (to test multiple smartContracts working together). I re-initialize them inside beforeEach() function. So I get the clean test for each test case. I have done ...
0 votes
1 answer
673 views

toNumber is not a function while writing tests

I am trying to write a simple test to validate a condition, however it fails saying 'toNumber is not a function' Here is the test condition const quorum = await wallet.quorum; assert(quorum.toNumber() ...
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=...
0 votes
1 answer
515 views

Nothing happens whe I run truffle test

I am new to solidity. Maybe I am missing something obvious in the setup. But when I run truffle test, I get nothing, the terminal just stays there forever. $ truffle test ... and I don't know why, ...
4 votes
3 answers
4k views

How to properly write Solidity unit tests?

I would like to write maintainable and readable unit tests for my code. Requirements: Test different actors. E.g. a bank contract and three customers interacting with it. Test for errors. E.g. test ...
5 votes
1 answer
691 views

Truffle test fails to call the base function, wants the override

I have an extended ERC20 contract with ERC827 functions, which are overrides of ERC20 with an extra callback parameter. I have these two pairs of base/override functions: Base: function ...
0 votes
2 answers
1k views

Assertion error running truffle test

I can't seem to understand where this error comes from. Maybe someone can help My token solidity file : pragma solidity >=0.4.2 <0.6.0; contract LairToken { //Name string public ...
1 vote
1 answer
574 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 { ...
0 votes
1 answer
1k views

How can I make sense of solidity-coverage reports

I'm trying to check the coverage of an entire ERC20 set of openzeppelin tests. I'm using openzeppelin/test-environment and solidity-coverage v0.7.4 as plugins in truffle. The tests went fine but I get ...
0 votes
2 answers
591 views

Truffle Test Error

I want to create a decentralise application where I sell my tokens.So,In this scenario.I create a function to end my selling tokens.So,I create a function below. The solidity code is here:- function ...
0 votes
1 answer
548 views

Vyper: Truffle test read mapping value inside struct

I have the following struct inside my vyper file: races: public({ start: timestamp, end: timestamp, racersBetHash: bytes32[address], racersBetAmount: wei_value[address] }[int128]) Then I ...
0 votes
1 answer
1k views

Deploying new contract inside truffle test case

I was trying to transact between two contracts inside my truffle test case. But not been able to do it. The second contract instance comes back undefined always. As per the truffle documentation, ...
0 votes
1 answer
446 views

Truffle Test Console Logging

I'm having some trouble with Truffle logging configuration. During tests, each submitted transaction and its hash is logged on the console and this one becomes full of useless messages that disturb ...
0 votes
1 answer
1k views

Unable to filter events with specific values of indexed parameters

I am currently trying to test a smart contract using the truffle suit ( with 'truffle test'). My contract is of a simple ERC20 token which includes the standard Transfer event: event Transfer(address ...
0 votes
2 answers
1k views

Truffle Test AssertionError: error message must contain revert

I can't figure out why this error occurs Here my test js code: var YarockToken = artifacts.require("./YarockToken.sol"); contract('YarockToken', function(accounts) { var tokenInstance; ...
0 votes
1 answer
581 views

Truffle test doesn't recognize estimateGas function

I'm trying to test my contracts using Truffle and Ganache, but I'm facing some problems with some functions. When I call a non view function, I'm getting the error "out of gas". Moreover, if ...
2 votes
1 answer
2k views

How to debug transaction from truffle test on development network

I am trying to debug a failing solidity function, which I am calling from the JS test files with truffle. When I run my test, I am successfully able to get a transaction id. However, my solidity ...
1 vote
1 answer
540 views

Truffle test case to unit test withdrawal pattern

How can I test the withdraw() function in a truffle javascript test case for the below contract? The problem is, If I use the msg.sender from the same contract, the before and after balance will be ...
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() ...
0 votes
2 answers
645 views

No events where emmited. Why?

This is not a duplicate question. The other one doesn't answer the problem in any way. Can anyone explain to me why do I get No Events where emmited when running truffle test? Ganache is listening in ...
1 vote
2 answers
478 views

Having trouble figuring out Truffle testing with Javascript

I've started unit testing my contracts with Truffle (using Javascript). I'm fairly new to Truffle and Mocha both, and while I've tried to follow the tutorials, I'm struggling to follow exactly what's ...
0 votes
1 answer
908 views

mintNewPosition function of LiquidityExamples contract (Uniswap docs - V3) get reverted when trying to add liquidity

I am trying to interact with Uniswap V3 contracts. More specifically, I am trying to add liquidity to DAI - USDC pool. I am doing this locally by forking the Mainnet using ganache. This is my contract ...
0 votes
0 answers
10 views

Why does truffle test break my migrations?

I have created a deployment script for an upgradable token contract which takes a flag from the command line for the deployment type. I type... truffle migrate --reset --type initial truffle migrate --...
1 vote
1 answer
343 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 ...
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, {...
2 votes
2 answers
861 views

Why do my truffle tests get much slower as I run more of them?

So I am currently building up a test suite for a project, and I have quite a few tests at this point. I am running into a problem however that truffle seems to run tests later in its execution much ...
2 votes
2 answers
788 views

Truffle test: how to get the block number of deployed contract?

In my test I would like to get the block or block number of when the contract was deployed. const instance = await MyContract.deployed() const contractDeploymentBlockNumber = await instance.?
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, ...
0 votes
2 answers
491 views

Use smartcontract's ENUM in test scenarios in truffle

I have create a truffle project with this command: truffle unbox react Here is my smartcontract contracts/SimpleStorage.sol : contract SimpleStorage { enum MyEnum { step1, step2, ...
2 votes
2 answers
258 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
1 answer
250 views

How to trace the line where a tx failed in truffle tests?

I know about 0x's sol-compiler and sol-trace. I used them before and they do exactly what I'm looking for, but these modules bring significant overhead when used with truffle. Check out this file to ...
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 ...
6 votes
2 answers
1k views

Is there a way to test an onlyOwner function from a Truffle/Solidity unit test?

I have a contract with a function marked as onlyOwner (from OpenZeppelin, so only the address that deployed the contract can call it). pragma solidity ^0.4.17; import "./Ownable.sol"; contract ...
2 votes
0 answers
1k views

Unexpected behavior with `block.timestamp` in truffle test

I am doing some experiments with block.timestamp(which is now's alias). I wrote some code to see if block.timestamp really represents the timestamp of the last mined block. From the documentation: ...
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 ...
2 votes
4 answers
3k views

How to test contract with multiple accounts / addresses in truffle?

I want to test my truffle contract with multiple msg.sender addresses. Like "the first user sell token, the second user buys this token". For one address I simply write something like contract.buy....
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 ...
0 votes
1 answer
1k views

Truffle.js file is not created with truffle init command

I have run the truffle init command successfully with creating the following directories and files such as contracts, migrations, test, and truffle-config.js but the one file is missing as truffle.js? ...
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 ...
0 votes
1 answer
215 views

Truffle/Ganache Gas Limit Increase [duplicate]

I had posted on the GitHub Discussion as well. I have this massive smart contract and my goal is to study the scalability of the contract. The values work for smaller sizes. However, it fails at ...
1 vote
1 answer
129 views

About try-catch error(Truffle Test)

I am learning solidity by transcribing code from "Practical Smart Contract Development with Solid and Etherium"(OREILLY). I am studying hard but struggling along the way. It is to be tested ...
0 votes
1 answer
69 views

Truffle: { Error: Invalid number of parameters for "undefined". Got 0 expected 1! at module.exports

I am trying to execute the following smart contract using Truffle: pragma solidity 0.5.16; contract Phishable { address public owner; constructor (address _owner) public{ owner = ...
5 votes
3 answers
7k views

Truffle test, how to get address(0)?

This is going to be short question and may be silly, but I'm literally stuck with a problem, where I need to pass address(0) to function in Truffle Test in JS and don't really know how to do it. In ...
3 votes
2 answers
2k views

How do I actually test a mint function using Truffle and the payable modifier in Solidity

I'm creating a smart contract and trying to test it using Truffle. I'm a little stuck on how to call the mint function ( how to actually execute the transaction from the test function ). I know Im ...
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 ...
0 votes
2 answers
175 views

How to use truffle-assertions to check if a constructor will revert?

Say I have a contract: contract Reverts{ constructor(param1){ require(param1); } } If param1 is false, the constructor should fail and revert state. truffle-assertions allows me to ...
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 ...
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 ...
0 votes
1 answer
133 views

"Error: Returned error: VM Exception while processing transaction" when I run truffle test

I'm running my unit test with truffle in ganache environment. Here's my Lottery SC: pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@...
0 votes
1 answer
129 views

"insuffiecient allowance" running my unit test

I'm developing in remix a lottery SC. I have a problem when I run buyTicket() function. On remix I fix it giving approve to SC address from erc20 function, but I don't know how to do it when I run my ...

1
2 3 4 5 6