Questions tagged [truffle-test]
The truffle-test tag has no usage guidance.
161
questions
2
votes
1answer
13 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
27 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,
...
0
votes
2answers
29 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
20 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
26 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
19 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
0answers
13 views
Assertion error running truffle test
I cant 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 name = "Lair ...
0
votes
0answers
15 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
14 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
13 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
27 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
23 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
41 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
23 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
35 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
35 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 ...
3
votes
0answers
52 views
`eth_getTransactionReceipt` returns the transaction hash not the receipt
I use sol-coverage in a truffle project. Ganache is my development blockchain. I have a lot of tests which end up doing more than a few thousand JSON RPC calls.
Due to unbeknownst reasons, the ...
1
vote
1answer
257 views
Simple Truffle tests timeout “before all” hook: prepare suite
I'm trying to write my first tests for truffle, but I run in a timeout each time I want to execute the tests.
Error: Timeout of 120000ms exceeded. For async tests and hooks, ensure "done()" is ...
1
vote
2answers
41 views
How do I specify the network ID in the config file when migrating/testing contracts on my local ganache?
So my issue is when I run the compile and then migrate commands everything goes smooth, then I try to test by running the truffle test command and it gives me an error saying 'Error: The network id ...
1
vote
0answers
54 views
What is the easiest way to write truffle tests in typescript?
I read about Typechain, but the configuration is rather verbose and generally feels like a very custom solution:
Everytime you change contracts you need to run yarn generate.
2
votes
1answer
50 views
How to trace the line where a tx failed in truffle tests?
I know about 0x's sol-compiler and sol-trace. I used them before and they do exactly what I'm looking for, but these modules bring significant overhead when used with truffle. Check out this file to ...
-1
votes
2answers
94 views
Truffle uint test script not updating storage variable, and strange behaviour
while testing I got a strange behavior of truffle, please see the subject smart contract code first
uint256 public burningRatePercent = 50;
function onlyOwnerSetBurningRate(uint256 ...
1
vote
1answer
18 views
Does truffle test mimic the exact network state of an actual migration?
I've defined a truffle migration step as follows:
Deploy my 'main' smart contract, nothing out of the ordinary:
var UniversityVoting = artifacts.require('./UniversityVoting.sol');
module....
0
votes
1answer
33 views
How does a transaction verified with Truffle test?
I'm a new to Ethereum and Solidity, and I don't understand how Truffle executes transaction calls.
From what I learned and understood, if I try to use a contract method which changes the contract's ...
1
vote
1answer
136 views
Error when testing the contract
ApprovalContract.sol
pragma solidity ^0.5.1;
contract ApprovalContract{
address public sender;
address payable public reciever;
address public constant approver=...
0
votes
1answer
49 views
totalSupply doesn't pass test
I'm starting programming. I wanted to do my first contract and I assigned totalSupply to 1000000.
pragma solidity ^0.5.8;
/**
* The DappToken
contract Constructor
Set the total number of tokens
...
1
vote
2answers
37 views
Contract.deployed() does not work as expected
I use Truffle to test a contract. When i use Contract.deployed() and i fetch address, for example :
In a first test, the contract's address is
0x07D899846146b3503dE9D9Dc36B94C2e428eA434
In a second ...
1
vote
3answers
316 views
Testing sha256(abi.encodePacked(_argument))
When trying to test a smart contract that uses
sha256(abi.encodePacked(_myargument))
I don't get the same hash on truffle !
I tried both
web3.utils.keccak256('_myargument')
web3.utils.sha3('...
3
votes
2answers
108 views
How to test events that were sent by inner transaction / delegate call?
Usually, using truffle I can check for events like this:
let { logs } = await myContract.doSomethingImportant( xxx );
// 1500 tokens are expected to get
expectEvent.inLogs(logs, '...
1
vote
1answer
29 views
ERC20 RefundableCrowdsale
I have a crowdsale contract that inherits RefundableCrowdsale.sol from OpenZeppelin. I was using their v1.10.0 initially, but now revamping it using v1.12.0.
contract TestTokenCrowdsale is Crowdsale,...
0
votes
1answer
38 views
truffle won't run tests while initializing a global contract instance
I am testing my smart contract in truffle. I need to declare some global variables hence I did so outside 'it'.
I also tried declaring a global contract instance that I can use in all test cases.
...
0
votes
1answer
69 views
truffle testing enum
I am trying to test an enum value from a test. This is simplified version of the contract:
pragma solidity >=0.5.0 <0.7.0;
contract Foo {
enum State {
StateA,
StateB
}
State ...
1
vote
1answer
44 views
Event declaration which fix my tests
I'm going to try to put this in simple. This is the code of my contract:
pragma solidity ^0.5.0;
contract Lottery {
address public manager;
address[] public players;
event Deposit(...
1
vote
3answers
105 views
A single exception in Truffle test causes every other test cases to fail
I'm making test script for my contract and it looks likes
contract('...', async () => {
let token = null;
before('deploy', async () => {
token = await MyContract.new(...);
})...
1
vote
1answer
226 views
Which network does truffle use for testing?
I have a network 'foo' that is configured inside truffle.js. Running my tests works just fine
truffle test --network foo ./test/*.js
then I realized I forgot to start 'foo'.
To confirm this running ...
1
vote
2answers
358 views
invalid number value (arg=“_goal”, coderType=“uint256”, value=2000000000000000000)
i am following a tutorial from here. And upon running truffle test. It produces following error.
2_HashnodeCrowdsale.js
======================
Deploying 'HashnodeCrowdsale'
------...
2
votes
1answer
323 views
“Callback was already called” during truffle test using a solidity testfile
I'm creating a contract/token which extends the openzeppelin ERC20.sol and Ownable.sol.
My contract has no own logic yet and looks like this:
pragma solidity ^0.5.2;
import "../node_modules/...
0
votes
0answers
15 views
Solidity: (why) is it considered an anti-pattern to inherit a contract in a truffle test?
There are some functions I'd like to expose on my contract but only for testing purposes. It seems reasonable to specify them with a visibility modifier of internal and have the test contract inherit ...
0
votes
0answers
201 views
Truffle.js file is not created with truffle init command
I have run the truffle init command successfully with creating the following directories and files such as contracts, migrations, test, and truffle-config.js but the one file is missing as truffle.js? ...
1
vote
2answers
109 views
How use Truffle Framework [closed]
Anyone please help me to understand what is exactly Truffle & Ganache ?
How to install & use Truffle ?
Please reply who are know this.
0
votes
0answers
161 views
TypeError: Member “equal” not found or not visible after argument-dependent lookup in type(library Assert)
Truffle v5.0.8 (core: 5.0.8)
Solidity v0.5.0 (solc-js)
Node v10.13.0
Web3.js v1.0.0-beta.37
Assert.equal worked in Truffle 4.x.
pragma solidity >=0.4.21 <0.6.0;
import "truffle/Assert.sol";
...
0
votes
1answer
100 views
How to test kill function including selfdestruct()?
there.
I'm coding kill function below:
function kill() public onlyOwner returns (bool) {
selfdestruct(msg.sender);
return true;
}
and my unit test code:
function testOwnerCanKillContract()...
0
votes
1answer
129 views
Truffle, getPastEvents synchronously
I try to check that a total of 4 events have been emitted by my contract instance. Next code will fail in the assert.equal line since getPastEvents will process the events in a callback and so the ...
3
votes
2answers
211 views
Truffle Test Issue With `address payable` and Compiler Version
I am trying to run truffle test on an old contract which was written using pragma solidity 0.4.24;. While I am able to deploy the contracts using truffle migrate, I get the following error when ...
0
votes
1answer
33 views
Cannot retrieve data from smartcontract during tests
I am writing truffle tests for my smart contract solidity version 0.4.24. The tests are emitting events to write data to memory through smart contract. But I am unable to retrieve data from functions.
...
0
votes
0answers
65 views
TypeError and ReferenceError in truffle test
Im newbie and doing an exercise Im having this errors at truffle testing:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
...
0
votes
1answer
208 views
truffle test: SyntaxError: missing ) after argument list [closed]
truffle test
Using network 'development'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
/home/ubuntutest/proyectoico/test/...
1
vote
2answers
60 views
Trying to test the contracts fully
truffle(develop)> version
Truffle v5.0.5 (core: 5.0.5)
Solidity v0.5.0 (solc-js)
Node v10.15.1
const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol');
contract ('...
0
votes
1answer
72 views
Truffle - how to share variables and functions between test files? [closed]
I have files in Test directory, each one performs different test but all of them contain at least exactly the same functions "register" and "vote", also few arrays like votings = [], groups = [] and ...
2
votes
1answer
164 views
how to test overloaded function in truffle?
I recently upgraded truffle to the newest version. Now it does not automatically detect overloaded functions anymore. Before, I could just do the following:
await contract.function({
from: accounts[...