Questions tagged [truffle-test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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 ...
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 ...
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!"); ...
0
votes
2answers
218 views

Mocha test at kill() function

How to test with Mocha and Chai that a call at the kill() function of a Smart Contract (i.e., which does the selfdestruct) has gone right?
0
votes
1answer
637 views

Error: VM Exception while processing transaction: out of gas - Truffle

I'm facing some issue with test cases, I wrote some simple function in my smart contract as following: function Create ( bytes32 _a, address _b, string _c, address[] _d, uint256[]...
0
votes
1answer
1k views

Error: Transaction:exited with an error (status 0) after consuming all gas

New to Ethereum and learning unit testing with Truffle. Here in smart contract function; function createAgreement( bytes32 _id, address _owner, string _fileHash, ...
1
vote
1answer
95 views

Truffle Test: How to Run n times the same function

Since I have to study the variation of the gasUsed of a function, using Truffle Test is it possible to do a test that runs n times the same function without going out of gas or exceding the block gas ...
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 ...
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
1answer
430 views

Better ways to test bytes32 type using truffle testing framework

small quick question, when I store a bytes32 and retrieve it from truffle console, why is it showing in 64 bits? Ex: 0x74657374737472696e6700000000000000000000000000000000000000000000 because this ...
0
votes
1answer
153 views

Truffle Test: How to send ether to a contract from a contract?

Would like to test the modifier below modifier isNotAContract(){ require (msg.sender == tx.origin, 'Contracts are not allowed to interact.'); _; } How can I invoke a function using this ...
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 ...
1
vote
2answers
778 views

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

I'm trying to make a simple test in Truffle using Ganache where I call a function from a smart contract instance. This component will create a Vault and return me its address. My truffle test does ...
0
votes
1answer
252 views

Solidity: VM Exception while processing transaction: invalid opcode - What happens?

If VM Exception while processing transaction: invalid opcode is thrown, does it have the same effect than revert?
0
votes
2answers
518 views

Unable to transfer ERC20 tokens from a contract

I'm having trouble getting a solidity contract method to transfer ERC20 tokens from address A to B assuming B has called approve outside the contract and setup sufficient allowance for A. The ...
0
votes
1answer
131 views

Transaction reverted when testing requires/asserts in non void functions

im trying to test the requires of a Smart Contract using just solidity according to this article: http://truffleframework.com/tutorials/testing-for-throws-in-solidity-tests This is the contract, 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 ...
1
vote
1answer
915 views

How to unit test struct values

I'm new to Solidity development and I'm trying to figure out the best way to test a function which sets the values of a struct in my Truffle environment. Firstly, is it expected that the result of ...
0
votes
1answer
584 views

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

a.getB.call().then(function (f) { console.log(f[1][0]) }); outputs: BigNumber { s: 1, e: 20, c: [ 5000000 ] } How can I access the value in c? How can I save object f to a javascript variable? ...
1
vote
1answer
208 views

How do OpenZeppelin ERC721 tests pass?

I don't understand how the following test can pass. I tried it in my application and it fails. The entry point is the description 'when called by the owner'. In this function two test cases are ...
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(...
0
votes
1answer
419 views

Difference in contract instance in web3 and truffle test

When I'm working whit web3 I have something like: var abi = [...]; var contract = new web3.eth.Contract(abi,"0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0"); then I use something like: myContract....
0
votes
1answer
281 views

Solidity unit tests for contracts with a dynamic array return type

I am writing a simple smart contract for storing an array of bytes32, pushing to it, and retrieving it: contract SimpleStorage { bytes32[] public items; event ItemAdded(bytes32 contents); ...
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 ...
1
vote
0answers
266 views

Truffle TypeError: Member “error” not found or not visible after argument-dependent lookup in type(library Assert)

Trying to test my Solidity contract for errors using Truffle test. TestSafeMath.sol function test_add_10_and_max_should_return_err() { uint256 max = 2**256 - 1; Assert.error(SafeMathExt....
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;...
1
vote
1answer
309 views

Truffle test remain in “pending” status

I've a smart contract under test, which exposes a public property of type address bestSeller: contract Club { address public owner; uint public price; //price to join the Club uint public ...
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.
1
vote
1answer
230 views

Help with inheritance and Truffle tests

I have two contracts that both inherit from OpenZeppelin's Whitelist. After deploying both contracts, I use an instance of the first contract to add a "trusted" address to the whitelist. Since both ...
0
votes
1answer
644 views

Truffle Test Library - TypeError: Member not found or not visible after argument-dependent lookup in library

Can somebody confirm this behavior and provide a solution? Using truffle test I get the error message Member "functionName" not found or not visible after argument-dependent lookup in library A. Is it ...
0
votes
3answers
2k views

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

I want to test gas limits of the block. Currently in my tests: console.log(accounts); console.log(accounts.length); I have 10 accounts, what to do if I want more? Related: https://github.com/...
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?
1
vote
2answers
506 views

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

Ropsten, Mainnet, or Ganache for example.
0
votes
2answers
322 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 ...
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: ...
1
vote
0answers
238 views

Invalid number of arguments to Solidity function

I have a function in my contract. First takes argument, the second one does not. Everything works fine until I change the name of the second one into the same one as the first one and create ...
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 ...
1
vote
1answer
191 views

Truffle test seems to succeed, but then 'transaction wasn't processed in 240 seconds! '

I have 5 smart contract functions and 26 unit tests for them. If I run the tests together, they run green, however, in the end, I get a timeout error: The error message wasn't quite informative for ...
0
votes
1answer
1k views

msg.sender.transfer(purchaseExcess); failure in solidity test

Got an exception at the line msg.sender.transfer(purchaseExcess); in my truffle solidity unit test. Any idea the reason? my contract code: function purchase(uint256 _tokenId) public payable { ...
1
vote
1answer
122 views

Contract not found during truffle test

I created and deployed two contracts successfully (with confirmation) using truffle migrate like so: module.exports = function(deployer) { deployer.deploy(ReentrancyPot).then(async () => { ...
0
votes
0answers
78 views

Gas + balance invariant not maintained on simple contract call

In order to understand reentrancy attacks, I'm using the following Honeypot contract: pragma solidity ^0.4.17; /// @title ReentrancyPot - A contract vulnerable to reentrancy contract ReentrancyPot { ...
1
vote
1answer
311 views

Very simple Truffle test, but assertion fails (functions seem to work fine in Remix)

In my QueryResultHandler.sol file, I have three functions: one for storing data (requesting two IDs as integers and two string values) and two for validation (either by providing the integers or the ...
0
votes
1answer
820 views

Truffle Error-VM Exception while processing transaction: revert

I am creating test case of solidity in truffle and my solidity function is given below for which I am creating test cases function isValidBuyer(uint256 buyTokenQty, uint256 senderValue) public ...
0
votes
0answers
289 views

Calling function of one contract in another using truffle

I have one contract and in it's constructor I have initialized properties of balances contract TestChainCoin is RefundableCrowdsale { function TestChainCoin() RefundableCrowdsale() { ...
0
votes
1answer
1k views

How to test a simple payment contract

I'm trying to test a simple payment contract according to the truffle tutorial, but not able to get it working. Would appreciate your guidance on how to get account balances (that seems to be the ...
0
votes
2answers
143 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
1answer
446 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, ...
1
vote
1answer
265 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 ...
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); }...
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 ...