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-...
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(...
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.
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 ...
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()
'...
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 ...
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 ...
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 ...
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:...
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 {
...
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 ...
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 ...
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
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:
.....
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 ...
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(...
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 ...
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 ...
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....
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-...
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 ...
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-...
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)
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:
...
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();
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] = ...
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 ...
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.
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/...
3
votes
Accepted
Better ways to test bytes32 type using truffle testing framework
The values you're showing are 32 bytes long (256 bits), not 64 bits.
They're that length because the type is bytes32. The number 1 is different from 10, and the same holds in hexadecimal. You can't ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
truffle-test × 297truffle × 205
solidity × 112
testing × 36
ganache × 23
truffle-migration × 22
web3js × 20
truffle-contract × 20
unittesting × 20
javascript × 17
mocha × 14
truffle-deployment × 13
contract-development × 11
ethereumjs × 8
test × 8
tokens × 7
erc-20 × 7
contract-debugging × 7
erc-721 × 7
solidity-0.5.x × 7
ganache-cli × 7
openzeppelin × 6
go-ethereum × 5
blockchain × 5
truffle-compile × 5