Skip to content

Commit

Permalink
create tests for ERC20SimpleSwap and small changes to ERC20SimpleSwap…
Browse files Browse the repository at this point in the history
…/SimpleSwap
  • Loading branch information
Eknir committed Nov 7, 2019
1 parent b16dfab commit 3ad8005
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 187 deletions.
26 changes: 14 additions & 12 deletions contracts/ERC20SimpleSwap.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pragma solidity ^0.5.11;
import "./ISimpleSwap.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/math/Math.sol";
import "openzeppelin-solidity/contracts/cryptography/ECDSA.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";

/**
@title Chequebook contract without waivers
Expand All @@ -13,7 +12,7 @@ Furthermore, solvency can be guaranteed via hardDeposits
@dev as an issuer, no cheques should be send if the cumulative worth of a cheques send is above the cumulative worth of all deposits
as a beneficiary, we should always take into account the possibility that a cheque bounces (when no hardDeposits are assigned)
*/
contract ERC20SimpleSwap is ISimpleSwap {
contract ERC20SimpleSwap {
using SafeMath for uint;

event Deposit(address depositor, uint amount);
Expand Down Expand Up @@ -63,9 +62,13 @@ contract ERC20SimpleSwap is ISimpleSwap {
DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT = defaultHardDepositTimeoutDuration;
}

/// @return the balance of the chequebook
function balance() public view returns(uint) {
return token.balanceOf(address(this));
}
/// @return the part of the balance that is not covered by hard deposits
function liquidBalance() public view returns(uint) {
return token.balanceOf(address(this)).sub(totalHardDeposit);
return balance().sub(totalHardDeposit);
}

/// @return the part of the balance available for a specific beneficiary
Expand All @@ -82,7 +85,7 @@ contract ERC20SimpleSwap is ISimpleSwap {
*/
function _cashChequeInternal(
address beneficiary,
address payable recipient,
address recipient,
uint cumulativePayout,
uint callerPayout,
bytes memory issuerSig
Expand Down Expand Up @@ -140,7 +143,7 @@ contract ERC20SimpleSwap is ISimpleSwap {
*/
function cashCheque(
address beneficiary,
address payable recipient,
address recipient,
uint cumulativePayout,
bytes memory beneficiarySig,
uint256 callerPayout,
Expand All @@ -165,7 +168,7 @@ contract ERC20SimpleSwap is ISimpleSwap {
@param cumulativePayout amount requested to pay out
@param issuerSig issuer must have given explicit approval on the cumulativePayout to the beneficiary
*/
function cashChequeBeneficiary(address payable recipient, uint cumulativePayout, bytes memory issuerSig) public {
function cashChequeBeneficiary(address recipient, uint cumulativePayout, bytes memory issuerSig) public {
_cashChequeInternal(msg.sender, recipient, cumulativePayout, 0, issuerSig);
}

Expand Down Expand Up @@ -212,7 +215,7 @@ contract ERC20SimpleSwap is ISimpleSwap {
function increaseHardDeposit(address beneficiary, uint amount) public {
require(msg.sender == issuer, "SimpleSwap: not issuer");
/* ensure hard deposits don't exceed the global balance */
require(totalHardDeposit.add(amount) <= address(this).balance, "SimpleSwap: hard deposit cannot be more than balance");
require(totalHardDeposit.add(amount) <= balance(), "SimpleSwap: hard deposit cannot be more than balance");

HardDeposit storage hardDeposit = hardDeposits[beneficiary];
hardDeposit.amount = hardDeposit.amount.add(amount);
Expand Down Expand Up @@ -274,7 +277,6 @@ contract ERC20SimpleSwap is ISimpleSwap {
internal pure returns (bytes32) {
return keccak256(abi.encodePacked(swap, beneficiary, decreaseTimeout));
}

}


77 changes: 0 additions & 77 deletions contracts/ISimpleSwap.sol

This file was deleted.

14 changes: 9 additions & 5 deletions contracts/SimpleSwap.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pragma solidity ^0.5.11;
import "./ISimpleSwap.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/math/Math.sol";
import "openzeppelin-solidity/contracts/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";
import "@openzeppelin/contracts/cryptography/ECDSA.sol";

/**
@title Chequebook contract without waivers
Expand All @@ -12,7 +11,7 @@ Furthermore, solvency can be guaranteed via hardDeposits
@dev as an issuer, no cheques should be send if the cumulative worth of a cheques send is above the cumulative worth of all deposits
as a beneficiary, we should always take into account the possibility that a cheque bounces (when no hardDeposits are assigned)
*/
contract SimpleSwap is ISimpleSwap {
contract SimpleSwap {
using SafeMath for uint;

event Deposit(address depositor, uint amount);
Expand Down Expand Up @@ -62,6 +61,11 @@ contract SimpleSwap is ISimpleSwap {
}
}

/// @return the balance of the chequebook
function balance() public view returns(uint) {
return address(this).balance;
}

/// @return the part of the balance that is not covered by hard deposits
function liquidBalance() public view returns(uint) {
return address(this).balance.sub(totalHardDeposit);
Expand Down
Loading

0 comments on commit 3ad8005

Please # to comment.