make LiquidPledgingEscapable

This commit is contained in:
perissology 2017-12-05 11:58:20 -08:00
parent 49540b1eb7
commit 9cf0856e3d
11 changed files with 34 additions and 19 deletions

View File

@ -12,7 +12,7 @@
"no-with": true, "no-with": true,
"no-empty-blocks": true, "no-empty-blocks": true,
"no-unused-vars": true, "no-unused-vars": true,
"double-quotes": true, "quotes": true,
"blank-lines": true, "blank-lines": true,
"indentation": true, "indentation": true,
"whitespace": true, "whitespace": true,

View File

@ -7,7 +7,8 @@ pragma solidity ^0.4.11;
/// safety precaution, but once fully tested and optimized this contract will /// safety precaution, but once fully tested and optimized this contract will
/// be a safe place to store funds equipped with optional variable time delays /// be a safe place to store funds equipped with optional variable time delays
/// to allow for an optional escape hatch to be implemented /// to allow for an optional escape hatch to be implemented
import "../node_modules/giveth-common-contracts/contracts/Escapable.sol"; import "giveth-common-contracts/contracts/Escapable.sol";
/// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract /// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract
/// to confirm and cancel payments in the `LiquidPledging` contract. /// to confirm and cancel payments in the `LiquidPledging` contract.
@ -42,8 +43,9 @@ contract LPVault is Escapable {
// @dev An array that contains all the payments for this LPVault // @dev An array that contains all the payments for this LPVault
Payment[] public payments; Payment[] public payments;
function Vault(address _escapeHatchCaller, address _escapeHatchDestination) function LPVault(address _escapeHatchCaller, address _escapeHatchDestination)
Escapable(_escapeHatchCaller, _escapeHatchDestination) public { Escapable(_escapeHatchCaller, _escapeHatchDestination) public
{
} }
/// @dev `liquidPledging` is the only address that can call a function with /// @dev `liquidPledging` is the only address that can call a function with
@ -82,7 +84,9 @@ contract LPVault is Escapable {
function authorizePayment( function authorizePayment(
bytes32 _ref, bytes32 _ref,
address _dest, address _dest,
uint _amount ) public onlyLiquidPledging returns (uint) { uint _amount
) public onlyLiquidPledging returns (uint)
{
uint idPayment = payments.length; uint idPayment = payments.length;
payments.length ++; payments.length ++;
payments[idPayment].state = PaymentStatus.Pending; payments[idPayment].state = PaymentStatus.Pending;

View File

@ -37,7 +37,12 @@ contract LiquidPledging is LiquidPledgingBase {
/// @dev This constructor also calls the constructor /// @dev This constructor also calls the constructor
/// for `LiquidPledgingBase` /// for `LiquidPledgingBase`
/// @param _vault The vault where ETH backing this pledge is stored /// @param _vault The vault where ETH backing this pledge is stored
function LiquidPledging(address _vault) LiquidPledgingBase(_vault) { function LiquidPledging(
address _vault,
address _escapeHatchCaller,
address _escapeHatchDestination
) LiquidPledgingBase(_vault, _escapeHatchCaller, _escapeHatchDestination) {
} }
/// @notice This is how value enters into the system which creates pledges; /// @notice This is how value enters into the system which creates pledges;

View File

@ -18,7 +18,7 @@ pragma solidity ^0.4.11;
*/ */
import "./ILiquidPledgingPlugin.sol"; import "./ILiquidPledgingPlugin.sol";
import "../node_modules/giveth-common-contracts/contracts/Owned.sol"; import "giveth-common-contracts/contracts/Escapable.sol";
/// @dev `LPVault` serves as an interface to allow the `LiquidPledgingBase` /// @dev `LPVault` serves as an interface to allow the `LiquidPledgingBase`
/// contract to interface with a `LPVault` contract /// contract to interface with a `LPVault` contract
@ -30,7 +30,7 @@ contract LPVault {
/// @dev `LiquidPledgingBase` is the base level contract used to carry out /// @dev `LiquidPledgingBase` is the base level contract used to carry out
/// liquid pledging's most basic functions, mostly handling and searching the /// liquid pledging's most basic functions, mostly handling and searching the
/// data structures /// data structures
contract LiquidPledgingBase is Owned { contract LiquidPledgingBase is Escapable {
// Limits inserted to prevent large loops that could prevent canceling // Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20; uint constant MAX_DELEGATES = 20;
@ -97,7 +97,11 @@ contract LiquidPledgingBase is Owned {
/// @notice The Constructor creates `LiquidPledgingBase` on the blockchain /// @notice The Constructor creates `LiquidPledgingBase` on the blockchain
/// @param _vault The vault where the ETH backing the pledges is stored /// @param _vault The vault where the ETH backing the pledges is stored
function LiquidPledgingBase(address _vault) { function LiquidPledgingBase(
address _vault,
address _escapeHatchCaller,
address _escapeHatchDestination
) Escapable(_escapeHatchCaller, _escapeHatchDestination) public {
admins.length = 1; // we reserve the 0 admin admins.length = 1; // we reserve the 0 admin
pledges.length = 1; // we reserve the 0 pledge pledges.length = 1; // we reserve the 0 pledge
vault = LPVault(_vault); // Assigns the specified vault vault = LPVault(_vault); // Assigns the specified vault

View File

@ -29,7 +29,11 @@ contract LiquidPledgingMock is LiquidPledging {
/// @dev `LiquidPledgingMock` creates a standard `LiquidPledging` /// @dev `LiquidPledgingMock` creates a standard `LiquidPledging`
/// instance and sets the mocked time to the current blocktime. /// instance and sets the mocked time to the current blocktime.
/// @param _vault The vault where ETH backing this pledge is stored /// @param _vault The vault where ETH backing this pledge is stored
function LiquidPledgingMock(address _vault) LiquidPledging(_vault) { function LiquidPledgingMock(
address _vault,
address _escapeHatchCaller,
address _escapeHatchDestination
) LiquidPledging(_vault, _escapeHatchCaller, _escapeHatchDestination) {
mock_time = now; mock_time = now;
} }

View File

@ -55,7 +55,7 @@ describe('LiquidPledging plugins test', function () {
it('Should deploy LiquidPledging contract', async function() { it('Should deploy LiquidPledging contract', async function() {
vault = await Vault.new(web3, accounts[0], accounts[1]); vault = await Vault.new(web3, accounts[0], accounts[1]);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 6500000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, accounts[0], accounts[1], { gas: 6500000 });
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
}); });

View File

@ -52,7 +52,7 @@ describe('LiquidPledging cancelPledge normal scenario', function () {
it('Should deploy LiquidPledging contract', async () => { it('Should deploy LiquidPledging contract', async () => {
vault = await Vault.new(web3, accounts[0], accounts[1]); vault = await Vault.new(web3, accounts[0], accounts[1]);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, accounts[0], accounts[1], { gas: 5800000 });
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
}); });

View File

@ -58,7 +58,7 @@ describe('DelegationChain test', function () {
it('Should deploy LiquidPledging contract', async () => { it('Should deploy LiquidPledging contract', async () => {
vault = await Vault.new(web3, accounts[0], accounts[1]); vault = await Vault.new(web3, accounts[0], accounts[1]);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, accounts[0], accounts[1], { gas: 5800000 });
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
}); });

View File

@ -63,7 +63,7 @@ describe('LiquidPledging test', function () {
it('Should deploy LiquidPledging contract', async () => { it('Should deploy LiquidPledging contract', async () => {
vault = await LPVault.new(web3, accounts[0], accounts[1]); vault = await LPVault.new(web3, accounts[0], accounts[1]);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, accounts[0], accounts[1], { gas: 5800000 });
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
}); });

View File

@ -58,7 +58,7 @@ describe('NormalizePledge test', function () {
it('Should deploy LiquidPledging contract', async () => { it('Should deploy LiquidPledging contract', async () => {
vault = await Vault.new(web3, accounts[0], accounts[1]); vault = await Vault.new(web3, accounts[0], accounts[1]);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5800000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, accounts[0], accounts[1], { gas: 5800000 });
await vault.setLiquidPledging(liquidPledging.$address); await vault.setLiquidPledging(liquidPledging.$address);
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
}); });

View File

@ -8,7 +8,7 @@ const assertFail = require('./helpers/assertFail');
const LiquidPledging = liquidpledging.LiquidPledgingMock; const LiquidPledging = liquidpledging.LiquidPledgingMock;
const LiquidPledgingState = liquidpledging.LiquidPledgingState; const LiquidPledgingState = liquidpledging.LiquidPledgingState;
const Vault = liquidpledging.Vault; const Vault = liquidpledging.LPVault;
const assert = chai.assert; const assert = chai.assert;
describe('Vault test', function () { describe('Vault test', function () {
@ -51,7 +51,7 @@ describe('Vault test', function () {
it('Should deploy Vault contract', async function () { it('Should deploy Vault contract', async function () {
vault = await Vault.new(web3, escapeHatchCaller, escapeHatchDestination, { from: vaultOwner }); vault = await Vault.new(web3, escapeHatchCaller, escapeHatchDestination, { from: vaultOwner });
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 6500000 }); liquidPledging = await LiquidPledging.new(web3, vault.$address, escapeHatchCaller, escapeHatchDestination, { gas: 6500000 });
await vault.setLiquidPledging(liquidPledging.$address, { from: vaultOwner }); await vault.setLiquidPledging(liquidPledging.$address, { from: vaultOwner });
liquidPledgingState = new LiquidPledgingState(liquidPledging); liquidPledgingState = new LiquidPledgingState(liquidPledging);
@ -94,7 +94,5 @@ describe('Vault test', function () {
assert.equal(expected, postBalance); assert.equal(expected, postBalance);
}); });
it('should')
}); });