Questions tagged [truffle-test]

The tag has no usage guidance.

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

Sign Transaction with Zero Address

I am writing and testing a smart contract. Using web3, I could not send a transaction from a Zero Address (0x0). I was wondering if it is ever possible to sign and send a transaction using the zero ...
0
votes
0answers
19 views

How to test with existing ERC20 tokens on local tests

I have a Solidity smart contract for NFTs that I need to test using Truffle Suite. While deploying the contract on Rinkeby, I provide it with an existing ERC20 token contract address that I use for ...
0
votes
0answers
7 views

Error: "This method only supports Buffer but input was..." when trying to test my solidity contract [duplicate]

Running the test suite will cause an error. The Error: Compilation finished successfully An unexpected error occurred: Error: This method only supports Buffer but input was: ...
0
votes
1answer
8 views

Issue running approve test

I need some assistance running the approving test. Currently running one of the basic test script to approve the token from exchange. I am getting the below attached err in WSL. Also, i believe the ...
0
votes
1answer
12 views

smart contract how link libraries to child contract under factory pattern

I am trying to create a factory and I can not find a way to link libraries to the child contract. I am trying to create a contract factory that create child contracts. the problem is that the child ...
0
votes
0answers
23 views

Testing state variables with Truffle (javascript)

I have a contract that defines a struct and has an internal function to create it such as struct Tokemon { string name; uint256 id; uint256 dna; uint32 level; uint8 rarity; ...
0
votes
1answer
28 views

How to test sending transaction from zero address in truffle

I have some smart contract which has this function: function someFunction() external returns (uint256) { require(msg.sender != address(0), "zero address"); //some code.... ...
1
vote
1answer
15 views

Testing address(this) generates exception, how to obtain the correct value for address(this)

I have modified the following code from a michalzalecki website https://michalzalecki.com/ethereum-test-driven-introduction-to-solidity/ to test address(this): pragma solidity 0.5.16; import "...
1
vote
1answer
71 views

Private keys & not buffer being passed to test file

I'm running a test on a very simple pool contract. I am using Mocha to write the tests, but Hardhat's network to run them. After firing up my Hardhat node I get the 10 test accounts per usual with ...
0
votes
0answers
38 views

How to addLiquidityETH in truffle console?

I'm trying to addLiquidityETH in truffle console but keeps running into ds-math-sub-underflow error. The pool pair is created at contract constructor and the wallet has more than enough for myToken ...
1
vote
1answer
28 views

How to test ether value in truffle test script using Mocha and chai

I'm having a method inside my contract which return a variable having value is 100 ether for example. E.g: uint256 private baseline constructor() { baseline = 100 ether; } function getBaseline() ...
0
votes
0answers
33 views

Truffle: Test contract creation from another contract

I have two contracts, Factory working as a factory for Business: // Factory.sol pragma solidity ^0.8.7; import "./Business.sol"; contract Factory { // Public only for debugging ...
0
votes
0answers
31 views

Why does this function produce an error in truffle but not not in remix?

I have a string handling library, consisting of several functions, but only one of them produces an error when I run it in truffle test. (The other functions seems to work fine.). This function does ...
0
votes
2answers
53 views

Error: *** Deployment Failed *** -- Invalid number of parameters for "undefined". Got 0 expected 1!

I am trying to deploy my smart contract. Upon deployment, I get this error message. Here is my contractToken.sol pragma solidity ^0.5.2; contract BPToken { uint256 public totalSupply; ...
0
votes
0answers
25 views

In my solidity file I have a parser Error but the line where truffle tells me the error has occurred is blank

I am building out a token and while testing using truffle my file failed to compile. pragma solidity ^0.5.0; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; contract Token { ...
0
votes
1answer
18 views

The second contract is not getting deployed in migration

const Input = artifacts.require("Input"); const Register = artifacts.require("Register"); module.exports = function (deployer) { deployer.deploy(Input, "test_name") ....
0
votes
0answers
42 views

Balance of ERC-20 Token suddenly changing to 0 in try/catch block

I'm coding a paymentsplitter that accepts LP tokens and standard tokens. If it's an LP token, it needs to convert them into the underlying assets, otherwise just split the payment. Since I only have ...
0
votes
0answers
6 views

Truffle test accounts

I'm trying to run unit tests with Truffle but the accounts being generated during testing are not the same as the ones generated at compile time. Is there a way to configure these?
0
votes
0answers
32 views

Cannot run a test version of the Truffle Pet Shop tutorial

I'm attempting to run npm run dev at the end of the Truffle Pet Shop tutorial, and I'm hitting an error. I'm not sure what I'm missing. Do you have any tips? Here's what I'm seeing in the console: &...
1
vote
0answers
54 views

Run truffle test, returns TypeError: Cannot read property '0' of null

after deleting several unnescesary smart contracts I was able to run npx Truffle Test and this is what my console returns... sing gas limit: 6500 K Using gas price: 10 Gwei Optimizer enabled: true ...
0
votes
0answers
45 views

Truffle Test - migration and test deploy contracts but test uses the parameter of migrations

I rage with this messed up truffle suit :D I have two contracts. One contract is owner of the other contract and is set at deployment. Now when I test it with truffle... I got 4 diffrent Contracts... ...
0
votes
2answers
166 views

How to configure `truffle test` to fork the main/rinkeby chain as its local chain?

The smart contract I want to unit test instantiates IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D). Obviously this contract does not exist on the local chain that is spawned by truffle ...
0
votes
1answer
24 views

How to test multiple contracts?

I have created a Ethereum dapp that has multiple contracts that access one another and use methods within each other. I would like to create a Javascript test which would emulate a use-case for this ...
0
votes
0answers
207 views

Truffle Test - Uniswap Router - Swap ETH for Token

I am trying to add an test for swapping ETH to Token. However, this works only if I am specifying as Receiver the Owner of the contract. As soon as I am changing the "to" parameter to ...
0
votes
0answers
18 views

Truffle Test error, and problems with npm

this isn't so much a truffle question, but more of a dependency and npm question. whenever I try to test this smart contract, my terminal keeps telling me that there is an error with my babel config. ...
0
votes
1answer
48 views

What is the proper way to handle revert errors from requires checks for truffle testing?

I have a smart contract that implements OZ's onlyOwner modifier for several functions. I am testing it using truffle and have written a unit test where a non-owner account calls an onlyOwner function....
0
votes
1answer
62 views

How do I separate truffle environments when working on separate projects?

I have two truffle projects on my local machine. When running truffle test on one project, the output indicates that all contracts from both projects are being compiled. I'd like to only compile the ...
0
votes
0answers
16 views

Testing a smart contract with Truffle

so I'm testing a smart contract a js framework called mocha and running the test through truffle. require('chai') .use(require('chai-as-promised')) .should() contract('Token', (accounts) => { ...
0
votes
1answer
96 views

Set msg.sender in testing

I have a Solidity function that manipulates an object. The function only allows this manipulation of the caller msg.sender is owner of that object. Something like this: function Manipulate(uint i) { ...
1
vote
1answer
385 views

How to properly write Solidity unit tests?

I would like to write maintainable and readable unit tests for my code. Requirements: Test different actors. E.g. a bank contract and three customers interacting with it. Test for errors. E.g. test ...
2
votes
0answers
41 views

1) "before all" hook: prepare suite for " "

I am trying to create an Integrated test (to test multiple smartContracts working together). I re-initialize them inside beforeEach() function. So I get the clean test for each test case. I have done ...
0
votes
0answers
7 views

Truffle Test Error for Hello World method

I am trying a very simple test in truffle using javascript. This is the solidity method I have function helloWorld() public view returns (string memory){ return "hello world"; } And I ...
0
votes
0answers
25 views

Truffle test - doesn't send funds to msg.sender

it seems like I have a wrong gnache or truffle setup ... I already ask a simular question here: Owner of contract is set to contract address? Basicly there is some mess up with addresses on my local ...
0
votes
1answer
538 views

Truffle test doesn't connect to Ganache

I'm using Truffle and Ganache for my development environment. Using the truffle console or truffle external scripts everything works fine, but truffle test does not seem to be connected to Ganache: ...
0
votes
0answers
71 views

Truffle test is failling with transferFrom.call

When I run tests with the following code, I get the following error: Error Error: Returned error: VM Exception while processing transaction: revert Tests it('Handles delegated token transfers', () =...
1
vote
1answer
14 views

Explore transaction from truffle test file

I have create this test: const { expectEvent } = require('@openzeppelin/test-helpers'); const MyContract = artifacts.require('MyContract'); contract('MyContract', function (accounts) { const [...
0
votes
0answers
120 views

Owner of contract is set to contract address?

I just testing a contract with truffle and Im wondering why the owner of the contract is set to the contract address itself. Migrations: const contractA= artifacts.require("ContractA"); ...
0
votes
1answer
43 views

Get The Address Of the Deployer Of Contract In Truffle Test

How can I get the address in Truffle that calls functions of the contract by default(When we don't use the {from: accounts[i]} statement)?
0
votes
0answers
11 views

ReferenceError while running the truffle test

I am getting the ReferenceError while executing truffle test, I got it from a book: //Greeter.sol pragma solidity >=0.4.0 <0.7.0; contract Greeter{ function greet() external pure returns(...
0
votes
0answers
40 views

Truffle test doesn't seem to finish before "succeeding", and doesn't wait for transactionHash of a sent tx!

quick problem I've been slamming my head against since last night, My truffle (v5.2.3) test file performs two (2) tests, that serially call() then actually send a transaction to make persistent ...
0
votes
1answer
403 views

Truffle test failing with "Error: Returned error: VM Exception while processing transaction: revert" - how can I debug it?

I'm using truffle, the ganache AppImage to run a personal blockchain, and have 2 solidity smart contracts Migrations.sol and PassportManager.sol I'm running a truffle test and getting Error: Returned ...
0
votes
1answer
21 views

Assertion Error

Solidity file pragma solidity ^0.5.0; contract Todo { struct User { uint id; string name; } User[] public users; uint public nextId = 1; function create(string memory name) public ...
0
votes
1answer
220 views

ERC721 testing transferFrom()

How can I test (truffle test or development console) the following: await nft.transferFrom(accounts[0], accounts[1], 1); await nft.transferFrom(accounts[1], accounts[0],1); The second line throws ...
0
votes
1answer
158 views

How can I test my purchase function on the truffle with chai?

I'm trying to test my token buying function but I encounter an error, o facilitate understanding I will show the code "Error: Returned error: VM Exception while processing transaction: revert&...
0
votes
1answer
32 views

Setting token balances in js test

I want to be able to set the token balance for Alice to 500 DAI & 500 USDT, however I have no clue how I am going to do that. Is there a way you can set an account's balance before a test without ...
0
votes
0answers
83 views

Transferring aToken(aDAI) in my truffle tests reverts with unspecific error

I'm having issues with setting up a truffle test to transfer aTokens (aDAI) to my contract. I'm using Aave v2 and running ganache with a fork from mainnnet. This is what I did so far: 1- Started a ...
0
votes
1answer
40 views

Interacting with existing Smart Contract deployed on test network like rinkeby from local test environment (truffle)

I have forked rinkeby network using ganache-cli as shown below ganache-cli -f https://rinkeby.infura.io/v3/id --account="fsdfmsadklksmdflskamf" Now, I want to test my smart contract which ...
0
votes
2answers
100 views

Use smartcontract's ENUM in test scenarios in truffle

I have create a truffle project with this command: truffle unbox react Here is my smartcontract contracts/SimpleStorage.sol : contract SimpleStorage { enum MyEnum { step1, step2, ...
2
votes
1answer
271 views

Big numbers in truffle test assertion

Here is what i've done: I have create a project this way: truffle unbox react npm install @openzeppelin/test-helpers I have keep SimpleStorage.sol sample contract and here is my test file: const { BN,...
0
votes
0answers
33 views

Set a gas limit when sending a transaction in a truffle test scenario

I am writing truffle tests for a smartcontract. I have create a truffle project with this command: truffle unbox react I have kept SimpleStorage.sol sample smartcontract. I have add some tests in ...

1
2 3 4 5 6