Questions tagged [truffle-test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
9
votes
5answers
2k views

Prevent 'truffle test' from invoking 'truffle deploy (migrate)'

It seems that truffle test automatically invokes truffle deploy (aka truffle migrate). As far as I'm concerned, these two functionalities are completely unrelated. So I cannot quite figure out why ...
6
votes
1answer
321 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 ...
5
votes
2answers
641 views

What Continuous Integration services support running Truffle Solidity tests?

What are the best practices for running a CI server that runs Truffle Solidity tests?
5
votes
1answer
640 views

AssertionError: error message must contain revert

I have tried a lot of research. I still somehow can't find and understand why this error occurs when im in private network. But if in 127.0.0.1:7545 which ganache, everything seems to be working, all ...
5
votes
1answer
666 views

Contract factory function running out of gas during Truffle test

Using openzeppelin library and truffle I am trying to make a Contract Factory that creates ERC20 tokens. I prefer to test it with Truffle using solidity and not javascript. Here is the code from the ...
5
votes
3answers
418 views

Mocking blockchain for unit test quorum

Is there a way so that I can mock blockchain for unit test in quorum. I do not want to set up a test blockchain for unit testing. Is there any possibility.
4
votes
3answers
91 views

I got this error during migration in truffle. : ParserError: Expected '(' but got identifier

This is my smartcontract code pragma solidity ^0.5.0; contract DappToken{ uint256 public totalSupply; constructor DappToken() public{ totalSupply = 10000; } } This is code for ...
4
votes
2answers
203 views

How to enhance list of accounts for the Truffle tests to run against Ropsten testnet

I am working on the my contracts testing scripts. But I want to run tests not on the local TestRPC or Ganache but in the Ropsten testnet. How can I predefine a list of accounts (private keys and ...
4
votes
1answer
828 views

Returns TX Object instead result in Truffle test

I'm getting AssertionError: expected { Object (tx, receipt, ...) } to be true Here is my testing code let apprOrOwnr = await this.erc721.isApprovedOrOwner(owner, tokenId); expect(apprOrOwnr).to....
4
votes
0answers
230 views

`eth_getTransactionReceipt` returns the transaction hash not the receipt

I use sol-coverage in a truffle project. Ganache is my development blockchain. I have a lot of tests which end up doing more than a few thousand JSON RPC calls. Due to unbeknownst reasons, the ...
4
votes
1answer
432 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 ...
3
votes
2answers
316 views

How to test events that were sent by inner transaction / delegate call?

Usually, using truffle I can check for events like this: let { logs } = await myContract.doSomethingImportant( xxx ); // 1500 tokens are expected to get expectEvent.inLogs(logs, '...
3
votes
1answer
881 views

“Callback was already called” during truffle test using a solidity testfile

I'm creating a contract/token which extends the openzeppelin ERC20.sol and Ownable.sol. My contract has no own logic yet and looks like this: pragma solidity ^0.5.2; import "../node_modules/...
3
votes
1answer
303 views

how to test overloaded function in truffle?

I recently upgraded truffle to the newest version. Now it does not automatically detect overloaded functions anymore. Before, I could just do the following: await contract.function({ from: accounts[...
3
votes
1answer
481 views

Truffle Test: How to test SafeMath Library for overflow

How can I test if a function is resistant against overflow with truffle test? contract SafeMath{ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b;...
3
votes
2answers
305 views

Truffle Test Issue With `address payable` and Compiler Version

I am trying to run truffle test on an old contract which was written using pragma solidity 0.4.24;. While I am able to deploy the contracts using truffle migrate, I get the following error when ...
3
votes
1answer
161 views

How to test contract interaction with mainnet contract via Truffle

I'm writing a contract via Truffle and my understanding is that running truffle test will run my tests in a clean-room environment. E.g. a fresh deployment blockchain run on my local machine How can ...
3
votes
1answer
451 views

Evaluate the performance of a smart contract [closed]

What is the best way and tools to evaluate the performance of a smart contract. More specifically, I want to test my contract for large scale deployment by making a script that emulate real world ...
3
votes
2answers
546 views

Error when running Truffle Test in Terminal

I am trying to use truffle to test my smart contracts and have written some test files. I am getting an error on the terminal trying to run the test and am unsure what the reason is. I access my ...
3
votes
1answer
115 views

3_deploy_contracts.js question

What is a good way to solve my deployment issue: (furtherance of issue: truffle testing problem, migration successful, testing runs out of gas with addition of testing file) When i add the ...
3
votes
1answer
558 views

Truffle web3.eth.sign produces wrong signature

Somehow truffle produces an invalid signature. To clarify this I imported the private key of the first Ganache account to metamask and compared the results. The following code used in a chrome ...
3
votes
0answers
57 views

Many Contract Testing strategies

I'm trying to wrap my brain around how to effectively test multi "projects" in Truffle, assume a simple ganache setup, also assume that these contracts seem to work, in remix, and in unit tests, but, ...
2
votes
3answers
2k views

Testing sha256(abi.encodePacked(_argument))

When trying to test a smart contract that uses sha256(abi.encodePacked(_myargument)) I don't get the same hash on truffle ! I tried both web3.utils.keccak256('_myargument') web3.utils.sha3('...
2
votes
1answer
2k views

Truffle test: How to test Ether transfer? Balance of specific account?

How is it possible to test if my contract actually transfers money to a specific account? function _transfer(address receiver_, uint256 payout) internal{ receiver_.transfer(payout); } Testing in ...
2
votes
2answers
895 views

Simple Truffle tests timeout “before all” hook: prepare suite

I'm trying to write my first tests for truffle, but I run in a timeout each time I want to execute the tests. Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is ...
2
votes
2answers
766 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 ...
2
votes
2answers
303 views

recipient address is not a contract address

Well, I have a smart contract called Register. The test script is quite straightforward: const Register = artifacts.require("Register") contract('Register', (accounts) => { let register; ...
2
votes
2answers
305 views

How do I specify the network ID in the config file when migrating/testing contracts on my local ganache?

So my issue is when I run the compile and then migrate commands everything goes smooth, then I try to test by running the truffle test command and it gives me an error saying 'Error: The network id ...
2
votes
1answer
57 views

Check emitted event with BN

I'm currently testing events that include numeric values: const level = new BN(1); truffleAssert.eventEmitted(tx, 'EventName', {level}); As you can see, the level variable is a BN, and holds the ...
2
votes
1answer
248 views

Contract Not Deploying In Truffle Tests

I am trying to do a simple test on Truffle, but it seems that the deployed() promise is never being executed. var MyContract = artifacts.require('MyContract') contract('MyContract', function(...
2
votes
1answer
192 views

Truffle Debugger: Inspect Transaction object?

Is it possible to inspect the transaction object 'msg' in the truffle debugger? When I step through the below and type :msg.value I get ReferenceError: msg is not defined Code: string public ...
2
votes
2answers
254 views

Error: Invalid number of arguments to Solidity function - I'm pretty sure the number of arguments is correct?

General problem: Using double linked list. Because of block gas limits, I call a function off-chain to find the exact insertion point. https://github.com/genesisdotre/ethereum-auction Branch: no-...
2
votes
1answer
425 views

How to get require message in a test case? Truffle test

For instance I'm running testcase for a smart contract and it's test function has required validation. function test(uint _id) public pure returns(bool){ require(_id == 0 ,"not valid!"); ...
2
votes
1answer
1k views

Calling event.watch() and event.get() prevents truffle JS tests to terminate

My contract is contract SimpleContract { uint storedData; event SimpleEvent(uint p); // EVENT function set(uint x) public { storedData = x; SimpleEvent(x); // TRIGGER ...
2
votes
0answers
31 views

How to simulate time increase in Remix IDE?

In my JavaScript tests: module.exports = { increaseTime: (duration) => { const id = Date.now(); return new Promise((resolve, reject) => { web3.currentProvider.send({ ...
2
votes
1answer
100 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 ...
2
votes
1answer
134 views

Truffle .call() returns values with array index instead of keys

I am currently writing tests for solidity contract using truffle. When I invoke a function from the contract with .call(), the object that is being returned to me has the values included twice, once ...
2
votes
1answer
851 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 ...
2
votes
0answers
77 views

Truffle test to verify events can be queried by the address of the signing user?

I'm trying to write a test which verifies I can query a given type of events by the user/address which sign them. I would like to apply TDD (relevant to say I haven't made the implementation for this ...
2
votes
1answer
89 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
126 views

IntelliJ + truffle tests

I would like to run truffle tests from IntelliJ. I found a tutorial here: https://charterhouse.github.io/2017/05/12/running-truffle-unit-tests-in-intellij-idea.html Unfortunately, it does not seem ...
2
votes
0answers
202 views

evm_revert to snapshot#1 in ganache-cli automatically

I am using evm_increaseTime in my tests to move block time but in ganache-cli it shows that it is reverting to snapshot #1. I have not used evm_revert or evm_snapshot. Is it normal? what is the ...
2
votes
2answers
1k views

Truffle cannot find Ethereum client when running tests

By default this is the content of the file truffle.js: module.exports = { // See <http://truffleframework.com/docs/advanced/configuration> // to customize your Truffle configuration! }; ...
2
votes
1answer
116 views

Interacting with a Custom Token Contract

I seem to be having problems interacting with a custom token contract. I am using truffle and ganache for my testing. I am trying to interact with the custom token contract so MyContract can ...
2
votes
0answers
539 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
424 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: ...
2
votes
1answer
538 views

Truffle send to fallback function from different account

I'm testing a simple fallback function with Truffle, the fallback function is: function () public payable { internalTransfer(this, msg.sender, 100000000); FundSuccess(msg.sender, msg.value); }...
1
vote
2answers
762 views

Contract is not defined in truffle tests

I am trying to test one of my contracts, but truffle complains that it is not defined. I can see that the test compiles to the build folder, and I have imported it the same way as other contracts, I ...
1
vote
2answers
536 views

How to get a transaction fee in a Truffle test

I would like to test a Solidity function that looks like this and check if a correct amount of ether was sent to a sender: function withdraw() public { uint contributed = amounts[msg.sender]; ...
1
vote
2answers
149 views

Returning dynamic arrays: out of gas

I'm trying to return a dynamic array of structures from a Solidity function to a client. Since I need to build the result, I'm declaring a storage variable and add elements to it: function ...

1
2 3 4 5