Donor to Giver refactor
This commit is contained in:
parent
75bb05769b
commit
e305229311
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -46,12 +46,12 @@ contract Vault {
|
|||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
// 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_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum NoteManagerType { Giver, Delegate, Project }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
|
@ -59,7 +59,7 @@ contract LiquidPledgingBase {
|
|||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
|
@ -111,14 +111,14 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
idGiver = uint64(managers.length);
|
||||
|
||||
managers.push(NoteManager(
|
||||
NoteManagerType.Donor,
|
||||
NoteManagerType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -126,28 +126,28 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DonorAdded(idDonor);
|
||||
GiverAdded(idGiver);
|
||||
}
|
||||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
event GiverAdded(uint64 indexed idGiver);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
///@notice Changes the address, name or commitTime associated with a specific giver
|
||||
function updateGiver(
|
||||
uint64 idGiver,
|
||||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
DonorUpdated(idDonor);
|
||||
NoteManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == NoteManagerType.Giver);//Must be a Giver
|
||||
require(giver.addr == msg.sender);//current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
giver.commitTime = newCommitTime;
|
||||
GiverUpdated(idGiver);
|
||||
}
|
||||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
event GiverUpdated(uint64 indexed idGiver);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
@ -274,7 +274,7 @@ contract LiquidPledgingBase {
|
|||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
|
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
|
|||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -373,7 +373,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
function isProjectCanceled(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -383,7 +383,7 @@ contract LiquidPledgingBase {
|
|||
function isProjectCanceled2(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
return false;
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -396,7 +396,7 @@ contract LiquidPledgingBase {
|
|||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
NoteManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == NoteManagerType.Donor) return idNote;
|
||||
if (manager.managerType == NoteManagerType.Giver) return idNote;
|
||||
|
||||
assert(manager.managerType == NoteManagerType.Project);
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -46,12 +46,12 @@ contract Vault {
|
|||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
// 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_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum NoteManagerType { Giver, Delegate, Project }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
|
@ -59,7 +59,7 @@ contract LiquidPledgingBase {
|
|||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
|
@ -111,14 +111,14 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
idGiver = uint64(managers.length);
|
||||
|
||||
managers.push(NoteManager(
|
||||
NoteManagerType.Donor,
|
||||
NoteManagerType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -126,28 +126,28 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DonorAdded(idDonor);
|
||||
GiverAdded(idGiver);
|
||||
}
|
||||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
event GiverAdded(uint64 indexed idGiver);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
///@notice Changes the address, name or commitTime associated with a specific giver
|
||||
function updateGiver(
|
||||
uint64 idGiver,
|
||||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
DonorUpdated(idDonor);
|
||||
NoteManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == NoteManagerType.Giver);//Must be a Giver
|
||||
require(giver.addr == msg.sender);//current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
giver.commitTime = newCommitTime;
|
||||
GiverUpdated(idGiver);
|
||||
}
|
||||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
event GiverUpdated(uint64 indexed idGiver);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
@ -274,7 +274,7 @@ contract LiquidPledgingBase {
|
|||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
|
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
|
|||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -373,7 +373,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
function isProjectCanceled(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -383,7 +383,7 @@ contract LiquidPledgingBase {
|
|||
function isProjectCanceled2(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
return false;
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -396,7 +396,7 @@ contract LiquidPledgingBase {
|
|||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
NoteManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == NoteManagerType.Donor) return idNote;
|
||||
if (manager.managerType == NoteManagerType.Giver) return idNote;
|
||||
|
||||
assert(manager.managerType == NoteManagerType.Project);
|
||||
|
||||
|
@ -431,20 +431,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// the token of value goes into the vault and the amount in the pledge
|
||||
/// relevant to this Giver without delegates is increased, and a normal
|
||||
/// transfer is done to the idReceiver
|
||||
/// @param idDonor Identifier of the donor thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same donor, another
|
||||
/// donor, a delegate or a project
|
||||
/// @param idGiver Identifier of the giver thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same giver, another
|
||||
/// giver, a delegate or a project
|
||||
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||
if (idGiver == 0) {
|
||||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
NoteManager storage sender = findManager(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
|
||||
require(sender.managerType == NoteManagerType.Donor);
|
||||
require(sender.managerType == NoteManagerType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -452,7 +452,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
vault.transfer(amount); // transfers the baseToken to the Vault
|
||||
uint64 idNote = findNote(
|
||||
idDonor,
|
||||
idGiver,
|
||||
new uint64[](0), //what is new?
|
||||
0,
|
||||
0,
|
||||
|
@ -465,16 +465,16 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
Transfer(0, idNote, amount);
|
||||
|
||||
transfer(idDonor, idNote, amount, idReceiver);
|
||||
transfer(idGiver, idNote, amount, idReceiver);
|
||||
}
|
||||
|
||||
|
||||
/// @notice Moves value between notes
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transferring
|
||||
/// @param idSender ID of the giver, delegate or project manager that is transferring
|
||||
/// the funds from Note to Note. This manager must have permissions to move the value
|
||||
/// @param idNote Id of the note that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a donor sending to a donor or
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
/// a delegate, a delegate to another delegate or a project to precommit it to that project
|
||||
function transfer(uint64 idSender, uint64 idNote, uint amount, uint64 idReceiver) {
|
||||
|
||||
|
@ -489,8 +489,8 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
transferOwnershipToDonor(idNote, amount, idReceiver);
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
transferOwnershipToGiver(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Project) {
|
||||
transferOwnershipToProject(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Delegate) {
|
||||
|
@ -505,9 +505,9 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
uint senderDIdx = getDelegateIdx(n, idSender);
|
||||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another donor
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
// Only accept to change to the original donor to remove all delegates
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idNote, amount, n.delegationChain.length);
|
||||
return;
|
||||
|
@ -553,7 +553,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the donors to avoid committing the donation or by project manager to use
|
||||
/// by the givers to avoid committing the donation or by project manager to use
|
||||
/// the Ether.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -730,7 +730,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
doTransfer(idNote, toNote, amount);
|
||||
}
|
||||
|
||||
function transferOwnershipToDonor(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
function transferOwnershipToGiver(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
uint64 toNote = findNote(
|
||||
idReceiver,
|
||||
new uint64[](0),
|
||||
|
|
|
@ -46,12 +46,12 @@ contract Vault {
|
|||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
// 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_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum NoteManagerType { Giver, Delegate, Project }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
|
@ -59,7 +59,7 @@ contract LiquidPledgingBase {
|
|||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
|
@ -111,14 +111,14 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
idGiver = uint64(managers.length);
|
||||
|
||||
managers.push(NoteManager(
|
||||
NoteManagerType.Donor,
|
||||
NoteManagerType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -126,28 +126,28 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DonorAdded(idDonor);
|
||||
GiverAdded(idGiver);
|
||||
}
|
||||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
event GiverAdded(uint64 indexed idGiver);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
///@notice Changes the address, name or commitTime associated with a specific giver
|
||||
function updateGiver(
|
||||
uint64 idGiver,
|
||||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
DonorUpdated(idDonor);
|
||||
NoteManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == NoteManagerType.Giver);//Must be a Giver
|
||||
require(giver.addr == msg.sender);//current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
giver.commitTime = newCommitTime;
|
||||
GiverUpdated(idGiver);
|
||||
}
|
||||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
event GiverUpdated(uint64 indexed idGiver);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
@ -274,7 +274,7 @@ contract LiquidPledgingBase {
|
|||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
|
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
|
|||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -373,7 +373,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
function isProjectCanceled(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -383,7 +383,7 @@ contract LiquidPledgingBase {
|
|||
function isProjectCanceled2(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
return false;
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -396,7 +396,7 @@ contract LiquidPledgingBase {
|
|||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
NoteManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == NoteManagerType.Donor) return idNote;
|
||||
if (manager.managerType == NoteManagerType.Giver) return idNote;
|
||||
|
||||
assert(manager.managerType == NoteManagerType.Project);
|
||||
|
||||
|
@ -431,20 +431,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// the token of value goes into the vault and the amount in the pledge
|
||||
/// relevant to this Giver without delegates is increased, and a normal
|
||||
/// transfer is done to the idReceiver
|
||||
/// @param idDonor Identifier of the donor thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same donor, another
|
||||
/// donor, a delegate or a project
|
||||
/// @param idGiver Identifier of the giver thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same giver, another
|
||||
/// giver, a delegate or a project
|
||||
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||
if (idGiver == 0) {
|
||||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
NoteManager storage sender = findManager(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
|
||||
require(sender.managerType == NoteManagerType.Donor);
|
||||
require(sender.managerType == NoteManagerType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -452,7 +452,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
vault.transfer(amount); // transfers the baseToken to the Vault
|
||||
uint64 idNote = findNote(
|
||||
idDonor,
|
||||
idGiver,
|
||||
new uint64[](0), //what is new?
|
||||
0,
|
||||
0,
|
||||
|
@ -465,16 +465,16 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
Transfer(0, idNote, amount);
|
||||
|
||||
transfer(idDonor, idNote, amount, idReceiver);
|
||||
transfer(idGiver, idNote, amount, idReceiver);
|
||||
}
|
||||
|
||||
|
||||
/// @notice Moves value between notes
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transferring
|
||||
/// @param idSender ID of the giver, delegate or project manager that is transferring
|
||||
/// the funds from Note to Note. This manager must have permissions to move the value
|
||||
/// @param idNote Id of the note that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a donor sending to a donor or
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
/// a delegate, a delegate to another delegate or a project to precommit it to that project
|
||||
function transfer(uint64 idSender, uint64 idNote, uint amount, uint64 idReceiver) {
|
||||
|
||||
|
@ -489,8 +489,8 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
transferOwnershipToDonor(idNote, amount, idReceiver);
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
transferOwnershipToGiver(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Project) {
|
||||
transferOwnershipToProject(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Delegate) {
|
||||
|
@ -505,9 +505,9 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
uint senderDIdx = getDelegateIdx(n, idSender);
|
||||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another donor
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
// Only accept to change to the original donor to remove all delegates
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idNote, amount, n.delegationChain.length);
|
||||
return;
|
||||
|
@ -553,7 +553,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the donors to avoid committing the donation or by project manager to use
|
||||
/// by the givers to avoid committing the donation or by project manager to use
|
||||
/// the Ether.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -730,7 +730,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
doTransfer(idNote, toNote, amount);
|
||||
}
|
||||
|
||||
function transferOwnershipToDonor(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
function transferOwnershipToGiver(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
uint64 toNote = findNote(
|
||||
idReceiver,
|
||||
new uint64[](0),
|
||||
|
|
|
@ -18,20 +18,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// the token of value goes into the vault and the amount in the pledge
|
||||
/// relevant to this Giver without delegates is increased, and a normal
|
||||
/// transfer is done to the idReceiver
|
||||
/// @param idDonor Identifier of the donor thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same donor, another
|
||||
/// donor, a delegate or a project
|
||||
/// @param idGiver Identifier of the giver thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same giver, another
|
||||
/// giver, a delegate or a project
|
||||
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
function donate(uint64 idGiver, uint64 idReceiver) payable {
|
||||
if (idGiver == 0) {
|
||||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
NoteManager storage sender = findManager(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
|
||||
require(sender.managerType == NoteManagerType.Donor);
|
||||
require(sender.managerType == NoteManagerType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -39,7 +39,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
vault.transfer(amount); // transfers the baseToken to the Vault
|
||||
uint64 idNote = findNote(
|
||||
idDonor,
|
||||
idGiver,
|
||||
new uint64[](0), //what is new?
|
||||
0,
|
||||
0,
|
||||
|
@ -52,16 +52,16 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
Transfer(0, idNote, amount);
|
||||
|
||||
transfer(idDonor, idNote, amount, idReceiver);
|
||||
transfer(idGiver, idNote, amount, idReceiver);
|
||||
}
|
||||
|
||||
|
||||
/// @notice Moves value between notes
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transferring
|
||||
/// @param idSender ID of the giver, delegate or project manager that is transferring
|
||||
/// the funds from Note to Note. This manager must have permissions to move the value
|
||||
/// @param idNote Id of the note that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a donor sending to a donor or
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
/// a delegate, a delegate to another delegate or a project to precommit it to that project
|
||||
function transfer(uint64 idSender, uint64 idNote, uint amount, uint64 idReceiver) {
|
||||
|
||||
|
@ -76,8 +76,8 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
transferOwnershipToDonor(idNote, amount, idReceiver);
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
transferOwnershipToGiver(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Project) {
|
||||
transferOwnershipToProject(idNote, amount, idReceiver);
|
||||
} else if (receiver.managerType == NoteManagerType.Delegate) {
|
||||
|
@ -92,9 +92,9 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
uint senderDIdx = getDelegateIdx(n, idSender);
|
||||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another donor
|
||||
if (receiver.managerType == NoteManagerType.Donor) {
|
||||
// Only accept to change to the original donor to remove all delegates
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == NoteManagerType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idNote, amount, n.delegationChain.length);
|
||||
return;
|
||||
|
@ -140,7 +140,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the donors to avoid committing the donation or by project manager to use
|
||||
/// by the givers to avoid committing the donation or by project manager to use
|
||||
/// the Ether.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -317,7 +317,7 @@ function donate(uint64 idDonor, uint64 idReceiver) payable {
|
|||
doTransfer(idNote, toNote, amount);
|
||||
}
|
||||
|
||||
function transferOwnershipToDonor(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
function transferOwnershipToGiver(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
uint64 toNote = findNote(
|
||||
idReceiver,
|
||||
new uint64[](0),
|
||||
|
|
|
@ -10,12 +10,12 @@ contract Vault {
|
|||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
// 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_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum NoteManagerType { Giver, Delegate, Project }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
|
@ -23,7 +23,7 @@ contract LiquidPledgingBase {
|
|||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
|
@ -75,14 +75,14 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
idGiver = uint64(managers.length);
|
||||
|
||||
managers.push(NoteManager(
|
||||
NoteManagerType.Donor,
|
||||
NoteManagerType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -90,28 +90,28 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DonorAdded(idDonor);
|
||||
GiverAdded(idGiver);
|
||||
}
|
||||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
event GiverAdded(uint64 indexed idGiver);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
///@notice Changes the address, name or commitTime associated with a specific giver
|
||||
function updateGiver(
|
||||
uint64 idGiver,
|
||||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
DonorUpdated(idDonor);
|
||||
NoteManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == NoteManagerType.Giver);//Must be a Giver
|
||||
require(giver.addr == msg.sender);//current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
giver.commitTime = newCommitTime;
|
||||
GiverUpdated(idGiver);
|
||||
}
|
||||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
event GiverUpdated(uint64 indexed idGiver);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
@ -238,7 +238,7 @@ contract LiquidPledgingBase {
|
|||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
|
@ -265,7 +265,7 @@ contract LiquidPledgingBase {
|
|||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -337,7 +337,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
function isProjectCanceled(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -347,7 +347,7 @@ contract LiquidPledgingBase {
|
|||
function isProjectCanceled2(uint64 projectId) constant returns (bool) {
|
||||
NoteManager storage m = findManager(projectId);
|
||||
return false;
|
||||
if (m.managerType == NoteManagerType.Donor) return false;
|
||||
if (m.managerType == NoteManagerType.Giver) return false;
|
||||
assert(m.managerType == NoteManagerType.Project);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentProject == 0) return false;
|
||||
|
@ -360,7 +360,7 @@ contract LiquidPledgingBase {
|
|||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
NoteManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == NoteManagerType.Donor) return idNote;
|
||||
if (manager.managerType == NoteManagerType.Giver) return idNote;
|
||||
|
||||
assert(manager.managerType == NoteManagerType.Project);
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ describe('LiquidPledging test', () => {
|
|||
let accounts;
|
||||
let liquidPledging;
|
||||
let vault;
|
||||
let donor1;
|
||||
let donor2;
|
||||
let giver1;
|
||||
let giver2;
|
||||
let delegate1;
|
||||
let adminProject1;
|
||||
let adminProject2;
|
||||
|
@ -52,13 +52,13 @@ describe('LiquidPledging test', () => {
|
|||
ethConnector.init('testrpc', { gasLimit: 5200000 }, () => {
|
||||
web3 = ethConnector.web3;
|
||||
accounts = ethConnector.accounts;
|
||||
donor1 = accounts[1];
|
||||
giver1 = accounts[1];
|
||||
delegate1 = accounts[2];
|
||||
adminProject1 = accounts[3];
|
||||
adminProject2 = accounts[4];
|
||||
adminProject2a = accounts[5];
|
||||
delegate2 = accounts[6];
|
||||
donor2 = accounts[7];
|
||||
giver2 = accounts[7];
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -67,18 +67,18 @@ describe('LiquidPledging test', () => {
|
|||
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5200000 });
|
||||
await vault.setLiquidPledging(liquidPledging.$address);
|
||||
}).timeout(6000);
|
||||
it('Should create a donor', async () => {
|
||||
await liquidPledging.addDonor('Donor1', 86400, 0, { from: donor1 });
|
||||
it('Should create a giver', async () => {
|
||||
await liquidPledging.addGiver('Giver1', 86400, 0, { from: giver1 });
|
||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||
assert.equal(nManagers, 1);
|
||||
const res = await liquidPledging.getNoteManager(1);
|
||||
assert.equal(res[0], 0); // Donor
|
||||
assert.equal(res[1], donor1);
|
||||
assert.equal(res[2], 'Donor1');
|
||||
assert.equal(res[0], 0); // Giver
|
||||
assert.equal(res[1], giver1);
|
||||
assert.equal(res[2], 'Giver1');
|
||||
assert.equal(res[3], 86400);
|
||||
}).timeout(6000);
|
||||
it('Should make a donation', async () => {
|
||||
await liquidPledging.donate(1, 1, { from: donor1, value: web3.toWei(1) });
|
||||
await liquidPledging.donate(1, 1, { from: giver1, value: web3.toWei(1) });
|
||||
const nNotes = await liquidPledging.numberOfNotes();
|
||||
assert.equal(nNotes.toNumber(), 1);
|
||||
await liquidPledging.getNote(1);
|
||||
|
@ -88,12 +88,12 @@ describe('LiquidPledging test', () => {
|
|||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||
assert.equal(nManagers, 2);
|
||||
const res = await liquidPledging.getNoteManager(2);
|
||||
assert.equal(res[0], 1); // Donor
|
||||
assert.equal(res[0], 1); // Giver
|
||||
assert.equal(res[1], delegate1);
|
||||
assert.equal(res[2], 'Delegate1');
|
||||
}).timeout(6000);
|
||||
it('Donor should delegate on the delegate', async () => {
|
||||
await liquidPledging.transfer(1, 1, web3.toWei(0.5), 2, { from: donor1 });
|
||||
it('Giver should delegate on the delegate', async () => {
|
||||
await liquidPledging.transfer(1, 1, web3.toWei(0.5), 2, { from: giver1 });
|
||||
const nNotes = await liquidPledging.numberOfNotes();
|
||||
assert.equal(nNotes.toNumber(), 2);
|
||||
const res1 = await liquidPledging.getNote(1);
|
||||
|
@ -146,8 +146,8 @@ describe('LiquidPledging test', () => {
|
|||
assert.equal(res3[5].toNumber(), 0); // Old Node
|
||||
assert.equal(res3[6].toNumber(), 0); // Not Paid
|
||||
}).timeout(6000);
|
||||
it('Donor should change his mind and assign half of it to project2', async () => {
|
||||
await liquidPledging.transfer(1, 3, web3.toWei(0.1), 4, { from: donor1 });
|
||||
it('Giver should change his mind and assign half of it to project2', async () => {
|
||||
await liquidPledging.transfer(1, 3, web3.toWei(0.1), 4, { from: giver1 });
|
||||
const nNotes = await liquidPledging.numberOfNotes();
|
||||
assert.equal(nNotes.toNumber(), 4);
|
||||
const res3 = await liquidPledging.getNote(3);
|
||||
|
@ -228,8 +228,8 @@ describe('LiquidPledging test', () => {
|
|||
assert.equal(st.notes[8].delegates[0].id, 2);
|
||||
assert.equal(st.notes[8].proposedProject, 4);
|
||||
}).timeout(6000);
|
||||
it('Donor should be able to send the remaining to project2', async () => {
|
||||
await liquidPledging.transfer(1, 5, web3.toWei(0.02), 4, { from: donor1 });
|
||||
it('Giver should be able to send the remaining to project2', async () => {
|
||||
await liquidPledging.transfer(1, 5, web3.toWei(0.02), 4, { from: giver1 });
|
||||
const st = await liquidPledging.getState(liquidPledging);
|
||||
assert.equal(st.notes.length, 9);
|
||||
assert.equal(web3.fromWei(st.notes[5].amount).toNumber(), 0);
|
||||
|
@ -275,7 +275,7 @@ describe('LiquidPledging test', () => {
|
|||
}).timeout(6000);
|
||||
it('Should not be able to withdraw it', async () => {
|
||||
await assertFail(async () => {
|
||||
await liquidPledging.withdraw(12, web3.toWei(0.005), { from: donor1 });
|
||||
await liquidPledging.withdraw(12, web3.toWei(0.005), { from: giver1 });
|
||||
});
|
||||
}).timeout(6000);
|
||||
it('Should not be able to cancel payment', async () => {
|
||||
|
@ -287,32 +287,32 @@ describe('LiquidPledging test', () => {
|
|||
assert.equal(web3.fromWei(st.notes[12].amount).toNumber(), 0);
|
||||
}).timeout(6000);
|
||||
it('original owner should recover the remaining funds', async () => {
|
||||
await liquidPledging.withdraw(1, web3.toWei(0.5), { from: donor1 });
|
||||
await liquidPledging.withdraw(2, web3.toWei(0.31), { from: donor1 });
|
||||
await liquidPledging.withdraw(4, web3.toWei(0.1), { from: donor1 });
|
||||
await liquidPledging.withdraw(1, web3.toWei(0.5), { from: giver1 });
|
||||
await liquidPledging.withdraw(2, web3.toWei(0.31), { from: giver1 });
|
||||
await liquidPledging.withdraw(4, web3.toWei(0.1), { from: giver1 });
|
||||
|
||||
await liquidPledging.withdraw(8, web3.toWei(0.03), { $extraGas: 100000 }, { from: donor1 });
|
||||
await liquidPledging.withdraw(9, web3.toWei(0.01), { from: donor1 });
|
||||
await liquidPledging.withdraw(8, web3.toWei(0.03), { $extraGas: 100000 }, { from: giver1 });
|
||||
await liquidPledging.withdraw(9, web3.toWei(0.01), { from: giver1 });
|
||||
|
||||
const initialBalance = await getBalance(web3, donor1);
|
||||
const initialBalance = await getBalance(web3, giver1);
|
||||
await vault.multiConfirm([2, 3, 4, 5, 6]);
|
||||
|
||||
const finalBalance = await getBalance(web3, donor1);
|
||||
const finalBalance = await getBalance(web3, giver1);
|
||||
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
|
||||
|
||||
assert.equal(collected, 0.95);
|
||||
}).timeout(8000);
|
||||
it('Should make a donation and create donor', async () => {
|
||||
it('Should make a donation and create giver', async () => {
|
||||
const oldNNotes = await liquidPledging.numberOfNotes();
|
||||
const oldNManagers = await liquidPledging.numberOfNoteManagers();
|
||||
await liquidPledging.donate(0, 1, { from: donor2, value: web3.toWei(1) });
|
||||
await liquidPledging.donate(0, 1, { from: giver2, value: web3.toWei(1) });
|
||||
const nNotes = await liquidPledging.numberOfNotes();
|
||||
assert.equal(nNotes.toNumber(), oldNNotes.toNumber() + 1);
|
||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||
assert.equal(nManagers.toNumber(), oldNManagers.toNumber() + 1);
|
||||
const res = await liquidPledging.getNoteManager(nManagers);
|
||||
assert.equal(res[0], 0); // Donor
|
||||
assert.equal(res[1], donor2);
|
||||
assert.equal(res[0], 0); // Giver
|
||||
assert.equal(res[1], giver2);
|
||||
assert.equal(res[2], '');
|
||||
assert.equal(res[3], 259200); // default to 3 day commitTime
|
||||
}).timeout(6000);
|
||||
|
|
Loading…
Reference in New Issue