Questions tagged [testing]

questions regarding the testing during development of contracts and DApps

Filter by
Sorted by
Tagged with
53
votes
13answers
23k views

How do I set up a private ethereum network?

I'd like to set up a local (private) blockchain that isn't connected to the wider internet so that I can deploy some test contracts. How do I go about doing that?
41
votes
8answers
21k views

How to quickly test a Solidity function?

There are snippets and functions of Solidity code provided on this Ethereum Stack Exchange and other sites. What are ways to quickly test them, possibly debug a little, and play around?
34
votes
5answers
19k views

How can I debug a smart contract?

When developing my smart contract, how can I debug it? Are there any debugging, testing tools or simulators that I can use to examine my code?
28
votes
10answers
11k views

How can you handle an expected throw in a contract test using truffle and ethereum-testRPC?

Is it possible to write a test using truffle that attempts to confirm that a throw occurs in a contract? For example, if I had a contract with function... contract TestContract { function testThrow(...
25
votes
4answers
8k views

What public test-networks and faucets exist?

What public test-networks exist and what are their conditions? What are the connection data? How often (if so) are they reset? Does a public faucet exist for this test network? Does a block explorer ...
25
votes
1answer
9k views

How to unit test smart contracts

How are Ethereum contracts tested? I've seen Truffle which referrers to itself as an Ethereum development framework. Are there any other frameworks and what is their level of maturity? Is there a de ...
21
votes
1answer
5k views

What is truffle?

What is the truffle framework? Who can use it, who should use it? And what are the benefits?
18
votes
6answers
12k views

Best way to test a smart contract

I just want to deploy and call a simple sample smart contract only for testing purpose. Do I need to download the entire ethereum blockchain? Its too huge and takes too long to download. Can someone ...
17
votes
3answers
5k views

How to check events in Truffle Tests?

What's the best way to check that events were fired in a Truffle test?
17
votes
1answer
2k views

What is embark?

What is the embark framework? Who can use it, who should use it? And what are the benefits?
15
votes
2answers
2k views

What is the reason for writing truffle tests in .sol and .js files?

What is the reason that tests can be written in both? Is there any distinct advantage to using one over the other? Or is one in general easy to work with?
13
votes
4answers
8k 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 ...
13
votes
2answers
16k views

How do Enums work?

I am just starting out with Solidity and JavaScript and am trying to understand Enums. I have a simple contract pragma solidity ^0.4.4; contract SimpleEnum { enum SomeData {Channel} SomeData ...
12
votes
1answer
1k views

How can I reliably induce a blockchain fork for testing purposes?

I would like to reliably induce a fork on a private testnet so that I can test the behavior of off-blockchain code that interacts with contracts. (see related questions as to why I would want to do ...
12
votes
4answers
3k 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 ...
11
votes
5answers
3k views

Geth Console - Sleep after mining a block?

I am running a local testnet with a low mining difficulty to test my contracts, and I am conscious that when I start another mining geth instance the total computation will hog my CPU. My question ...
11
votes
3answers
3k views

What is the difference between testrpc and EtherSim?

These are both "faux-blockchains" for development purposes. Both are recommended from various people as a good tool when developing in truffle. And I even think both are being developed by the same ...
10
votes
3answers
2k views

What's the fastest way to mine a transaction so I can test contracts quickly?

I am developing a solidity automated test framework in nodejs that uses events/logging extensively. The use of events eliminates (I believe) all the RPC simulators out there. It's also frustrating ...
10
votes
1answer
2k views

how can I run a truffle test in a debugger? [duplicate]

as a developer I want to run my javascript test in a debugger so as to be able to step through tests and inspect the values of variables. The goal is to run it in a Mocha debug mode
9
votes
1answer
2k views

How can I take a snapshot of Ganache or Truffle Develop state and reload later?

I would like to be able to save the state of my local Ganache or Truffle Develop chains into some sort of file. At a later time, I would like to be able to restart Ganache or Truffle Develop and apply ...
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 ...
9
votes
2answers
3k views

How to create private network with preallocated amount of ETH?

I am trying to create a private network for testing purposes. What I need is: Fast generating of DAG file. Fast mining of the first block. Address with some preallocated amount of Eth. I found that ...
9
votes
1answer
596 views

Filtering on events of the entire blockchain not possible in testrpc via truffle

A contract I wrote has an event in its constructor. Since I want to find it back in the logs it doesn't seem possible to start listening to the latest block. Because the event is already 'fired' ...
8
votes
1answer
5k views

How to unlock accounts programmatically after the node has started?

Is there any way of just unlocking accounts without opening the console with geth? I'm writing some scripts to automate cluster generation and I wish I could just call geth to unlocking some accounts ...
8
votes
2answers
4k views

Getting more Ether on a private test net

I setup a local testnet using geth following these instructions. I was able to mine my initial Ether and all was working. After deploying some contracts I quickly spent all the Ether I had. Now it ...
8
votes
2answers
709 views

Why are there so many testing environments around Ethereum?

A newbie here, just trying to connect the dots. Why are there so many test environments in the ethereum ecosystem -- rinkebys, testrpc, ropsten and what else? Why not have just one testing ...
8
votes
2answers
483 views

Conformance test suite for ERC-721 smart contracts

Entities like Open Zeppelin offer "well tested and audited" (I'm paraphrasing) open source Solidity code for common patterns such as ownership, ERC20 tokens, etc. Are there any such entities (or just ...
8
votes
1answer
1k views

Truffle — testing enum values

I am using truffle to develop a simple smart contract. I have the following contract: contract Puppy { enum State { good, bad } State public status; State public constant INITIAL_STATUS = ...
8
votes
1answer
640 views

What is the most correct way to test modifiers?

As per the title, which testing method is most correct for modifiers? Something like testing via inheritance and creating a function specifically designed to test modifiers or testing via a framework ...
7
votes
4answers
5k views

How to access the deployed contract's address from Truffle JS tests?

I've written a test that involves returning the token balance that the contract itself holds. In the contract source file I would access the balance using the function getBalanceOf(this). However, ...
7
votes
1answer
1k views

How to unit test contract private and internal functions?

How can we unit test contract private functions using the Truffle framework? Since Solidity doesn't have package access or reflection language features, standard private testing approaches don't work....
7
votes
5answers
6k views

Trying to connect Mist/Ethereum wallet with testrpc

I need someone who can explain to me, step by step, in simple terms how can I connect the ethereum wallet with the local blockchain. I found the following link: Connect Mist to ethereum-js testrpc ...
7
votes
3answers
2k views

Compile error with trivial assertion in Truffle test

Before I did anything serious I just wanted to check the toolchain is working. I wrote a test like this: pragma solidity ^0.4.2; import "truffle/Assert.sol"; import "truffle/DeployedAddresses.sol"; ...
6
votes
3answers
4k views

Truffle solidity tests: out of gas & exceeds block gas limit

I am trying to run some basic test w/ my contract, written with Truffle's Solidity tests (tests written in Solidity). When runninng truffle test, I get Error: VM Exception while processing ...
6
votes
1answer
1k views

invalid JUMP after upgrading truffle & testrpc

I have a contract with a method add() where I read the value msg.value and change the contract informations. before upgrading, I was calling this method in my test with return contract.add({from: ...
6
votes
2answers
2k views

How should we benchmark transaction per sec?

I'd like to compare the transaction speed of private Ethereum(ex. PoA), Eris and HydraChain. How should we benchmark them?
6
votes
2answers
1k views

How can I change the gas price or the gas limit when testing with pyethereum?

I've got some code that's ultimately destined to run on a private network. I'm testing it with the lovely pyethereum, doing things like: from ethereum import tester as t class testMyContract(...
6
votes
1answer
2k views

How to check if a bytes32 represents an empty string?

Why does the require not throw here when I am passing an empty string for the _name param? function MyContract(bytes32 _name) public { require(_name.length > 0); name = _name; }...
6
votes
2answers
448 views

How can developers test time-dependent contracts?

I'm working on a revenue distribution contract that lumps eth by week. In order to test it, I need some way to set the now variable. Is there any way to do that? Using solidity/geth.
6
votes
2answers
2k views

How to properly simulate mining time with Ganache CLI

I am using the Ganache CLI for testing my smart contracts and frontends. I need a way to incorporate a delay into ganache-cli when performing write transactions in order for it to more closely ...
6
votes
1answer
545 views

Reset balance in truffle test accounts after each test

I am writing unit tests for a function where I am sending tokens from one address to other in exchange of ether. I ran these tests a few times and now I am left with 0 ether in one account. I tried ...
6
votes
3answers
382 views

Why does truffle always fail with “Error: Don't set config.from directly. Instead, set config.networks and then config.networks[<network name>].from”

I have a problem that suddenly appeared, and now I get it every time that I try to run truffle test or truffle migrate, regardless of which project it is. I've even tried fetching the Petshop from the ...
6
votes
1answer
2k views

function.call() behaves differently to function() in truffle test

I'm using Truffle 4.0.1 and Node 9.2.1 In my solidity smart contract I have a function function finalize() public onlyOwner { require(!isFinalized); finalization(); // does some stuff ...
6
votes
2answers
868 views

How to Unit test modifiers in Solidity

I'm using https://github.com/dapphub/dapp framework for writing Solidity contracts and their ds-test unit test framework. Has anyone tried to cover modifiers in unit tests? Example: modifier ...
6
votes
1answer
442 views

Is truffle based on node and is it possible to run some kind of node debugger in order to pause the Javascript tests and examine variables?

I am currently developing a Dapp and using truffle test to verify the contract. However, I find that I am also debugging the Javascript that runs the test with a lot of console.log() statements. This ...
6
votes
1answer
627 views

How to sequence steps in a truffle test?

I'm trying to test contract which rely on a particular state of other deployed contract. For example let say i have a contract wanting to test the "transfer" function of an ERC20 contract. I should ...
5
votes
2answers
2k views

Remove trailing zero from web3.toAscii() conversion

I have a contract that returns a bytes32 type variable and I'm currently testing it with truffle and javascript. The original data ['Roberto', 'Juan', 'Andrea'] This array is what i get as a ...
5
votes
2answers
2k views

How to get the transaction cost in a Truffle unit test?

How can I get the actual gas consumed by a sendTransaction inside a truffle test? In the following test, buyer sends an amount of 50 ETH to a contract: const EmptyContract = artifacts.require("...
5
votes
3answers
1k views

How can I mock the time for solidity tests?

My contract has an expiration date that I'd like to unit test but I don't know how to go about doing that. If I could mock the time of the contract that would be dope. Google search provided no ...
5
votes
2answers
1k views

Sign data with private key inside a truffle test file

I've got a contract method that checks the signer of a message using the solidity ecrecover function. In my truffle test file I now want to check if this is done correctly. Therefore I need to sign a ...

1
2 3 4 5
7