Skip to main content
10 votes

What Continuous Integration services support running Truffle Solidity tests?

Honestly, any CI service will do the only requirements are a test blockchain (easy to install ganache-cli ) or use the docker image and other packages of interest including solidity-coverage, eth-gas-...
GrandFleet's user avatar
10 votes
Accepted

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

To assert the balance of an account, try this: let expectedBalance = web3.toBigNumber(web3.toWei(3, 'ether')); let actualBalance = await web3.eth.getBalance(accounts[1]); assert.deepEqual(...
Henk's user avatar
  • 4,271
10 votes
Accepted

Truffle test, how to get address(0)?

You can simply use 0, or 0x0000000000000000000000000000000000000000. address(0) in Solidity is equivalent to 0x0000000000000000000000000000000000000000.
Shane Fontaine's user avatar
9 votes

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

I ran into this issue as well, and it is indeed the intended behavior of truffle test: cleanroom behavior. Each run of truffle test redeploys the contracts. If it didn't, then saved state from a prior ...
Yaoshiang's user avatar
  • 301
9 votes
Accepted

Testing sha256(abi.encodePacked(_argument))

First you need to know that sha256 and keccak256 functions are not the same. Check the docs to see available functions. sha256 (with pyhton): >>> sha256("Hello World!").hexdigest() '...
alberto's user avatar
  • 3,343
6 votes
Accepted

Truffle - test - how to get more than 10 accounts?

Truffle tests run ganache-cli behind the scene in default mode (10 accounts). But if you run yourself ganache-cli with x accounts generated, you will have access to all of these accounts from your ...
Greg Jeanmart's user avatar
6 votes

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

It is really embarrassing, how narrow minded the truffle authors think. My tests run their own deployment that is used in the tests. In my case, the truffle migration includes the steps that data is ...
Marc Wäckerlin's user avatar
6 votes

Truffle test, how to get address(0)?

You must put single quotes around it. '0x0000000000000000000000000000000000000000' worked for me Been hunting down that bug for some time ...
Johannes S.'s user avatar
6 votes
Accepted

Simple Truffle tests timeout "before all" hook: prepare suite

There is an issue in a way you use HDWalletProvider when configuring development network in truffle-config.js. You should add it like: provider: () => new HDWalletProvider('your mnemonic', 'http:...
Igor Sobolev's user avatar
6 votes
Accepted

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

Prior to Solidity v0.4.21: contract ContractName { function ContractName(...) public { ... } ... } Solidity v0.4.21 onward: contract ContractName { constructor(...) public { ...
goodvibration's user avatar
5 votes

Error: Please pass numbers as strings or BigNumber objects to avoid precision errors

The signature of the toWei method is (can be found in the docs. web3.utils.toWei(number [, unit]) number - String|BN: The value. unit - String (optional, defaults to "ether"): The ether to convert ...
Rosco Kalis's user avatar
  • 2,137
5 votes

How to access in JavaScript multiple return values returned from a solidity function

I'm not sure the version of web3 used in the previous answer by ivicaa. On web3 "v1.0.0-beta.37", multiple values are actually returned in an Object, not an Array. However, since the ...
fodisi's user avatar
  • 51
5 votes

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

You can set the ganache-cli network ID by using a flag when running it: ganache-cli --networkId 4447
Shane Fontaine's user avatar
5 votes

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

You can use HDWalletProvider to connect to a provider (infura or your local node) using a mnemonic phrase. In case you are using truffle, you can do it by seting you config to something like this: .....
João Quintanilha's user avatar
5 votes
Accepted

Sending transaction from different addresses in truffle test case

In order to execute a state-changing function within a transaction, you need to use send. On Truffle you can also omit it and let Truffle choose the default: call for constant functions (either pure ...
goodvibration's user avatar
4 votes
Accepted

Truffle test remain in "pending" status

it("report correctly the best seller"), async () => { let bestSeller = await instance.bestSeller.call(); } // guess you didn't have ')' here, cause if it were there, it does not run to it(...
viz's user avatar
  • 535
4 votes
Accepted

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

The truffle test command-line uses the development network configuration. In other words, it is in fact equivalent to truffle test network=development. So I solved this problem by adding in each one ...
goodvibration's user avatar
4 votes

Returning dynamic arrays: out of gas

You get an out of gas because your Conversation[] userConversations; that you believe is in memory is actually on storage. Try to change it to Conversation[] memory userConversations; and you will ...
Xavier Leprêtre B9lab's user avatar
4 votes
Accepted

Contract state won't change during Truffle tests

A simple solution to this was right under my nose. Obviously, I just had to read the documentation given to me. methods.myMethod.call Note calling can not alter the smart contract state. methods....
Craig's user avatar
  • 118
4 votes
Accepted

how to test overloaded function in truffle?

Make sure you upgrade to the latest version of Truffle, and then check out these release notes on overloaded functions: https://github.com/trufflesuite/truffle/releases/tag/v5.0.0#user-content-what-s-...
faina's user avatar
  • 121
4 votes
Accepted

How to test kill function including selfdestruct()?

I don't quite get the code. It looks it should be xtn.kill(); In any case, kill wipes out the state and the bytecode. If I'm not mistaken, the return step will never happen because the contract was ...
Rob Hitchens's user avatar
  • 55.2k
4 votes

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

Use openzeppelin-test-helpers Specifically use expectEvent.inTransaction I created an example in the community forum for how to use: https://forum.zeppelin.solutions/t/how-to-check-for-events-that-...
abcoathup's user avatar
  • 1,338
4 votes
Accepted

How to call an overloaded function in Truffle with ABIEncoderV2?

Related to how to test overloaded function in truffle?, but slightly different with passing a struct. The solution is simple: MyContract.methods['init((address,address,address))'](myStruct)
Markus - soliditydeveloper.com's user avatar
4 votes

How to configure `truffle test` to fork the main/rinkeby chain as its local chain?

You can fork Rinkeby or the Mainnet pretty easily using Ganache-CLI. Read this article for a detailed explanation https://blockheroes.dev/test-smart-contracts-on-mainnet/ The simplest command is: ...
Ioana Roceanu's user avatar
3 votes

Truffle test error: Cannot create instance of Vault; no code at address

let VaultAddress = await VaultFactoryInstance.CreateVaultContract.call(); should be: let VaultAddress = await VaultFactoryInstance.CreateVaultContract();
thefett's user avatar
  • 3,873
3 votes

How to unit test struct values

You can deconstruct a struct's values when doing unit tests in Hardhat. In your example, if you would like to get the age and name from a struct then the code would be: let [age, name] = ...
Harbs's user avatar
  • 31
3 votes
Accepted

Truffle Test - Solidity: How to access value of Promise object? [object Promise] [BigNumber]

How can I access the value in c? the number is not only what is contained inside c but the whole BigNumber notation, which is accessible with a f.toString() How can I save object f to a javascript ...
qbsp's user avatar
  • 4,367
3 votes

Difference in contract instance in web3 and truffle test

The difference is that Truffle injects Web3.js 0.20 into the test script, whereas you are working with Web3.js 1.0. Web3.js is a whole lot different from Web3.js 0.20.
Henk's user avatar
  • 4,271
3 votes

What is the proper method of detecting the network inside of a Truffle test file?

If you are looking to know which truffle network key from the truffle.js was selected you can use the truffle object deployer which is passed as the first argument on the migration files ($ROOT/...
Gabriel G.'s user avatar
3 votes
Accepted

Truffle test error: Cannot create instance of Vault; no code at address

I finally managed to get a working solution (even though I'm not sure it's the best one). const VaultFactory = artifacts.require("./VaultFactory"); const Vault = artifacts.require("./Vault"); ...
Antoine Delia's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible