// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; import "remix_tests.sol"; import "remix_accounts.sol"; import "../contracts/EscrowAgent.sol"; contract EscrowAgentTest is EscrowAgent { address owner; address receiver; address acc2; function beforeEach() public { owner = TestsAccounts.getAccount(0); receiver = TestsAccounts.getAccount(1); acc2 = TestsAccounts.getAccount(2); } /// #sender: account-0 function testIfAgentsAccountsIsTheSameAsAssignedAccount() public { Assert.equal(agent, owner, "Agent is not the same as owner"); } /// #sender: account-1 /// #value: 100000000000000000 function testShouldFailIfDepositAsNotOwner() public payable { deposit(receiver); console.log("Balance %d", address(this).balance); Assert.ok(address(this).balance == msg.value, "Balance should be greater than 0"); } /// #sender: account-0 /// #value: 100000000000000000 function testShouldPassIfDepositAsOwner() public payable { deposit(receiver); console.log("Balance %d", address(this).balance); Assert.ok(address(this).balance == msg.value, "Balance should be greater than 0"); } /// #sender: account-0 /// #value: 100000000000000000 function testShouldPassIfDepositToAnotherReceiverAsOwner() public payable { deposit(acc2); Assert.ok(address(this).balance == msg.value * 2, "Balance should be greater than 0"); } /// #sender: account-0 /// #value: 100000000000000000 function testShouldFailWhenWithdrawIsCalledBeforeServiceIsCompleted() public { uint balance = 0.2 ether; Assert.ok(address(this).balance == balance, "Account balance should be 0.2 ETH"); withdraw(payable(receiver)); Assert.ok(address(this).balance == balance / 2, "Account balance should be 0.1 ETH"); } /// #sender: account-0 /// #value: 100000000000000000 function testShouldPassWhenWithdrawAfterServiceIsCompleted() public { completed(receiver); uint balance = 0.2 ether; Assert.ok(address(this).balance == balance, "Account balance should be 0.2 ETH"); withdraw(payable(receiver)); Assert.ok(address(this).balance == balance / 2, "Account balance should be 0.1 ETH"); } /// #sender: account-0 /// #value: 100000000000000000 function testShouldPassIfAcc2WithdrawsFunds() public { completed(acc2); uint balance = 0.1 ether; Assert.ok(address(this).balance == balance, "Account balance should be 0.2 ETH"); withdraw(payable(acc2)); Assert.ok(address(this).balance == 0, "Account balance should be 0.1 ETH"); } }