Questions tagged [truffle-test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
17 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
29 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
14 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: &...
0
votes
0answers
12 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
20 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
1answer
35 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
0answers
13 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
96 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
10 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
25 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
23 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
12 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
59 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
103 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
35 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
6 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
12 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
290 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
41 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
13 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
74 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
26 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
9 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
25 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
165 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
138 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
69 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
27 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
68 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
23 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
59 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, ...
1
vote
1answer
132 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
23 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 ...
0
votes
1answer
22 views

Difference between contract.new and contract.deployed functions

I have create a basic truffle project and i am writing automated tests. There is 2 ways to instantiate the smartcontract to test and i want to understand the difference between this 2 ways: const ...
-1
votes
1answer
18 views

sync function syntax [closed]

What is the difference between this syntax: beforeEach( async () => { ... }); and this one: beforeEach(async function() { ... }); Thanks
0
votes
1answer
57 views

Truffle test: could not find local build/contracts

I have create a truffle project with this command: truffle unbox react I have run this commands: npm install @openzeppelin/contracts npm install @openzeppelin/test-helpers npm install @openzeppelin/...
2
votes
1answer
167 views

Why do my truffle tests get much slower as I run more of them?

So I am currently building up a test suite for a project, and I have quite a few tests at this point. I am running into a problem however that truffle seems to run tests later in its execution much ...
0
votes
1answer
29 views

Truffle test: Problem with understanding the test

I am trying to understand the test provided at: Tutorial ("Test balance after deposit", function() { return SimpleBank.deployed().then(function(instance) { sb = instance; ...
0
votes
0answers
82 views

Truffle test doesn't recognize estimateGas function

I'm trying to test my contracts using Truffle and Ganache, but I'm facing some problems with some functions. When I call a non view function, I'm getting the error "out of gas". Moreover, if ...
0
votes
2answers
44 views

Issue deploying a contract successfully with Truffle and ganache

Long story short my contract is not passing the deployment test using truffle, mocha, and chai. I ran the code individually in the truffle console and it was returning an address just fine but it won'...
0
votes
0answers
41 views

Wrong contract balance shown by web3.eth.getBalance

I want to test if the balance updates when I send some eths it("the balance matches the price of a person", async function(){ let instance = await People.deployed() await instance....
0
votes
1answer
111 views

Truffle Test AssertionError: error message must contain revert

I can't figure out why this error occurs Here my test js code: var YarockToken = artifacts.require("./YarockToken.sol"); contract('YarockToken', function(accounts) { var tokenInstance; ...
0
votes
0answers
2k views

Metamask RPC error -32603… {“error”:“revert”,“program_counter”:6758,“return”:“0x”}

I have a dApp that leverages ERC721 contract which allows users to upload images onto IPFS and transfer them to each other. User A can upload images fine and transfer them fine to User B. Once ...
1
vote
1answer
22 views

How to resolve the issue while trying to test my contract

I'm new to blockchain development and can't figure out what I have done wrong. This is my smart contract Election : pragma solidity ^0.5.0; contract Election { struct Candidate { uint ...
0
votes
0answers
63 views

Truffle “test” is passing only 1 it(“”) test instead of showing “all 3 tests passed”

MyToken.sol //// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract MyToken is ERC20 { constructor(uint256 ...
0
votes
0answers
172 views

“before each” hook error while run truffle test command

I ran truffle test command on my project for testing but I got an error like this: "before each" hook for "1- should be return true Pauser Role for account[0]" why I'm getting ...
2
votes
2answers
86 views

Importing openzeppelin-test-helpers

Somethings I need BN library for correct balanceOf assertion with 1e18 decimals, somettimes expectRevert. I see the different projects use it differently: const { constants, time, ether, expectRevert }...
0
votes
0answers
15 views

truffle deployer - addess is still there without deploy

First Question: // Stage deploying A before B deployer.deploy(A); deployer.deploy(B); This is found on the truffle website. It says stage deploying A before B. So this must mean that deploying B ...

1
2 3 4 5