Questions tagged [test]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
39 views

Run a single hardhat test file

I have a few test files: ./test/ContractA.test.js const { expect } = require("chai"); describe("ContractA tests", function () { it("does function one", async function (...
user avatar
  • 123
0 votes
0 answers
10 views

Test Function with Random Output

I have a test that runs against an Ethereum smart contract (Solidity vs ^0.6). The function I am testing outputs a value A, say, 90% of the time and B 10% of the time. I want to test that this ratio ...
user avatar
1 vote
1 answer
11 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, &...
user avatar
1 vote
1 answer
24 views

Using modifiers in Foundry `test`

Is it a good practice to create modifiers in Foundry tests? When testing cases, that share significant number of steps, but not that much that you want to create a separate testContract for them, with ...
user avatar
0 votes
0 answers
16 views

expect revert breaking test

I have this function I expect to revert, unfortunately , it is breaking my tests. pwn = attackPwned.connect(pwner).pwnEm({ value: parseEther("1").toString(), }); ...
user avatar
  • 1,198
0 votes
1 answer
18 views

How should I approach testing functions that call already deployed contracts? [ethers.js] [chai] [mocha]

Suppose my contract utilizes the WETH contract (address 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2) in some manner. I can write test cases with Chai/Mocha just fine for most cases (they're "...
user avatar
2 votes
1 answer
27 views

Truffle contract factory test with Javascript

Here is my smart contract source code. // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract CampaignFactory { address[] public deployedCampaigns; function createCampaign(uint ...
user avatar
0 votes
1 answer
124 views

Sending multiple transactions in a block using Hardhat test network

Hardhat's test network, defaultNetwork: "hardhat" in config, automatically mines a block every time a transaction is sent by default. This is problematic for situations where I want to test ...
user avatar
  • 626
0 votes
1 answer
38 views

Test if a smart contract function has been called

In my hardhat project I'm testing my smart contracts using chai. For the sake of simplicity let's assume my contract is: contract MyContract { function a() external { b(); } function b() ...
user avatar
  • 523
1 vote
1 answer
116 views

How to write unit test in hardhat?

I´m new to solidity and wonder how I`m writing a uint test for this contract in hardhat: //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/...
user avatar
  • 27
0 votes
0 answers
86 views

Mocking and testing UniswapV2's swapExactETHForTokens in brownie: VirtualMachineError: revert: Index out of range

I'm at a loss with one particular brownie test I wrote, that relies on a mock I've written for Uniswap V2's swapExactETHForTokens, the code of which can be found below: In MockUniswapV2.sol: import &...
user avatar
  • 1
0 votes
1 answer
65 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 ...
user avatar
1 vote
2 answers
166 views

Truffle Chai Assertion Error with Truffle Unit Cases

Problem: facing an issue with the below Truffle test case while trying to Implement the ERC20 token in my contract. contract("Token Test", async(accounts) => { const[deployerAccount, ...
user avatar
0 votes
1 answer
30 views

Can someone please tell me what i have wrong here

function calculateSplitPercent() public { for(uint256 i = 0; i >= uniqueIdCounter; i++) { uint256 spliPercent = balanceOf[uniqueIdToAddress[i]].div(totalFunded).mul(100); ...
user avatar
0 votes
1 answer
33 views

I can't figure out why my test dont pass

I always get this an error when i run my test, i dont know what to do anymore you can test at my repository on github here
user avatar
1 vote
0 answers
190 views

experiencing "RangeError: Maximum call stack size exceeded" with hardhat mainnet fork, when calling contract names on chain

I am trying to test my contract against mainnet using the hardhat fork mechanism, I am using alchemy as my network provider and trying to retrieve the contract names from mainnet after creating ERC721 ...
user avatar
0 votes
2 answers
123 views

Understand the output of eth-gas-reporter

So, I am using the eth-gas-reporter package to understand how much gas functions costs (via hardhat test). But I don't understand the output. What is the meaning of 5 gwei/gas,calls, what are the ...
user avatar
  • 128
1 vote
1 answer
333 views

How to spoof accounts using Foundry?

Currently using Foundry & Hardhat for development, Foundry for testing & Hardhat for deployment. I'm trying to fuzz a test input of a function that adds an address to a whitelist and I need a ...
user avatar
  • 45
0 votes
1 answer
563 views

Convert big number to number on hardhat tests

Sorry for the newbie question. There are a lot of solutions but non of them worked for me. I am getting an account's balance with const balance_before = await ethers.provider.getBalance(redeemer....
user avatar
  • 128
0 votes
1 answer
1k views

Rinkeby faucet not working. Please help [duplicate]

Trying to send some test ETH to wallet but Rinkeby faucet not working. It says insufficient funds for gas * price + value. Looks like the queue is backed up for 2 days also. Is there a solution for ...
user avatar
0 votes
1 answer
37 views

how to subctract in type script big numbers?

I'm trying to to subctract in type script big numbers, but getting error... const supply1 = 100000; const _amount = 100; const supply = ethers.utils.parseEther(`${supply1}`); const diff = supply - ...
user avatar
  • 79
0 votes
2 answers
373 views

How to unit-test a contract using chainlink VRF v2?

I have seen similar questions using the chainlink VRF v1 but I don't manage to make them work. I have tried to: create a subscription on rinkeby chainlink add the address of my locally deployed ...
user avatar
0 votes
1 answer
131 views

TypeError: nft.createToken(...) is not a function error

I created an ERC721 token using openzeppelin like this: pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/...
user avatar
1 vote
1 answer
193 views

Hardhat stuck testing in mainnet by default

I'm new to hardhat and tried to run some tests. Everything works fine until I try to execute payable functions. Addresses generated with ethers.getSigners(); have no eth on them. Which made me realise ...
user avatar
0 votes
0 answers
9 views

How to fix the errors in appveyor

I submit a PR to go-ethereum I had tested the code on my local ubuntu server with go run build/ci.go test -dlgo -coverage and it returns OK,but there are lots of errors in PR's action I don't known ...
user avatar
0 votes
1 answer
37 views

Undeclared Identifier in Payable Function

I want to call a contracts functions from another contract for hardhat-gas-reporter purposes however I keep getting undeclared identifier here. What am I doing wrong? contract BaseRosie is Ownable, ...
user avatar
  • 1
0 votes
1 answer
212 views

Brownie : Contract Functionality not available in local environment

I have set up a new brownie project (brownie bake yearn strategy mix). When I try running tests I get this error : brownie.exceptions.BrownieEnvironmentError: Functionality not available in local ...
user avatar
  • 1
0 votes
1 answer
237 views

How do i get mocha's before() hook to work properly?

This is the test code im trying to run: const {expect} = require("chai"); const {ethers} = require("hardhat"); const {SignerWithAddress} = require("@nomiclabs/hardhat-ethers/...
user avatar
0 votes
0 answers
17 views

I'm using brownie for testing contracts but its stuck like that in the image

I made a project folder using brownie. I can deploy the contract from the scripts folder but when I test it it's stuck I can't find anything that solves the problem.
user avatar
0 votes
1 answer
25 views

Should I care about these benchmark values?

Let's say I have a contract which, for the sake of this post, inherits OpenZeppelin's Ownable. I made a minor update (in terms of code / complexity: an override & revert to disable a method). Then ...
user avatar
0 votes
0 answers
11 views

Remix price token implementation error

Please help me with the implementation of this contract. Blockquote// //AggregatorV3Interface internal priceFeed; /** * Network: Kovan * Aggregator: ETH/USD * Address: ...
user avatar
0 votes
0 answers
9 views

Why don't we have to import web3.js into testing js files? [duplicate]

As a newbie to solidity, this is my code for testing some smart contract that I wrote, by following a tutorial. The name of the file is "EthSwap.test.js" and I'm using "truffle". ...
user avatar
  • 143
0 votes
0 answers
11 views

How to solve Rinkeby Authenticated Faucet reCaptcha thinking I am a bot? [duplicate]

I am trying to get Rinkeby Ether on the above mentioned website and it keeps not giving me any. When I click "Give me Ether" it does not even show any popup to prove I'm a human (like, &...
user avatar
0 votes
0 answers
32 views

getBalance() returns huge value

I'm testing method for transfering tokens to another address: it("Should transfer all tokens to address1", async function () { await hardhatDonation.donate({ ...
user avatar
3 votes
2 answers
1k views

Network ropsten doesn't show in metamask

Why I can't change the network to Ropsten Test Network? It doesn't show up in pop up menu.
user avatar
1 vote
4 answers
113 views

How to inject a fake value while testing a contract?

I'm used to Java mocks, where I could access and modify private values. As we are on our local machine and own ethereum node, we may do the same. My problem is I want to modify a required address. ...
user avatar
1 vote
1 answer
1k views

How to run hardhat tests on a testnet?

I want to run my tests on testnet, mainly because I need to test chainlink VRF. How can I do that? this is my hardhat.config.js: require("@nomiclabs/hardhat-ethers"); require("@...
user avatar
  • 353
0 votes
2 answers
640 views

How to use changeEtherBalance from waffle-hardhat?

I want to check if the ether balance of an account decreased after the transaction using changeEtherBalance I tried to follow the waffle docs but couldn't do it either. await token.connect(...
user avatar
  • 353
0 votes
1 answer
584 views

Returning a uint256 array from contract, and parsing in test

I have an ERC721 contract that mints an NFT. I added a function that mints multiple NFTs in one call. I tried returning the token ids from that function, but I cannot write the test code to get them. ...
user avatar
1 vote
1 answer
453 views

How can I mock ERC20 in build-in truffle test suite?

I want to test my contract using truffle test which required a mock ERC20. I've found this example in Github and also this thread. const ERC20 = artifacts.require("ERC20"); I've tried but ...
user avatar
  • 135
2 votes
1 answer
219 views

How to mock out a signed transaction w/ Waffle Mocks?

When applying Waffle mock to simulate a contract method that must be explicity signed an error is thrown: Error: Contract with a Signer cannot override from (operation="overrides.from", code=...
user avatar
0 votes
1 answer
74 views

How to use bn-chai in a typescript test script?

I would like to use bn-chai plugin for chai in a test script written in typescript. I imported (the official documentation uses require) the dependencies and set chai according documentation: import { ...
user avatar
5 votes
0 answers
697 views

Hardhat: InvalidInputError: sender doesn't have enough funds to send tx

I am getting following error: InvalidInputError: sender doesn't have enough funds to send tx. The max upfront cost is: 1720878550726790368 and the sender's account only has: 47925025381294726 I am ...
user avatar
1 vote
3 answers
2k views

How to debug a solidity test

I am using ganache and truffle to write some tests in solidity (following the example in https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-solidity). I am getting the usual, not ...
user avatar
0 votes
0 answers
84 views

Initialise struct with nested mappings in a truffle test

I am writing a test following the following examples: https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-solidity In the test I need to define a struct located in the storage. I wrote ...
user avatar
1 vote
0 answers
21 views

Ropstens test net. How do I solve this?

The picture below shows the wallet status of the Ropstens test server. How long do I have to wait to resolve it? How do I solve this? Where should I ask for help? My wallet is not working.
user avatar
0 votes
2 answers
75 views

Remix says that I got undeclared variable in my test contract when trying to run it, when it is declared in the original contract. How to fix?

Basically I need to get the hash from the function in the original contract, and for that the function makeBet() requires some input. The function looks like this: pragma solidity >=0.8.0 <0.9.0;...
user avatar
  • 43
1 vote
3 answers
5k views

change transaction msg.value and msg.sender on hardhat test

I have a lottery kind of app for which users send money to a contract that at the time pays rewards. Simplified, the method I'm trying to test is something like this: struct Bet { address payable ...
user avatar
0 votes
1 answer
111 views

Should you use call() when you call solidity functions from Javascript tests

Let's say my solidity code is contract MetaCoin { uint256 public balance = 0; function getBalance() public view returns(uint) { return balance } } Let's say I want to call the getBalance ...
user avatar
3 votes
1 answer
812 views

Openzeppelin test helper with hardhat config and tests

I'm using hardhat and I added a task to manipulate time in the hardhat.config.js file which is working fine. require("@nomiclabs/hardhat-waffle"); require("@nomiclabs/hardhat-truffle5&...
user avatar
  • 2,526