Questions tagged [testing]

questions regarding the testing during development of contracts and DApps

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

How can I call contract which created from another contract (In TESTING)?

Hello guys now Im testing my contract, but I dont know how to call contract which created from another contract, If someone did it please help) Create I mean like following code. function ...
0
votes
1answer
13 views

reverted with reason string 'Dai/insufficient-allowance' Testing

I am trying to test a simple function transferring Dai balance. test --> const [owner] = await ethers.getSigners(); const amount = await _hardhatPresaleERC20.calculateAmountTokensPurchased(1); ...
0
votes
0answers
11 views

Fast forwarding time in hardhat testing?

My contract is calling a method on a different contract to track how the response changes. I am unit testing with a forking mainnet network in hardhat, which allows me to interact with that other ...
0
votes
0answers
14 views

When running test unable to locat variable

the Code executes properly, although when I attempt to run a test it fails. It appears to me as if, when the test calls the deploy function which calls should call Lottery.sol contract and run ...
0
votes
0answers
9 views

Getting "Provider not found" while testing my contract with waffle

I am testing my contract using Waffle and I am following the documentation provided, using const provider = new MockProvider(); to get a provider for testing. An error was raised in expect().catch() ...
0
votes
1answer
37 views

Using Fork on Hardhat in testing

I am getting an error using a hardhat fork for testing. I run the forked node with "npx hardhat node --fork https://eth-mainnet.alchemyapi.io/v2/key --fork-block-number 13997235" I am able ...
0
votes
0answers
11 views

How to parse event logs (ERC-20 Transfer) from trace_call

I'm trying to get the event logs of a transaction (simulating transaction without actually adding it to blockchain). From trace_call, I am able to get vmTrace and a sample entry looks like this { &...
1
vote
0answers
18 views

While writing a test using dapptools, how do I send a transaction as a specific wallet address?

I'm playing around with dapptools: dapp And I want to write a test that checks the gas for OpenZeppelin's ERC721 implementation of the transferFrom(..) function. Here's my test: // SPDX-License-...
0
votes
1answer
25 views

Simulating a transaction's state change without writing to the blockchain

I'm trying to simulate a transaction to observe the state change and events that will be emitted, before sending the transaction to the blockchain. I'm interested in all the internal calls and state ...
0
votes
2answers
17 views

How to create your own Mock contract if one does not exist

Is there a guide on how to create your own Mock contracts in order to properly test smart contracts on local network? And how to conclude if one corresponds to the idea, and meets the requirements of ...
1
vote
1answer
18 views

Why doesn't Truffle's testing framework automatically retrieve fresh values of public state variables after every interaction with the contract?

