artifacts.require('./RefundEscrow');

I’m trying to call the below contract in the test file:

const RefundEscrow = artifacts.require('./RefundEscrow');

But I get the following error:

Error: Could not find artifacts for ./RefundEscrow from any sources

Noting that the RefundEscrow.sol file is exist in @OpenZeppelin\contracts\payment\escrow

1 Like

I think it should be

const RefundEscrow = artifacts.require('RefundEscrow');

If you have a contract RefundEscrow

2 Likes

I have tried this, but I get the same error, and yes have a contract RefundEscrow

1 Like

A little weird, how about truffle compile --force and then run this script?

1 Like

Still not working, I have the same error

Can you share the code of your contract?

1 Like
pragma solidity >=0.5.1;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/WhitelistCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/distribution/RefundableCrowdsale.sol";

contract PFBTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale, WhitelistCrowdsale, RefundableCrowdsale {

	// Track investor contributions
	uint256 public investorMinCap = 10000000000000000; // 0.01 ether
	uint256 public investorHardCap = 350000000000000000000; // 350 ether
	mapping(address => uint256) public contributions;

constructor(
	uint256 _rate,
	    address payable _wallet,
	    ERC20 _token,
	    uint256 _cap,
	uint256 _goal
)
	Crowdsale(_rate, _wallet, _token)
	CappedCrowdsale(_cap)
	RefundableCrowdsale(_goal)
	public
{
	require(_goal <= _cap);
}

/**
  * @dev Returns the amount contributed so far by a sepecific user.
  * @param _beneficiary Address of contributor
  * @return User contribution so far
  */
  function getUserContribution(address _beneficiary)
public view returns (uint256)
  {
return contributions[_beneficiary];
  }

/**
  * @dev Extend parent behavior requiring purchase to respect investor min/max funding cap.
  * @param _beneficiary Token purchaser
  * @param _weiAmount Amount of wei contributed
  */
  function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
  )
internal view
  {
super._preValidatePurchase(_beneficiary, _weiAmount);
uint256 _existingContribution = contributions[_beneficiary];
uint256 _newContribution = _existingContribution.add(_weiAmount);
require(_newContribution <= investorHardCap, "The maximum investment amount is: 350 ether");
require(_newContribution >= investorMinCap, "The minimum investment amount is: 0.01 ether");
  }

  /**
 * @dev Extend parent behavior to update beneficiary contributions.
 * @param beneficiary Token purchaser
 * @param weiAmount Amount of wei contributed
 */
function _updatePurchasingState(
	address beneficiary,
	uint256 weiAmount
  	)
  		internal
  	{
    super._updatePurchasingState(beneficiary, weiAmount);
    contributions[beneficiary] = contributions[beneficiary].add(weiAmount);
}
}

I’m having the same issue:

‘Error: Could not find artifacts for .\RefundEscrow from any sources’

I’ve also tried removing the ‘./’, prefixing with ‘payments/’, etc.

Is there any resolution to this?

Note, the require statement is in a test.js file in my project.

Hi: welcome! :wave:

So what does your test file look like?

And what does your test file look like?

I’d like to call out my unfamiliarity with the tech stack. The code is adapted from a tutorial from late 2018, back when the package was ‘openzeppelin-solidity’, and RefundableCrowdsale used a ‘RefundVault’. It looks like openzeppelin has evolved a bit since then. I am attempting to do the tutorial with more updated packages. The below snippet is from the top section of the test file:

import ether from './helpers/ether'
import EVMRevert from './helpers/EVMRevert';

const { latestTime } = require('./helpers/latestTime');
const { increaseTimeTo, duration } = require('./helpers/increaseTime');
const BN = web3.utils.BN;

require('chai')
  .use(require('chai-bn')(BN))
  .use(require('chai-as-promised'))
  .should();

const MyToken = artifacts.require('MyToken');
const MyTokenCrowdsale = artifacts.require('MyTokenCrowdsale');
const RefundEscrow = artifacts.require('./RefundEscrow');

contract('MyTokenCrowdsale', function([_, wallet, investor1, investor2]) {

How about change it to

const RefundEscrow = artifacts.require('RefundEscrow');

Tried that. It didn’t work.

@Ahmed_Awadallah @broadbear
Hi, I just had a test at my local environment, maybe you can have a look, all is good in my side.
Code is at here:

Re-visiting this. I am now using a version of openzeppelin that uses RefundVault and was having the same issue. I looked in the build/contracts folder where the abis are stored after the contracts are compiled and noticed there was no 'RefundVault.json' file. I also noticed there were some junk contracts in the directory. I deleted all the json files in the build/contracts folder, re-compiled the contracts, and the RefundVault.json file appeared.

You'll notice that the const RefundVault = artifacts.require('./RefundVault'); statement refers to a file in the current directory (with './'), not under the utils directory found in the path to the RefundVault.sol source file. This was a clue as to why it was not being found. The mocha tests must reference the abis in the build/contracts folder directly (which makes sense), which flattens the directory structure as all relevant abis are found together in the same directory.