Skip to content

Instantly share code, notes, and snippets.

@mujuni88
Created February 26, 2022 22:39
Show Gist options
  • Save mujuni88/ec1c4464ee7196ab0f8ef2d29269cdb1 to your computer and use it in GitHub Desktop.
Save mujuni88/ec1c4464ee7196ab0f8ef2d29269cdb1 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// 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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment