Questions tagged [truffle-test]
The truffle-test tag has no usage guidance.
301
questions
0
votes
0
answers
16
views
How to transfer money inside truffle console?
When I log in to the truffle console I see there are a bunch of addresses filled with money. I need to transfer an amount to the account that I am using with Metamask. (I don't want to import the ...
1
vote
0
answers
14
views
Deactivate clean-room environment in truffle
Everything is in the question, does anyone have a way to prevent the redeployment of the contract every time you run a test and keep using the same "contract" feature ?
Edit : I've found it, ...
0
votes
0
answers
18
views
Truffle migrations - it doesn't recognize the network from external file, why?
1_initial_migration.js file:
const Globals = require("../globals.js");
const Migrations = artifacts.require("Migrations");
const Test = artifacts.require("Test");
...
1
vote
1
answer
33
views
What are the Solidity contracts that the Infura NFT SDK uses? How can one test these contracts?
I am trying to make use of the Infura NFT SDK that would work with another contract that I developed. I wanted to make some unit tests locally, however, searching on their documentation and on the ...
0
votes
0
answers
78
views
How ganache unlocks account that doesn't belong to me?
In ganache mainnet fork, I can unlock any account and make transactions on behalf of that account:
npx ganache-cli -p 8545 -f https://mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID --unlock $...
0
votes
0
answers
23
views
Retrieving incorrect Address during Truffle Test?
Im practicing truffle tests after moving from hardhat. I began with a standard 721 like so:
// SampleNft.sol
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/utils/Counters....
1
vote
1
answer
45
views
Error: *** Deployment Failed *** "Migrations" -- Returned error: no pending block
When i run "truffle test" in VS on my basic helloworld smart contract, i get the error message:
"Error: *** Deployment Failed ***
"Migrations" -- Returned error: no pending ...
0
votes
1
answer
133
views
Truffle/Ganache Gas Limit Increase [duplicate]
I had posted on the GitHub Discussion as well. I have this massive smart contract and my goal is to study the scalability of the contract. The values work for smaller sizes. However, it fails at ...
1
vote
1
answer
67
views
About try-catch error(Truffle Test)
I am learning solidity by transcribing code from "Practical Smart Contract Development with Solid and Etherium"(OREILLY).
I am studying hard but struggling along the way.
It is to be tested ...
0
votes
1
answer
51
views
Truffle: { Error: Invalid number of parameters for "undefined". Got 0 expected 1! at module.exports
I am trying to execute the following smart contract using Truffle:
pragma solidity 0.5.16;
contract Phishable {
address public owner;
constructor (address _owner) public{
owner = ...
0
votes
0
answers
50
views
How to add delay while testing smart contract
Currently I am testing smart contract with truffle framework. In my smart contract I have a function which can be executed for limited time period(say 100 seconds from contract deploy). How can I ...
1
vote
1
answer
76
views
Why am I getting incorrect WBTC when swapping it with DAI using Uniswap?
Hi I created a smart contract but when I am swaping 1 Million DAI with WBTC tokens I am getting only ~3379786784 WEI (~34 WBTC) but when I am checking its value on UNISWAP website it is showing 43 ...
1
vote
0
answers
46
views
Unit testing a double mapping
How to call a double mapping in unit tests?
Here is an extract of our contrat:
contract StackingPool {
struct Staker {
uint128 amount; // Amount token stake
uint256 date; // Date ...
0
votes
0
answers
62
views
Require causing transaction revert although condition is true on smart contract
something strange is going on. I'm testing some contracts on remix EVM. I have some pretty basic NFT staking contracts that works fine when comes to staking and transfering the token. However, if I ...
0
votes
0
answers
46
views
Truffle test: Error: expected event argument '_ids' to have value 1 but got 1
I wrote an ERC1155 Nft whith this following function:
contract Nft is ERC1155{
using Counters for Counters.Counter;
Counters.Counter private id;
event MintBatch(address indexed _to, ...
0
votes
1
answer
114
views
"Error: Returned error: VM Exception while processing transaction" when I run truffle test
I'm running my unit test with truffle in ganache environment.
Here's my Lottery SC:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@...
0
votes
0
answers
109
views
How to run truffle debugger on failing test that reverts
One particular function in my smart contract always runs out of gas and reverts. I am trying to do a debug of my contract source code to figure out where the "gas leak" is, and fix it. I am ...
0
votes
1
answer
74
views
"insuffiecient allowance" running my unit test
I'm developing in remix a lottery SC. I have a problem when I run buyTicket() function. On remix I fix it giving approve to SC address from erc20 function, but I don't know how to do it when I run my ...
0
votes
1
answer
74
views
Error: No events were emitted
I am coding an ICO project. However when trying to make the token purchase I got the following error:
Using network 'test'.
Compiling your contracts...
===========================
> Compiling .\...
1
vote
1
answer
15
views
Passing an error testing suite in contract
hello how do i make a proper testing suite for error?
the contract has this modifier for freeMint() fn
modifier protectTier(uint256 _level) {
require(
_level != privateTier, &...
0
votes
1
answer
89
views
Truffle Struct Test How To Call
how to call struct properties in truffle test ? for public variables we can use .call() but i cant figure out how to do with struct properties
how to access properties of struct ?
with any other ...
0
votes
1
answer
98
views
truffle test does not run tests when test network is not specified
trying to run a test for my contract, but truffle test is just compiling the contracts and not running anything. my truffle.config does not specify a test network, which should result in truffle ...
1
vote
0
answers
11
views
Truffle test, is it possible and useful to test types?
All is in the question : is it possible and useful and to test types ?
Or don't need to test it because Solidity is a statically typed programming language (it's already done).
I did many researches ...
0
votes
2
answers
106
views
How to use truffle-assertions to check if a constructor will revert?
Say I have a contract:
contract Reverts{
constructor(param1){
require(param1);
}
}
If param1 is false, the constructor should fail and revert state.
truffle-assertions allows me to ...
0
votes
1
answer
51
views
Storage arrays don't store my input values
I checked other similar topics but I still can't figure out how to solve my problem, the code below is part of my contract,
pragma solidity ^0.8.13;
contract MyContract{
address owner;
...
0
votes
1
answer
243
views
Testing `approve` function
I would like to test a contract where I use the approve function of an ERC20 token.
Is there any test suite that allows doing that?
truffle? hardhat?
Any suggestion would be highly appreciated!
1
vote
1
answer
81
views
How to write the javascript test code on whether a smart contract function is successfully executed or not?
I wrote a lottery smart contract and gonna to test an "enter" functionality of the smart contract.
The below code is javascript test code for the "enter" function of the smart ...
0
votes
0
answers
26
views
Truffle test not running completely
I am a beginner in Solidity and truffle.
Trying to create something from scratch so I am not using anything from openzeppelin.
I created an ERC20 token smart contract and created a second smart ...
1
vote
1
answer
1k
views
why vs code not recognizing the node version
when I install a "truffle for vs code" extension in vs code and try to create a new solidity project then nodejs version is not recognized but I have installed nodejs's correct version.
0
votes
1
answer
396
views
Truffle Test Console Logging
I'm having some trouble with Truffle logging configuration. During tests, each submitted transaction and its hash is logged on the console and this one becomes full of useless messages that disturb ...
0
votes
1
answer
234
views
Truffle default account private keys
Is there a way in truffle develop tests to access the list of private keys in the same way we can access the list of accounts?
Basically, for every contract I need to test, the truffle test contract ...
1
vote
1
answer
196
views
truffle installed but not working
I'm using node version 12.20.2 and npm version 6.14.11 and installed truffle with cmd as administrator, the truffle framework version 5.5.12 has been installed but when I run any command in the vs ...
0
votes
1
answer
87
views
unable to install truffle
I'm trying to install truffle on node version 8.9.0 but it shows it has been installed and when I try to do anything on that, throws this error.
C:\Users\com\AppData\Roaming\nvm\v8.9.0\node_modules\...
2
votes
0
answers
75
views
Eth-gas-reporter typeError
I am trying to understand how the eth-gas-reporter works but I keep getting
TypeError: invalid reporter 'eth-gas-reporter' when I ran truffle test.
Specifically the output is:
Using network '...
0
votes
1
answer
38
views
Why is there a difference in ether sent and difference in balance before and after transaction?
I'm doing a simple Dapp where I register a star as an NFT, using openzeppelin ERC721 contract, and then I can put it up for sale and buy it. In truffle I'm writing a test where I create a star, put it ...
0
votes
1
answer
61
views
Requires working strangely / truffle / tests
My contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.13;
import '@openzeppelin/contracts/access/Ownable.sol';
contract GuessAndWin is Ownable{
string public hint;
string ...
0
votes
0
answers
46
views
Issue in test-environment install
I tried to install test-environment, it throws the error. Please advice on how to solve this.
npm ERR! enoent undefined ls-remote -h -t https://github.com/ethereumjs/ethereumjs-abi.git
PS E:\...
1
vote
0
answers
89
views
Truffle test throws an error in "before each" hook
Developing a flash loan which i use truffle to test my code,
david@LAPTOP-3KIH2P0K:/mnt/c/pr0/flash/FlashloanLeveragedYieldFarm$ truffle test
Using network 'development'.
Compiling your contracts...
=...
1
vote
0
answers
93
views
Truffle Testing, Javascript & Solidity Testing Use Case
I’ve been studying the truffle documentation and saw how little differences were detected between the way solidity testing and javascript testing works. This confuses me as a developer, the ...
0
votes
1
answer
669
views
mintNewPosition function of LiquidityExamples contract (Uniswap docs - V3) get reverted when trying to add liquidity
I am trying to interact with Uniswap V3 contracts. More specifically, I am trying to add liquidity to DAI - USDC pool. I am doing this locally by forking the Mainnet using ganache. This is my contract ...
1
vote
1
answer
65
views
Why Contract State not Persisted in Every Test Sequentially?
I have a smart contract in truffle project and want to test it. I have multiple tests sequentially which means contract's state after first test will be needed for the second test.
The problem is, it ...
0
votes
1
answer
77
views
Truffle Test: Using a contract instance as function parameter
I'm having a function IN A LIB that require a contract as parameter.
function createCalendarEntry(uint256 releaseTime,
SPToken token) public pure returns (CalendarEntry memory) {
return ...
0
votes
2
answers
1k
views
How to Automate End to End Testing For Etherium Dapps With Metamask?
I'm wondering what the best way to test the entire stack of a dapp is?
From UI -> to wallet connection -> web3.js and interacting with the smart contract?
In web2 we could just use something ...
0
votes
1
answer
205
views
toNumber is not a function while writing tests
I am trying to write a simple test to validate a condition, however it fails saying 'toNumber is not a function'
Here is the test condition
const quorum = await wallet.quorum;
assert(quorum.toNumber() ...
0
votes
1
answer
84
views
Javascript testing vs remix
So what would be the benefit of testing the smart contracts using javascript with truffle instead of remix? I just feel is really tedious. I'm guessing there is a reason, but I don't see it, so should ...
1
vote
1
answer
103
views
How test uint from smartcontract with chai?
In my solidity smartcontract, I have a function to return a uint value :
function getUserBalance(address userAddress, address tokenAddress)
public
view
returns (uint256)
{
...
0
votes
1
answer
16
views
How do I assert this properly?
Say I want to make a test for this sample contract:
// assume we import OpenZeppelin's Ownable
contract Metaverse extends Ownable, ... {
...
// Assume this is just to experiment and learn.
...
1
vote
1
answer
635
views
Signing messages in Truffle tests
I use Truffle to develop locally and run tests with truffle test (letting it create a temporary local blockchain).
In one of my tests I need to sign a message and for that I need the test wallet's ...
0
votes
1
answer
277
views
withdraw function for withdraw ethereum token from a contract is behaving weird
I copy a withdrawal function from the solidity documentation and added it to my contract
function withdraw() public onlyOwner {
uint256 ownerBalance = address(this).balance;
require(...
3
votes
1
answer
432
views
Cannot retrieve uint Array from Struct in Solidity
I have the following struct in my contract
struct Transaction {
TransactionType transactionType;
uint256 id;
uint256 productId;
uint256 timestamp;
address from;
address to;
...