Questions tagged [testing]

questions regarding the testing during development of contracts and DApps

Filter by
Sorted by
Tagged with
0
votes
1answer
9 views

revert on `evm_increaseTime` when running test on mainnet fork

I am trying to run the test on mainnet fork using hardhat-deploy example template, particularly the for-test branch example. https://github.com/wighawag/template-ethereum-contracts/tree/examples/fork-...
0
votes
1answer
17 views

How to write tests for time based contracts?

I have a function that requires 7 days to pass from the time of an event (lockTime) before the rest of it will execute: function resetGame () public onlyOwner { require (block.timestamp >= ...
0
votes
2answers
18 views

How can i construct Unit testing for smart contract?

Because i need to test smart contracts functions deployed in ropsten function deposit(uint256 _amount) public { // Amount must be greater than zero require(_amount > 0, "amount ...
0
votes
1answer
41 views

Testing Token with Uniswap liquidity provisioning using hardhat

I'm attempting to fork Safemoon (or really NotSafeMoon), and use it as a vehicle to learn smart contract development. (I've got a substantial amount of what you might call "Web 2.0" dev ...
0
votes
0answers
40 views

How do I use BigNumber values in Hardhat tests?

I'm using Hardhat with TypeScript/Ethers/Chai. I can't find a way to test BigNumber values. For example, expect(someBigNumber).to.be.equal.to.(otherBigNumber) will (understandably) throw an error like ...
0
votes
1answer
30 views

How to fork the mainnet

I'm pretty new to Ethereum. I'm trying to write a simple dapp, which can deposit and withdrawal from aave. In order to communicate create the contract first I need to fork the mainnet. I'm not exactly ...
0
votes
1answer
31 views

How to solve “sender doesn't have enough funds to send tx. The upfront cost is: xxxxxxxxxxxxxxxx and the sender's account only has: 0”?

I found a similar answer for this question here, but I am using hardhat and ethers for my testing. I am just sending erc20 to my contract and here is my test file: it("Transferring Tokens to ...
1
vote
1answer
19 views

What's the difference between ethers.provider and ethers.network.provider in ethers.js?

I am using hardhat and ethers.js for testing and when I call WETHSigner = await ethers.provider.getSigner(WETHHolderAddress); it fails but this works: WETHSigner = await ethers.getSigner(...
0
votes
1answer
11 views

How do obtain wrapped btc and wrapped ada in a local test network or a live test network like ropsten?

In the local test network and ropsten test network, it's easy to obtain ethereum but I need other tokens in order to do testing. I'm not sure how to obtain those tokens for testing.
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
1answer
68 views

What is `signer.sendTransaction(…)` and its purpose in the Hardhat mainnet forking docs?

For unit testing purposes, I want to impersonate the DAI contract to transfer some DAI to a local wallet address in my local blockchain environment. I have followed the instructions on Hardhat's ...
0
votes
1answer
253 views

Invalid ENS name when running hardhat test

Am testing my smart contract using Hardhat, Waffle(beginner) and I can't understand why am getting Invalid ENS name error. 'Should only allow tokencreator to change token creator: AssertionError: ...
0
votes
2answers
27 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;...
0
votes
1answer
9 views

Is it possible to construct objects in javascript and pass it to Solidity?

Let's say I have these 2 contracts defined in the same solidity file. contract Coin { string public name; constructor(string _name) public { name = _name; } } contract MetaCoin { ...
0
votes
1answer
16 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 ...
0
votes
0answers
13 views

Solidity uint256 equivalence bug during integration tests

Only happens on about 20% of runs. (the numbers are random each run, but they always equal).
0
votes
1answer
14 views

Test require() clause in constructor

I am writing a test suite to ensure that parameters in my smart contract's constructor are being properly validated by a require() statement prior to any gas expenditures. I have been looking through ...
1
vote
1answer
82 views

Failing to decode tx's data

I'm trying to decode the data from a transaction on a smart contract test using the instructions from Ethers.js docs but I keep getting that the first argument (fragment) is invalid: Ethers.js ...
0
votes
1answer
45 views

How to use existing ERC20 tokens in local testnet?

I am running a local Hardhat network to test my contracts. I want my contract to eventually be able to swap existing ERC20 tokens, for example WETH/USDC on Uniswap. Is there a way to test this in my ...
0
votes
1answer
20 views

How do I force a Chainlink price oracle to return a diffrent price for an asset with Hardhat mainnet forking?

I'm working on a DeFi protocol and I would like to test liquidations with Hardhat mainnet forking. Plan is quite simple: Send enough ETH from my test account to the Binance wallet to pay for gas. ...
0
votes
0answers
33 views

Withdraw funds from contract

I made the following withdraw function in my smart contract: function withdraw() public onlyOwner { (bool success, ) = msg.sender.call{value: address(this).balance}(""); } I call ...
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) { ...
0
votes
0answers
19 views

Questions concerning the modification of an existing contract. Two liquidity pools, fee that can be taken out, testing on remix, buying the token

I am learning Solidity, and I am trying to modify an existing contract. But the questions I have I can ask independently from the contract. is there a possibility to have two liquidity pools? One as ...
0
votes
0answers
35 views

Hardhat not catching exception from external contracts on forknet

I am testing a function that involves a buying transaction on PancakeSwap. This involves a series of internal function calls which is not shown here for simplicity sake. here is my test snippet: ...
1
vote
1answer
91 views

Prefunding wallets in HardHat

I know that Hardhat automatically prefunds each default wallet with ETHs, however I have a few questions with regards to that. How does this prefunding work when I change the network (Say from ...
1
vote
1answer
85 views

Hardhat can't find the mint function

I'm using hardhat as a framework to develop my smartcontracts. So far it's been great, but im clueless as to why I can't call the mint function from my tests. Here's the error message: Token.connect(.....
0
votes
0answers
200 views

Modify block number when testing with Hardhat

I see that is it is possible to define the timestamp of the next block (see here) in this way: await network.provider.send("evm_setNextBlockTimestamp", [1625097600]); await network.provider....
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 ...
1
vote
1answer
41 views

OpenZeppelin test helper: expectEvent.inTransaction error

I'm trying to use OZ Test helpers to pass a test when a specific event is emitted. Here is the logic: I call function1 with a JS Promise. function1 calls function2 which emits an event. Parts of ...
0
votes
0answers
10 views

How do you test your contracts, and how long do you spend testing?

I want to improve how I test to increase my effectiveness and efficiency, so would like to hear from others. How do you test your smart contracts i.e. do you have a particular methodology for what ...
0
votes
0answers
10 views

How can I measure block processing time on a given Ethereum client?

I'm looking for a tool or library to measure block processing time on a given Ethereum client. My scenario would be to be able to compare block processing time to State size. The goal is to understand ...
2
votes
1answer
556 views

Metamask doesn't allow me to approve transactions

Metamask does'nt allow me to click on confirm when I wan't to approve a transaction. (i.e. the Confirm button is disabled and stays disabled whatever I do) Because "Confirm" is disabled I ...
0
votes
1answer
252 views

TypeError: Cannot read property 'providers' of undefined: Truffle & Web3

Here is the necessary part of the code, from where I keep receiving the following error: const { Web3 } = require("web3"); const web3 = new Web3(new Web3.providers.HttpProvider('http://...
1
vote
1answer
91 views

TDD Solidity: expect internal struct state

I'm a big fan of TDD/BDD so I figured hardhat and chai/waffle are a good start to learning smart contract development. I've run into an issue though where I'm wondering what best practice would be to ...
0
votes
1answer
262 views

How to unit test when a function depends on hardcoded deployed contract address?

I've been writing unit tests for a contract using Hardhat + Ethers + Typescript, let's call it ContractA. This ContractA has a hardcoded address of a deployed ERC20 token in it like this TokenA = '0x.....
1
vote
1answer
40 views

Changing contract property to public increases gas costs

I am following kind of an outdated tutorial and trying to adapt it to the more recent changes in Solidity and other packages. Following one of my changes, I am running into a problem that I can't find ...
0
votes
1answer
18 views

Testing the functions of an instance contract with truffle

I have contract A and contract B with the following structures: contract A { int x; function setX(){ x = _x; } } contract B { A[] contractInstances; function ...
0
votes
1answer
25 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 ...
1
vote
1answer
2k views

How to interact with the functions of my smart contract in Hardhat?

I am learning to program in Solidity and have followed a basic tutorial on creating a smart contract from a number counter. The tutorial was followed by using Remix and I was very clear about the ...
0
votes
1answer
108 views

Limit gas in brownie automated tests

I have create a brownie project with automated tests according to this documentation: https://vyper.readthedocs.io/en/stable/testing-contracts-brownie.html#writing-a-basic-test Here is an example: def ...
0
votes
1answer
30 views

error comparing numbers in smart contract (Big Number)

I am unable to understand when all do we need to convert numbers to bigNumbers for asserting to be equal. In some cases by mistake i missed to convert integer variables to bigNumber and they worked ...
1
vote
1answer
73 views

Perimeter of mocha, waffle and chai

Here is what i've understood (please tell me if i am wrong): Mocha (mochajs.org) is a testing framework Waffle (getwaffle.io) is another testing framework chai: This is not a framework, this is a ...
0
votes
1answer
2k views

Ethers.js testing: Giving hardhat generated accounts ETH

Deployment √ Should set the contract's address as owner (44ms) √ Should assign the totalSupply of credits to the creditsContract (114ms) Transactions 1) Should fail if sender ...
0
votes
0answers
12 views

toNumber in test.js

I am creating a test.js for my smart contract. I forgot to use "toNumber" while testing some uint variables to be equal in some cases and it executed without any error. So in what all cases ...
0
votes
0answers
80 views

Why is the allowance 10**8 inside the test but equal to zero in the smart contract?

I'm running this test: def test_mint(prf, exValue, web3): wBtcAddress = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" ABI = [{"constant":True,"inputs":[],"...
0
votes
0answers
18 views

dapp without test.js

We can test our smart contract in remix and can perform several workflow checks before putting the contract in the final sol file in the dapp project. This way we can ensure that everything is in ...
0
votes
1answer
71 views

Using openzeppelin-test-environment to test upgradeable contract

openzeppelin-test-environment is quite a new package, it doesn't tell how to initialize the upgradeable contract https://github.com/OpenZeppelin/openzeppelin-test-environment Just a basic example from ...
1
vote
0answers
69 views

Maian Tool Repository on Docker: How to store contract retrieved from etherscan.io and what is ‘test.sol’

I am in the MAIAN tool repository on docker. The link at : MAIAN Tool GitHub Link They provided details of how to execute the MAIAN tool from docker. I am in the MAIAN tool repository on docker. They ...
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
102 views

Feedback on Implementing Merkle Airdrop for Rug Pull Victims

Summary: Developed a smart contract that enables the GovernorDAO Community to un-rug the CBDAO Rug Pull victims by providing them with a Merkle Distribution Airdrop. Over 1/3 of an already-minted ...

1
2 3 4 5
8