Questions tagged [truffle-test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

truffle solidity unit test modifiers: How do you test modifiers dependent on the sender account?

QUESTION: How do you write unit test code that would test that a non-owner can't execute a function modified by a requirement that they be the owner using in solidity and truffle? I am trying to write ...
1
vote
0answers
27 views

Is Truffle test useful?

Hi there I came across "Truffle test". As a developer I feel like it's better to test code on remix for unit testing rather than wasting time on writing truffle test in javascript. What do ...
0
votes
0answers
31 views

Testing using Truffle unbox: Assert.equal error

I ran the pet shop project. It uses "truffle unbox". The petshop project at: Petshop project using Assert.equal without any error is able to execute Assert.equal command but when I am using ...
0
votes
0answers
32 views

Problem with Assert.equal

I am compiling the code available at using "truffle test": https://michalzalecki.com/ethereum-test-driven-introduction-to-solidity/ pragma solidity 0.5.16; import "truffle/Assert.sol&...
0
votes
0answers
17 views

Truffle test stuck when testing with geth endpoint

I tried to test the truffle suite official metacoin example using truffle test. I opened a local private chain using geth with http rpc service open at localhost:8545. My truffle-config.js file is ...
0
votes
0answers
24 views

truffle test is showing error after running on truffle(develop) console

I am using truffle in windows and everything went well. I've successfully set up development network. But when I try to run test from the truffle(develop) console this error shows - TypeError [...
0
votes
1answer
22 views

How to use truffle-assertions to verify parameters of an emit?

I have not been able to find any resources with usage instruction besides github and blog post by the author On github an example is show as such: truffleAssert.eventEmitted(result, 'TestEvent', (...
0
votes
2answers
43 views

Signature test failed at Truffle js

I'm trying to test validAddress function from my contract ValidationUser, using truffle and test with JS. I checked the V value from the signature and its 27,28 so it is not the problem. Also, I have ...
1
vote
0answers
30 views

Using privateFor in truffle test

Using truffle , I am able to deploy private smart contracts using privateFor clause. However, I am not able to use in truffle test. I get the following error. Is there a way we can use privateFor ? ...
1
vote
1answer
30 views

How to call an overloaded function in Truffle with ABIEncoderV2?

How do you call an overloaded function in Truffle when passing a struct using pragma experimental ABIEncoderV2;? contract MyContract { struct MyStruct { address param1; address param2; ...
0
votes
1answer
34 views

address(this) in solidity is returning wrong contract address

This is my cantract code which I was using in truffle pragma solidity 0.5.16; contract Test { function getAdd() public view returns(address){ address add = address(this); return ...
1
vote
1answer
42 views

Sending transaction from different addresses in truffle test case

I am having an admin in my contract who can do certain things. Here is the contract function changeAdmin(address admin_) public { if (msg.sender != admin) revert(); potentialAdmin = admin_; }...
0
votes
1answer
45 views

What are the accounts generated by Truffle and Ganache? How is the Truffle migration done eactly?

I have a few question regarding Truffle, Ganache, and testing: When I execute truffle develop and get 10 accounts and 10 private keys, do those represent my accounts in my wallet or other users? For ...
0
votes
0answers
40 views

Truffle Error: invalid argument 0: hex string without 0x prefix

I'm trying to deploy and test the smart contracts on the Goerli network using Truffle. While migrating getting below error. Contract: Simple Storage Test suite Simple Storage Set ...
0
votes
2answers
31 views

How to specify custom test directory path in truffle-config.js

How do I specify a custom test directory path in truffle-config.js? My test directory is not present at the same level as truffle-config.js, it is residing in a different directory. Truffle has ...
0
votes
1answer
44 views

How can I make sense of solidity-coverage reports

I'm trying to check the coverage of an entire ERC20 set of openzeppelin tests. I'm using openzeppelin/test-environment and solidity-coverage v0.7.4 as plugins in truffle. The tests went fine but I get ...
0
votes
0answers
25 views

How can I test the placeBet() and settleBet() in ethereum hashdice contracts?

I would like to test the smart contract of hashdice using remix IDE, and using truffle. I wonder how to give the arguments for testing. function placeBet(uint _betMask, uint _modulo, uint _commit, ...
0
votes
1answer
46 views

Solidity test fails when testing onlyOwner functions

I have a contract where some functions can be called only by the owner of the contract and I want to test it with a solidity test in truffle. The contract looks like this: contract owned { ...
0
votes
0answers
57 views

truffle test fails with `Error: Callback was already called.`

I have a single .sol contract that includes 2 libraries, 1 interface and 3 contracts A, B and C such that B is A and C is A, B. The contract C is the one I am interested in as it includes all the ...
0
votes
1answer
29 views

Truffle Test: Setting blockTime

I'm using Truffle and I want to increase the blocktime to mimic that of the mainnet when i run my tests. As i understand it, Truffle has already instantiated a web3 instance that's ready to use so i ...
1
vote
1answer
39 views

TypeError: tests is not a function Error in Truffle

I am following an online tutorial, doing almost exactly like the instructor. I have the following error every time I try to run 'truffle test' my truffle-config file: module.exports = { // See &...
1
vote
1answer
39 views

Testing solidity transfer method not transferring tokens

I have this solidity contract: contract Token { mapping(address => uint256) public balanceOf; event Transfer( address indexed _from, address indexed _to, uint256 _value ); ...
3
votes
2answers
158 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 ...
0
votes
1answer
198 views

Error : Number can only safely store up to 53 bits

Hi I am trying to run the following tests var chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); var expect = chai.expect; var Bet = artifacts....
1
vote
1answer
30 views

How to use solidity library with truffle

I'm using truffle V5.1.13 and when I run truffle test the res variable contains a transaction receipt rather than the expected 2. I notice if I remove everything that has to do with the library things ...
0
votes
0answers
17 views

I got the error when I do 'truffle test' in Truffle tutorial that pet-shop-tutorial

I'm doing truffle tutorial the pet-shop-tutorial but when I typed truffle test in cmd, I got the error. Here is the error message. I have no idea how I can fix it and where should I check. Please ...
0
votes
1answer
98 views

Cannot create contract from another contract - truffle and ganache

I'm trying to write a test with ganache and truffle to create a contract instance from another contract. Everything works in Remix but it doesn't in ganache. This is the code const assert = require('...
0
votes
1answer
49 views

Unable to filter events with specific values of indexed parameters

I am currently trying to test a smart contract using the truffle suit ( with 'truffle test'). My contract is of a simple ERC20 token which includes the standard Transfer event: event Transfer(address ...
0
votes
0answers
25 views

How to assign event output to variable when testing?

I'm using Truffle test(chai/mocha) and openzeppelin-test-helpers. Can anyone help me about how to assign values from event to variables in the above testing environment?
0
votes
1answer
27 views

Truffle test: “Cannot read property 'gasUsed' of null” error. Truffle migrate works fine

Whenever I try and do truffle test I get the error Cannot read property 'gasUsed' of null But truffle migrate --reset works fine More confusingly, to rule out something in one of my tests that is ...
1
vote
3answers
160 views

Test using async/await in truffle not working

I am using node v12.13.1, truffle@5.1.8 and ubuntu 18.04 and running the test using documentation of async/await. https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-javascript#using-...
0
votes
1answer
186 views

TypeError: balance.toNumber is not a function

I need check that token has no balance when selfDestruct was called, but shows an error that balance.toNumber is not a function in the test file. DappTokenSale.sol function endSale() public { //...
0
votes
0answers
130 views

Mocha timeout when running truffle test. Works fine on ganache, not on public networks

This is the error I get when running truffle test --network kovan: 1) "before all" hook: prepare suite Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is called; if ...
4
votes
3answers
82 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 ...
2
votes
1answer
46 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 ...
1
vote
1answer
58 views

How do I pass a function pointer to a contract method from a unit test?

I'm getting this error: Error: invalid type (arg="type", value="function") when trying to call this method on the contract IntOption: function create( address target, string memory name, ...
1
vote
2answers
41 views

No events where emmited. Why?

This is not a duplicate question. The other one doesn't answer the problem in any way. Can anyone explain to me why do I get No Events where emmited when running truffle test? Ganache is listening in ...
0
votes
1answer
144 views

Truffle js test a call with arguments

I am trying to testa a smart contract function that receives an arg. I'm using truffle javascript tests, this is the smart contract function, very simple: function addExam(string memory hash) public ...
0
votes
1answer
90 views

Truffle. Test .call() args . Error: invalid string value (…) at PromiEvent

I have a js truffle test: it("should add an exam to the exams list", async () => { // This should test the complete functionality let hash_test = "fB03aA5E2E71De1470ae2"; let instance =...
1
vote
1answer
37 views

Solidity. Truffle test not passing “expected { _events: {},…” to equal

I can't get a test to pass, for me it is very clear but I am missing something obvious: This is the smart contract: function getContractOwner() public pure returns (string memory ...
0
votes
2answers
46 views

Assertion error running truffle test

I can't seem to understand where this error comes from. Maybe someone can help My token solidity file : pragma solidity >=0.4.2 <0.6.0; contract LairToken { //Name string public ...
0
votes
0answers
21 views

Truffle test passing when it should not

I have this test, it clearly shouldn't pass: contract("Exams", function(accounts) { it("should keep the contract owner", function() { // var expectedValue = "...
0
votes
1answer
47 views

Nothing happens whe I run truffle test

I am new to solidity. Maybe I am missing something obvious in the setup. But when I run truffle test, I get nothing, the terminal just stays there forever. $ truffle test ... and I don't know why, ...
1
vote
1answer
23 views

Different behavior of the same contract between JavaScript and Solidity tests with Truffle

I have a simple contract that functions as a ratekeeper - it is constructed with a capacity and time_frame (in blocks) parameters and makes sure we never add more than $capacity payments in any given ...
0
votes
0answers
35 views

Different when calling deployed Address and new() contract

I follow the code of MetaCoin project and wonder how different between two types of test: pragma solidity >=0.4.25 <0.6.0; import "truffle/Assert.sol"; import "truffle/DeployedAddresses.sol"; ...
0
votes
1answer
34 views

truffle test - does not Assert (Erc20, Solidity)

I am probably doing something wrong but can't see what exactly. Code: pragma solidity ^0.5.8; import "truffle/Assert.sol"; contract TestABC { function totalSupplyTest() public { bool a ...
-1
votes
2answers
57 views

Help a noob testing: it ' should deposit 1 Ether'

I wanted to revive or refactor this old smart contract as an exercise to learn solidity and js coding. Truffle compiled it and migrated it and it passed the first test (Although I'm not sure if it ...
0
votes
1answer
35 views

Call functions from another account by default in web3

In my truffle tests, I am trying to call a function from an account other than the default account, so not accounts[0] from the below result. web3.eth.defaultAccount doesn't seem to work. web3.eth....
0
votes
0answers
70 views

Truffle test including mainnet contract - Error: Cannot create instance of Whitelist; no code at address

Problem with the error Error: Cannot create instance of Whitelist; no code at address 0x6198149b79AFE8114dc07b46A01d94a6af304ED9 How do I have to setup truffle so that I can run a test which includes ...
0
votes
0answers
78 views

Truffle how to test with reference to mainnet smart contract - Error: while migrating VM Exception while processing transaction: revert

I would like to run a truffle test on a smart contract that includes a smart contract address deployed on mainnet. However, this results in the following error Error: Error: Error: while migrating ...