I have the following simple smart contract defined: contract LoanApplication { struct Applicant { bytes32 ssn; bool hasApplied; } struct Loan { string loanID; uint ...
1
vote
1answer
62 views

how to hardhat test against a mainnet fork?

I'm using hardhat to fork the polygon mainnet by - npx hardhat node --fork <ALCHEMY RPC ENDPOINT> now i want to test on this local network. what is the command? npx hardhat test is not working.
0
votes
1answer
39 views

How to test sending eth to function using ethers.js?

I'm net to eth dev and trying to test sending eth while assigning a value to betOnTeam function: function betOnTeam(uint8 _team) public payable { // assign usre to _team and add betting value to ...
1
vote
1answer
27 views

Error: Could not find artifacts for contract

I'm new to ethereum development and trying to test SimpleStorage contract using truffle: I created file structure using turffle init and here is the files sturctur: ~/Desktop/truffle-test$ tree . . ├──...
0
votes
3answers
37 views

Uncaught Error: Callback was already called in mocha

Following an aging tutorial, I'm trying to learn how to test a smart contract: const assert = require('assert'); const ganache = require('ganache-cli'); const Web3 = require('web3'); const web3 = ...
1
vote
0answers
84 views

Hardhat testing on testnet (Rinkeby)

I want to do some final tests on a smart contract that has been deployed on the Rinkeby testnet. I am trying to run the below script (saved in my hardhat test folder) with hardhat but get the ...
0
votes
1answer
45 views

How to increase block.number in a truffle solidity test?

Is there any way to increase the block.number (e.g. mine a block) in a solidity based truffle test? I am able to do this just fine with a javascript based test by making an RPC call to the evm, but I ...
0
votes
1answer
45 views

Ethers.js equivalent for web3.eth.getStorageAt?

I want to check a private state variable with ethers.js. What is the equivalent for web3.eth.getStorageAt ?
0
votes
1answer
102 views

Key Error: 'eth_usd_price_feed' during brownie test

from brownie import Lottery, accounts, config, network from web3 import Web3 def test_get_entrance_fee(): account = accounts[0] lottery = Lottery.deploy( config["networks"][...
0
votes
2answers
866 views

cannot estimate gas; transaction may fail or may require manual gas limit

I have an ERC721 contract on rinkeby and need to test the mint function, but sometimes I receive the fallowing error: Error: cannot estimate gas; transaction may fail or may require manual gas limit .....
0
votes
1answer
71 views

Smart Contract Testing - ethereum-waffle expect function

Can someone please explain the significance of the location of the "await" keyword in the "expect" function from the waffle testing framework? for example: this passes (assume its ...
0
votes
0answers
8 views

How to catch the revert error in javascript mocha for testing solidity contracts [duplicate]

I struggled to find a nice solution to my question and thought of sharing it here so that others could benefit and others may have better suggestions. I have a solidity code where I have a function ...
0
votes
0answers
14 views

Unable to simulate openingTime for a TimedCrowdsale while testing

I'm writing the tests for a TimedCrowdsale smart contract and I'm not being able to simulate the openingTime. I'm doing this: it('should accept payments after start', async function () { await ...
0
votes
2answers
201 views

How to test Uniswap contracts locally?

So far I developed smart contracts in Solidity using Ganache. I didn't have to use Uniswap in any way. Now I'd like to use Uniswap to put some of my ERC-20 token as liquidity. I started reading the ...
1
vote
0answers
14 views

Keep track of staking award token

I'm building a smart contract where users can stake the native token and earn the same token as a reward. For example, users stake dai and earn back dai as a reward as well. I have made almost most of ...
0
votes
2answers
89 views

Error: Private key does not satisfy the curve requirements (ie. it is invalid)

I have a project working fine on truffle but when migrating to Kovan network, Getting the issue "Error: Private key does not satisfy the curve requirements (ie. it is invalid)" project is an ...
9
votes
2answers
1k views

Run a single hardhat test

I have a test file in hardhat like so: const { expect } = require("chai"); describe("contract tests", function () { it("does function one", async function () { ...
0
votes
0answers
28 views

solidity struct unit test

I think I am not the only one who has this problem. I just want to get the names of the variables inside a struct along with typing them. I have a file that shows the structure of the item. But I do ...
1
vote
1answer
1k views

Where to find and how to get Kovan USDC testnet tokens

I need USDC Kovan testnet tokens transffered to this address 0x2E9b971e336C825BC41b9FE87376E74f0B3345FE for testing purposes. Token contract for this token is https://kovan.etherscan.io/token/...
0
votes
1answer
19 views

Array in contract is pre-filled with random accounts

Hi all I have a problem with my contract, have a look I use a players array to save every account that calls the enter function, the enter function is the only function that pushes accounts into the ...
0
votes
0answers
91 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
23 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: ...
2
votes
0answers
47 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
600 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
105 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
38 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....
3
votes
2answers
159 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
1k 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
174 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
42 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
1answer
26 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
263 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
2answers
189 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
237 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
160 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
853 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
27 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
14 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
80 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
27 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 ...

1
2 3 4 5
9