0

My contract

pragma solidity ^0.8.13;

contract Escrow{
    address payable public dev;
    address public website;
    address public customer;
    uint public amount;

    constructor( address payable _dev, address _customer,uint _amount){
        dev = _dev;
        website = msg.sender;
        customer = _customer;
        amount = _amount;

    }

    function deposit() payable public{
        require(msg.sender == customer, "Only customer can add money");
        require(address(this).balance <= amount, "Money can not exceed given amount");
    }

    function sendMoney() public{
        dev.transfer(amount);
    }

}

Deployment script

const Escrow = artifacts.require("Escrow");

module.exports = function (deployer, network, accounts) {
  deployer.deploy(Escrow, accounts[1],accounts[2], 1000);
};

When I do manual testing on the remix website it's working fine. But when testing sendMoney function it's throwing error

const Escrow = artifacts.require("Escrow");

contract("Escrow", (accounts) => {
  let escrow = null;
  const [website, dev, customer] = accounts;
  before(async () => {
    escrow = await Escrow.deployed();
  }); 

  it("Check money send", async ()=>{
    try{
      const prevDevBalance = web3.utils.toBN(await web3.eth.getBalance(dev))
      await escrow.sendMoney({from:accounts[0]})
      const newDevBalance = web3.utils.toBN(await web3.eth.getBalance(dev))
      assert(true)
      return
    }catch(e){
      assert(false)
      console.log("ERRORR",e)
    }
  }) 
});

Sometimes tests are successful but 90% time throwing this issue.


  1) Contract: Escrow
       Check money send:
     Uncaught AssertionError: Unspecified AssertionError
      at checkError (test/index.js:7:5)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)



UnhandledRejections detected
Promise {
  <rejected> AssertionError: Unspecified AssertionError
      at checkError (test/index.js:7:5)
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    showDiff: false,
    actual: null,
    expected: undefined,
    uncaught: true
  }
} AssertionError: Unspecified AssertionError
    at checkError (test/index.js:7:5)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  showDiff: false,
  actual: null,
  expected: undefined,
  uncaught: true
}
2
  • Have u deposited ether to the contract first ?
    – Majd TL
    Commented May 26, 2022 at 7:16
  • It would be easier if we saw what's the error, place console.log("ERRORR",e) before the assert(false)
    – Kof
    Commented May 26, 2022 at 12:56

1 Answer 1

0

You don't seem to initialize the contract, its constructor expects 3 arguments address payable _dev, address _customer,uint _amount.

Use this to deploy -

  before(async () => {
    escrow = await Escrow.new(dev, customer, "1");
  }); 
3
  • If i use .deployed then it will take deployed contract. And in migrations I have provided arguments. What is diff in you above code? Also I need to deploy my contract as website. how can I do that ? Commented May 28, 2022 at 10:04
  • It passes params for the constructor, did you do that on your deployed contract?
    – Kof
    Commented May 28, 2022 at 17:57
  • added the deployment script. I guess issue is i am not passing value on init and checking contract balance in require statement is issue. Will ping you if this was the issue Commented May 28, 2022 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.