Questions tagged [testing]

questions regarding the testing during development of contracts and DApps

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

Truffle - Testing EIP712 using Web3js

I've been studying EIP712 and tried to implement some testing using truffle and Web3js. However, I noticed that web3.eth.accounts.sign() is compliant with EIP191, therefore I cannot retrieve the ...
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: ...
1
vote
0answers
13 views

In brownie tests how to use interfaces defined in packages

In brownie tests how to use third party interfaces defined in brownie packages? For example how do I use @openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol from OpenZeppelin ...
0
votes
1answer
38 views

Testing arguments of contract events with hardhat + chai

I'm currently using chai with hardhat and ethereum-waffle to test my smart contracts: const chai = require('chai') const hre = require('hardhat') const { solidity } = require('ethereum-waffle') chai....
0
votes
1answer
23 views

ERC20 token, override functions but state variable do not update as expected

I am trying to implement and test an ERC20 token by inheriting from ERC20.sol from OpenZeppelin. I want most of the functions to be by default from OpenZeppelin but I also want to overrride some of ...
0
votes
1answer
16 views

How to test clone contract functions?

I have a clonable contract which I'm passing to the clone factory contract and I'm trying to access the functions inside it but for some reason only the view functions work. this.nft = await NFT....
2
votes
2answers
60 views

Testing an event with a timestamp arg

I'm trying to write a test using waffle, but I'm not sure how to assert that a timestamp is correct in an emitted event. My event looks like this: event BeginJourney ( uint256 indexed departFrom, ...
1
vote
1answer
93 views

Testing for emitted events in Hardhat

I have a Solidity contract that inherits from ERC721PresetMinterPauserAutoId I want to write a test that verifies that a Transfer event has been emitted by the contract after the public mint(to) ...
0
votes
1answer
39 views

How to test if contract is receiving ETH

I'm desperately trying to find an answer as to how I can accurately test my smart contract balances, as not only can I not get the test to return the correct balance number, but I also am not seeing ...
0
votes
0answers
11 views

How to test in local, a contract if call an AMM contract?

I'm trying to test a smart contract but i have inside of my contract a call to PancakeSwap and i would like to test it, but i dont find what is the good way to do it: i have to mock router´s contract?...
0
votes
0answers
7 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 { ...
0
votes
0answers
84 views

Locally test Chainlink VRF call from another contract in Waffle/Hardhat

Locally testing Chainlinks VRF While trying to locally test a contract that calls a Chainlink VRF contract, I'm experiencing some difficulties in setting up the contract balances. I have a ...
0
votes
1answer
23 views

How to create a signer object from an address in ethers?

I have a list of addresses, and I would like to use them to test my contract in my hardhat ethers project. Normally I get a list of addresses like this: [a, b, c] = await ethers.getSigners() but what ...
0
votes
1answer
66 views

Truffle test in solidity with sending value

I have a simple contract with public function, that can receive value and do something based on that value: pragma solidity >= 0.8.0 < 0.9.0; contract ContractA { uint public boughtItems = ...
0
votes
1answer
47 views

Non transparent (forward) Proxy in Solidity

For testing/mocking purposes, I need to call a contract (A) from another contract (B) that just forwards the calls to (A). The calls need to be forwarded, not delegated. And I don't want to rewrite ...
0
votes
1answer
131 views

Hardhat writing tests for contract that calls another contract

Basically I need to use DAI stablecoin in my contract. I want to test it out so I have copied the DAI smart contract code and deployed it on my localhost. Everything works fine, but I can't write ...
0
votes
1answer
17 views

Truffle not able to run two files at the same time

I have two files in my test folder, when I run truffle test I get results for the first file but by the time it reaches to the second one ganache fails and I get the error below. I have tried placing ...
0
votes
1answer
12 views

Unit testing does not fail when I add 1 to the variables to be equated to

Just started with unit testing after creating my token, but the test cases are passing even if I add a number in the equals bracket. In test one, if I change to expect(await instance.balanceOf(...
0
votes
0answers
35 views

Solidity Unit tests won't pass on tutorial

I'm learning solidity and going through the tutorial at: https://ethereum-blockchain-developer.com/060-tokenization/08-unit-test-crowdsale/ The tests won't run for me and I'm clueless of what is ...
1
vote
1answer
18 views

Reference already-deployed contracts in testing-suite

when I run my deploy script in console, ContractContainer has the newly deployed contract-address. But when I try to reference that in tests, ContractContainer seems to be empty. What would be the ...
0
votes
1answer
60 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-...
1
vote
1answer
77 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
20 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
496 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 ...
2
votes
0answers
700 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
97 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
498 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
58 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
26 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
30 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
1answer
684 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
1k 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
30 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
14 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
18 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
15 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 ...
2
votes
1answer
180 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
132 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
38 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. ...
1
vote
0answers
42 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
93 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
22 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
67 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
139 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
234 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
637 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
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 ...
1
vote
1answer
79 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
11 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 ...

1
2 3 4 5
8