Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 76fce0d

Browse files
committedJul 13, 2017
Adapted to runethtx
1 parent 978dbae commit 76fce0d

12 files changed

+7661
-1423
lines changed
 

‎.eslintrc

-45
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,7 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"es6": true,
5-
"node": true,
6-
"mocha": true
7-
},
82
"extends": "airbnb",
9-
"parser": "babel-eslint",
103
"rules": {
11-
// indentation
12-
"indent": [ 2, 4 ],
13-
14-
// spacing
15-
"template-curly-spacing": [ 2, "always" ],
16-
"array-bracket-spacing": [ 2, "always" ],
17-
"object-curly-spacing": [ 2, "always" ],
18-
"computed-property-spacing": [ 2, "always" ],
19-
"no-multiple-empty-lines": [ 2, { "max": 1, "maxEOF": 0, "maxBOF": 0 } ],
20-
21-
// strings
22-
"quotes": [ 2, "double", "avoid-escape" ],
23-
24-
// code arrangement matter
25-
"no-use-before-define": [ 2, { "functions": false } ],
26-
27-
// make it meaningful
28-
"prefer-const": 1,
29-
30-
// keep it simple
31-
"complexity": [ 1, 5 ],
32-
33-
// Consisten return
34-
"consistent-return": 0,
35-
36-
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/*.spec.js", "**/compile.js", "**/test/*.js"]}],
37-
38-
// react
39-
"react/prefer-es6-class": 0,
40-
"react/jsx-filename-extension": 0,
41-
"react/jsx-indent": [ 2, 4 ],
42-
434
"jsx-a11y/href-no-hash": "off",
445
"jsx-a11y/anchor-is-valid": ["warn", { "aspects": ["invalidHref"] }]
45-
},
46-
"globals": {
47-
"artifacts": true,
48-
"web3": true,
49-
"contract": true,
50-
"assert": true
516
}
527
}

‎contracts/LiquidPledging.sol

+37-40
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ contract LiquidPledging is LiquidPledgingBase {
2121
/// @param idReceiver To who it's transfered. Can ve the same donnor, another
2222
/// donor, a delegate or a project
2323
function donate(uint64 idDonor, uint64 idReceiver) payable {
24-
NoteManager sender = findManager(idDonor);
24+
NoteManager storage sender = findManager(idDonor);
2525

26-
if (sender.managerType != NoteManagerType.Donor) throw;
27-
if (sender.addr != msg.sender) throw;
26+
require(sender.managerType == NoteManagerType.Donor);
27+
require(sender.addr == msg.sender);
2828

2929
uint amount = msg.value;
3030

31-
if (amount == 0) throw;
31+
require(amount > 0);
3232

3333
vault.transfer(amount);
3434
uint64 idNote = findNote(
@@ -40,7 +40,7 @@ contract LiquidPledging is LiquidPledgingBase {
4040
PaymentState.NotPaid);
4141

4242

43-
Note nTo = findNote(idNote);
43+
Note storage nTo = findNote(idNote);
4444
nTo.amount += amount;
4545

4646
Transfer(0, idNote, amount);
@@ -60,12 +60,12 @@ contract LiquidPledging is LiquidPledgingBase {
6060

6161
idNote = normalizeNote(idNote);
6262

63-
Note n = findNote(idNote);
64-
NoteManager receiver = findManager(idReceiver);
65-
NoteManager sender = findManager(idSender);
63+
Note storage n = findNote(idNote);
64+
NoteManager storage receiver = findManager(idReceiver);
65+
NoteManager storage sender = findManager(idSender);
6666

67-
if (sender.addr != msg.sender) throw;
68-
if (n.paymentState != PaymentState.NotPaid) throw;
67+
require(sender.addr == msg.sender);
68+
require(n.paymentState == PaymentState.NotPaid);
6969

7070
// If the sender is the owner
7171
if (n.owner == idSender) {
@@ -76,7 +76,7 @@ contract LiquidPledging is LiquidPledgingBase {
7676
} else if (receiver.managerType == NoteManagerType.Delegate) {
7777
appendDelegate(idNote, amount, idReceiver);
7878
} else {
79-
throw;
79+
assert(false);
8080
}
8181
return;
8282
}
@@ -88,11 +88,8 @@ contract LiquidPledging is LiquidPledgingBase {
8888
// If the receiver is another doner
8989
if (receiver.managerType == NoteManagerType.Donor) {
9090
// Only accept to change to the original donor to remove all delegates
91-
if (n.owner == idReceiver) {
92-
undelegate(idNote, amount, n.delegationChain.length);
93-
} else {
94-
throw;
95-
}
91+
assert(n.owner == idReceiver);
92+
undelegate(idNote, amount, n.delegationChain.length);
9693
return;
9794
}
9895

@@ -122,7 +119,7 @@ contract LiquidPledging is LiquidPledgingBase {
122119
return;
123120
}
124121
}
125-
throw; // It is not the owner nor any delegate.
122+
assert(false); // It is not the owner nor any delegate.
126123
}
127124

128125

@@ -135,13 +132,13 @@ contract LiquidPledging is LiquidPledgingBase {
135132

136133
idNote = normalizeNote(idNote);
137134

138-
Note n = findNote(idNote);
135+
Note storage n = findNote(idNote);
139136

140-
if (n.paymentState != PaymentState.NotPaid) throw;
137+
require(n.paymentState == PaymentState.NotPaid);
141138

142-
NoteManager owner = findManager(n.owner);
139+
NoteManager storage owner = findManager(n.owner);
143140

144-
if (owner.addr != msg.sender) throw;
141+
require(owner.addr == msg.sender);
145142

146143
uint64 idNewNote = findNote(
147144
n.owner,
@@ -161,12 +158,12 @@ contract LiquidPledging is LiquidPledgingBase {
161158
/// @param idNote Id of the note that wants to be withdrawed.
162159
/// @param amount Quantity of Ether that wants to be withdrawed.
163160
function confirmPayment(uint64 idNote, uint amount) onlyVault {
164-
Note n = findNote(idNote);
161+
Note storage n = findNote(idNote);
165162

166-
if (n.paymentState != PaymentState.Paying) throw;
163+
require(n.paymentState == PaymentState.Paying);
167164

168165
// Check the project is not canceled in the while.
169-
if (getOldestNoteNotCanceled(idNote) != idNote) throw;
166+
require(getOldestNoteNotCanceled(idNote) == idNote);
170167

171168
uint64 idNewNote = findNote(
172169
n.owner,
@@ -184,9 +181,9 @@ contract LiquidPledging is LiquidPledgingBase {
184181
/// @param idNote Id of the note that wants to be canceled for withdraw.
185182
/// @param amount Quantity of Ether that wants to be rolled back.
186183
function cancelPayment(uint64 idNote, uint amount) onlyVault {
187-
Note n = findNote(idNote);
184+
Note storage n = findNote(idNote);
188185

189-
if (n.paymentState != PaymentState.Paying) throw;
186+
require(n.paymentState == PaymentState.Paying);
190187

191188
// When a payment is cacnceled, never is assigned to a project.
192189
uint64 oldNote = findNote(
@@ -206,7 +203,7 @@ contract LiquidPledging is LiquidPledgingBase {
206203
/// @notice Method called by the reviewer of a project to cancel this project.
207204
/// @param idProject Id of the projct that wants to be canceled.
208205
function cancelProject(uint64 idProject) {
209-
NoteManager project = findManager(idProject);
206+
NoteManager storage project = findManager(idProject);
210207
require((project.reviewer == msg.sender) || (project.addr == msg.sender));
211208
project.canceled = true;
212209
}
@@ -258,9 +255,9 @@ contract LiquidPledging is LiquidPledgingBase {
258255

259256

260257
function transferOwnershipToProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
261-
Note n = findNote(idNote);
258+
Note storage n = findNote(idNote);
262259

263-
if (getProjectLevel(n) >= MAX_SUBPROJECT_LEVEL) throw;
260+
require(getProjectLevel(n) < MAX_SUBPROJECT_LEVEL);
264261
uint64 oldNote = findNote(
265262
n.owner,
266263
n.delegationChain,
@@ -283,7 +280,7 @@ contract LiquidPledging is LiquidPledgingBase {
283280

284281
function transferOwnershipToDonor(uint64 idNote, uint amount, uint64 idReceiver) internal {
285282
// If the owner does not change, then just let it this way.
286-
Note n = findNote(idNote);
283+
Note storage n = findNote(idNote);
287284

288285
if (n.owner == idReceiver) return;
289286
uint64 toNote = findNote(
@@ -297,9 +294,9 @@ contract LiquidPledging is LiquidPledgingBase {
297294
}
298295

299296
function appendDelegate(uint64 idNote, uint amount, uint64 idReceiver) internal {
300-
Note n = findNote(idNote);
297+
Note storage n= findNote(idNote);
301298

302-
if (n.delegationChain.length >= MAX_DELEGATES) throw;
299+
require(n.delegationChain.length < MAX_DELEGATES);
303300
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length + 1);
304301
for (uint i=0; i<n.delegationChain.length; i++) {
305302
newDelegationChain[i] = n.delegationChain[i];
@@ -317,7 +314,7 @@ contract LiquidPledging is LiquidPledgingBase {
317314

318315
/// @param q Unmber of undelegations
319316
function undelegate(uint64 idNote, uint amount, uint q) internal {
320-
Note n = findNote(idNote);
317+
Note storage n = findNote(idNote);
321318
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
322319
for (uint i=0; i<n.delegationChain.length - q; i++) {
323320
newDelegationChain[i] = n.delegationChain[i];
@@ -334,11 +331,11 @@ contract LiquidPledging is LiquidPledgingBase {
334331

335332

336333
function proposeAssignProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
337-
Note n = findNote(idNote);
334+
Note storage n = findNote(idNote);
338335

339-
if (getProjectLevel(n) >= MAX_SUBPROJECT_LEVEL) throw;
336+
require(getProjectLevel(n) < MAX_SUBPROJECT_LEVEL);
340337

341-
NoteManager owner = findManager(n.owner);
338+
NoteManager storage owner = findManager(n.owner);
342339
uint64 toNote = findNote(
343340
n.owner,
344341
n.delegationChain,
@@ -352,17 +349,17 @@ contract LiquidPledging is LiquidPledgingBase {
352349
function doTransfer(uint64 from, uint64 to, uint amount) internal {
353350
if (from == to) return;
354351
if (amount == 0) return;
355-
Note nFrom = findNote(from);
356-
Note nTo = findNote(to);
357-
if (nFrom.amount < amount) throw;
352+
Note storage nFrom = findNote(from);
353+
Note storage nTo = findNote(to);
354+
require(nFrom.amount >= amount);
358355
nFrom.amount -= amount;
359356
nTo.amount += amount;
360357

361358
Transfer(from, to, amount);
362359
}
363360

364361
function normalizeNote(uint64 idNote) internal returns(uint64) {
365-
Note n = findNote(idNote);
362+
Note storage n = findNote(idNote);
366363
if (n.paymentState != PaymentState.NotPaid) return idNote;
367364

368365
// First send to a project if it's proposed and commited

‎contracts/LiquidPledgingBase.sol

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pragma solidity ^0.4.11;
22

3-
import "./Vault.sol";
3+
contract Vault {
4+
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
5+
}
46

57
contract LiquidPledgingBase {
68

@@ -39,7 +41,7 @@ contract LiquidPledgingBase {
3941
/////
4042

4143
modifier onlyVault() {
42-
if (msg.sender != address(vault)) throw;
44+
require(msg.sender == address(vault));
4345
_;
4446
}
4547

@@ -79,9 +81,9 @@ contract LiquidPledgingBase {
7981
string newName,
8082
uint64 newCommitTime)
8183
{
82-
NoteManager donor = findManager(idDonor);
83-
if (donor.managerType != NoteManagerType.Donor) throw;
84-
if (donor.addr != msg.sender) throw;
84+
NoteManager storage donor = findManager(idDonor);
85+
require(donor.managerType == NoteManagerType.Donor);
86+
require(donor.addr == msg.sender);
8587
donor.addr = newAddr;
8688
donor.name = newName;
8789
donor.commitTime = newCommitTime;
@@ -105,9 +107,9 @@ contract LiquidPledgingBase {
105107
event DeegateAdded(uint64 indexed idMember);
106108

107109
function updateDelegate(uint64 idDelegate, address newAddr, string newName) {
108-
NoteManager delegate = findManager(idDelegate);
109-
if (delegate.managerType != NoteManagerType.Delegate) throw;
110-
if (delegate.addr != msg.sender) throw;
110+
NoteManager storage delegate = findManager(idDelegate);
111+
require(delegate.managerType == NoteManagerType.Delegate);
112+
require(delegate.addr == msg.sender);
111113
delegate.addr = newAddr;
112114
delegate.name = newName;
113115
DelegateUpdated(idDelegate);
@@ -130,19 +132,19 @@ contract LiquidPledgingBase {
130132
event ProjectAdded(uint64 indexed idMember);
131133

132134
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime) {
133-
NoteManager project = findManager(idProject);
134-
if (project.managerType != NoteManagerType.Project) throw;
135-
if (project.addr != msg.sender) throw;
135+
NoteManager storage project = findManager(idProject);
136+
require(project.managerType == NoteManagerType.Project);
137+
require(project.addr == msg.sender);
136138
project.addr = newAddr;
137139
project.name = newName;
138140
project.commitTime = newCommitTime;
139141
ProjectUpdated(idProject);
140142
}
141143

142144
function updateProjectCanceler(uint64 idProject, address newReviewer) {
143-
NoteManager project = findManager(idProject);
144-
if (project.managerType != NoteManagerType.Project) throw;
145-
if (project.reviewer != msg.sender) throw;
145+
NoteManager storage project = findManager(idProject);
146+
require(project.managerType == NoteManagerType.Project);
147+
require(project.reviewer == msg.sender);
146148
project.reviewer = newReviewer;
147149
ProjectUpdated(idProject);
148150
}
@@ -168,7 +170,7 @@ contract LiquidPledgingBase {
168170
uint64 oldNote,
169171
PaymentState paymentState
170172
) {
171-
Note n = findNote(idNote);
173+
Note storage n = findNote(idNote);
172174
amount = n.amount;
173175
owner = n.owner;
174176
nDelegates = uint64(n.delegationChain.length);
@@ -183,9 +185,9 @@ contract LiquidPledgingBase {
183185
address addr,
184186
string name
185187
) {
186-
Note n = findNote(idNote);
188+
Note storage n = findNote(idNote);
187189
idDelegate = n.delegationChain[idxDelegate - 1];
188-
NoteManager delegate = findManager(idDelegate);
190+
NoteManager storage delegate = findManager(idDelegate);
189191
addr = delegate.addr;
190192
name = delegate.name;
191193
}
@@ -202,7 +204,7 @@ contract LiquidPledgingBase {
202204
address reviewer,
203205
bool canceled)
204206
{
205-
NoteManager m = findManager(idManager);
207+
NoteManager storage m = findManager(idManager);
206208
managerType = m.managerType;
207209
addr = m.addr;
208210
name = m.name;
@@ -234,19 +236,19 @@ contract LiquidPledgingBase {
234236
}
235237

236238
function findManager(uint64 idManager) internal returns (NoteManager storage) {
237-
if (idManager >= managers.length) throw;
239+
require(idManager < managers.length);
238240
return managers[idManager];
239241
}
240242

241243
function findNote(uint64 idNote) internal returns (Note storage) {
242-
if (idNote >= notes.length) throw;
244+
require(idNote < notes.length);
243245
return notes[idNote];
244246
}
245247

246248
function getOldestNoteNotCanceled(uint64 idNote) internal constant returns(uint64) {
247249
if (idNote == 0) return 0;
248-
Note n = findNote(idNote);
249-
NoteManager owner = findManager(n.owner);
250+
Note storage n = findNote(idNote);
251+
NoteManager storage owner = findManager(n.owner);
250252
if (owner.managerType == NoteManagerType.Donor) return idNote;
251253

252254
uint64 parentProject = getOldestNoteNotCanceled(n.oldNote);
@@ -270,7 +272,7 @@ contract LiquidPledgingBase {
270272

271273
function getProjectLevel(Note n) internal returns(uint) {
272274
if (n.oldNote == 0) return 1;
273-
Note oldN = findNote(n.oldNote);
275+
Note storage oldN = findNote(n.oldNote);
274276
return getProjectLevel(oldN) + 1;
275277
}
276278

‎contracts/test/LiquidPledgingMock.sol ‎contracts/LiquidPledgingMock.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pragma solidity ^0.4.11;
22

3-
import '../LiquidPledging.sol';
3+
import "./LiquidPledging.sol";
44

5-
// @dev DevTokensHolderMock mocks current block number
5+
// @dev LiquidPledgingMock mocks current block number
66

77
contract LiquidPledgingMock is LiquidPledging {
88

‎contracts/Vault.sol

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
pragma solidity ^0.4.11;
22

33
import "./Owned.sol";
4-
import "./LiquidPledging.sol";
4+
5+
contract LiquidPledging {
6+
function confirmPayment(uint64 idNote, uint amount);
7+
function cancelPayment(uint64 idNote, uint amount);
8+
}
59

610
contract Vault is Owned {
711

@@ -66,7 +70,7 @@ contract Vault is Owned {
6670

6771
function doConfirmPayment(uint _idPayment) internal {
6872
require(_idPayment < payments.length);
69-
Payment p = payments[_idPayment];
73+
Payment storage p = payments[_idPayment];
7074
require(p.state == PaymentState.Pending);
7175

7276
p.state = PaymentState.Paid;
@@ -83,7 +87,7 @@ contract Vault is Owned {
8387

8488
function doCancelPayment(uint _idPayment) internal {
8589
require(_idPayment < payments.length);
86-
Payment p = payments[_idPayment];
90+
Payment storage p = payments[_idPayment];
8791
require(p.state == PaymentState.Pending);
8892

8993
p.state = PaymentState.Canceled;

‎js/liquidPladging.js ‎js/liquidPledging.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const LiquidPledgingAbi = require("../build/contracts/LiquidPledging.json").abi;
1+
const LiquidPledgingAbi = require("../build/LiquidPledging.sol").LiquidPledgingAbi;
2+
const LiquidPledgingCode = require("../build/LiquidPledging.sol").LiquidPledgingByteCode;
3+
const LiquidPledgingMockAbi = require("../build/LiquidPledgingMock.sol").LiquidPledgingMockAbi;
4+
const LiquidPledgingMockCode = require("../build/LiquidPledgingMock.sol").LiquidPledgingMockByteCode;
5+
const runethtx = require("runethtx");
26

3-
module.exports = class LiquidPledging {
7+
module.exports = (test) => {
8+
const LiquidPladgingContract = test ?
9+
runethtx.generateClass(LiquidPledgingMockAbi, LiquidPledgingMockCode) :
10+
runethtx.generateClass(LiquidPledgingAbi, LiquidPledgingCode);
11+
12+
return class LiquidPledging extends LiquidPladgingContract {
413
constructor(web3, address) {
5-
this.web3 = web3;
6-
this.address = address;
14+
super(web3, address);
715
this.notes = [];
816
this.managers = [];
917
}
@@ -110,4 +118,5 @@ module.exports = class LiquidPledging {
110118

111119
this.donorsState = donorsState;
112120
}
121+
};
113122
};

‎js/vault.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const VaultAbi = require("../build/Vault.sol").VaultAbi;
2+
const VaultByteCode = require("../build/Vault.sol").VaultByteCode;
3+
const runethtx = require("runethtx");
4+
5+
module.exports = runethtx.generateClass(VaultAbi, VaultByteCode);

‎package-lock.json

+7,518-1,280
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
},
4343
"homepage": "https://github.com/Giveth/liquidpledging#readme",
4444
"dependencies": {
45-
"babel-eslint": "^7.2.3"
45+
"babel-eslint": "^7.2.3",
46+
"chai": "^4.1.0",
47+
"ethconnector": "0.0.25",
48+
"runethtx": "0.0.9"
4649
}
4750
}

‎test/NormalOperation.js

+43-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const LiquidPledging = artifacts.require("LiquidPledgingMock");
2-
const Vault = artifacts.require("Vault");
1+
const ethConnector = require('ethconnector');
2+
const chai = require('chai');
3+
const assert = chai.assert;
4+
const LiquidPledging = require('../js/liquidPledging.js')(true);
5+
const Vault = require('../js/vault.js');
36
const assertFail = require("./helpers/assertFail");
7+
const getBalance = require("runethtx").getBalance;
48

59
const getNote = async (liquidPledging, idNote) => {
610
const note = {
@@ -90,21 +94,36 @@ const printBalances = async(liquidPledging) => {
9094
}
9195
};
9296

93-
94-
contract("LiquidPledging", (accounts) => {
97+
describe("LiquidPledging test", () => {
98+
let web3;
99+
let accounts;
95100
let liquidPledging;
96101
let vault;
97-
let donor1 = accounts[1];
98-
let delegate1 = accounts[2];
99-
let adminProject1 = accounts[3];
100-
let adminProject2 = accounts[4];
101-
let adminProject2a = accounts[5];
102-
let delegate2 = accounts[6];
103-
let reviewer = accounts[7];
102+
let donor1;
103+
let delegate1;
104+
let adminProject1;
105+
let adminProject2;
106+
let adminProject2a;
107+
let delegate2;
108+
let reviewer;
109+
before((done) => {
110+
ethConnector.init("testrpc", { gasLimit: 4000000 }, () => {
111+
web3 = ethConnector.web3;
112+
accounts = ethConnector.accounts;
113+
donor1 = accounts[1];
114+
delegate1 = accounts[2];
115+
adminProject1 = accounts[3];
116+
adminProject2 = accounts[4];
117+
adminProject2a = accounts[5];
118+
delegate2 = accounts[6];
119+
reviewer = accounts[7];
120+
done();
121+
});
122+
});
104123
it("Should deploy LiquidPledgin contract", async () => {
105-
vault = await Vault.new();
106-
liquidPledging = await LiquidPledging.new(vault.address);
107-
await vault.setLiquidPledging(liquidPledging.address);
124+
vault = await Vault.new(web3);
125+
liquidPledging = await LiquidPledging.new(web3, vault.$address);
126+
await vault.setLiquidPledging(liquidPledging.$address);
108127
});
109128
it("Should create a donor", async () => {
110129
await liquidPledging.addDonor("Donor1", 86400, {from: donor1});
@@ -181,7 +200,7 @@ contract("LiquidPledging", (accounts) => {
181200
assert.equal(res3[1].toNumber(), 1); // Owner
182201
assert.equal(res3[2].toNumber(), 1); // Delegates
183202
assert.equal(res3[3].toNumber(), 3); // Proposed Project
184-
assert.isAbove(res3[4], n + 86000);
203+
assert.isAbove(res3[4].toNumber(), n + 86000);
185204
assert.equal(res3[5].toNumber(), 0); // Old Node
186205
assert.equal(res3[6].toNumber(), 0); // Not Paid
187206
});
@@ -224,10 +243,10 @@ contract("LiquidPledging", (accounts) => {
224243
assert.equal(res6[6].toNumber(), 1); // Peinding paid Paid
225244
});
226245
it("Should collect the Ether", async () => {
227-
const initialBalance = await web3.eth.getBalance(adminProject1);
246+
const initialBalance = await getBalance(web3, adminProject1);
228247

229248
await vault.confirmPayment(0);
230-
const finalBalance = await web3.eth.getBalance(adminProject1);
249+
const finalBalance = await getBalance(web3, adminProject1);
231250

232251
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
233252

@@ -257,7 +276,7 @@ contract("LiquidPledging", (accounts) => {
257276
});
258277
});
259278
it("Delegate should send part of this ETH to project2", async () => {
260-
await liquidPledging.transfer(2, 5, web3.toWei(0.03), 4, {from: delegate1});
279+
await liquidPledging.transfer(2, 5, web3.toWei(0.03), 4,{$extraGas: 100000}, {from: delegate1});
261280
const st = await getState(liquidPledging);
262281
assert.equal(st.notes.length, 9);
263282
assert.equal(web3.fromWei(st.notes[ 8 ].amount).toNumber(), 0.03);
@@ -292,7 +311,7 @@ contract("LiquidPledging", (accounts) => {
292311
assert.equal(st.notes.length, 11);
293312
assert.equal(web3.fromWei(st.notes[ 9 ].amount).toNumber(), 0.01);
294313
assert.equal(web3.fromWei(st.notes[ 10 ].amount).toNumber(), 0.01);
295-
});
314+
}).timeout(4000);
296315
it("project2a authorize to spend a little", async () => {
297316
const n = Math.floor(new Date().getTime() / 1000);
298317
await liquidPledging.setMockedTime(n + 86401*3);
@@ -302,7 +321,7 @@ contract("LiquidPledging", (accounts) => {
302321
assert.equal(web3.fromWei(st.notes[ 10 ].amount).toNumber(), 0);
303322
assert.equal(web3.fromWei(st.notes[ 11 ].amount).toNumber(), 0.005);
304323
assert.equal(web3.fromWei(st.notes[ 12 ].amount).toNumber(), 0.005);
305-
});
324+
}).timeout(4000);
306325
it("project2 is canceled", async () => {
307326
await liquidPledging.cancelProject(4, {from: reviewer});
308327
});
@@ -326,21 +345,20 @@ contract("LiquidPledging", (accounts) => {
326345
});
327346
it("original owner should recover the remaining funds", async () => {
328347
const st = await getState(liquidPledging);
329-
330348
await liquidPledging.withdraw(1, web3.toWei(0.5), {from: donor1});
331349
await liquidPledging.withdraw(2, web3.toWei(0.31), {from: donor1});
332350
await liquidPledging.withdraw(4, web3.toWei(0.1), {from: donor1});
333351

334-
await liquidPledging.withdraw(8, web3.toWei(0.03), {from: donor1});
352+
await liquidPledging.withdraw(8, web3.toWei(0.03), {$extraGas: 100000}, {from: donor1});
335353
await liquidPledging.withdraw(9, web3.toWei(0.01), {from: donor1});
336354

337-
const initialBalance = await web3.eth.getBalance(donor1);
355+
const initialBalance = await getBalance(web3, donor1);
338356
await vault.multiConfirm([2,3,4,5,6]);
339357

340-
const finalBalance = await web3.eth.getBalance(donor1);
358+
const finalBalance = await getBalance(web3, donor1);
341359
const collected = web3.fromWei(finalBalance.sub(initialBalance)).toNumber();
342360

343361
assert.equal(collected, 0.95);
344-
});
362+
}).timeout(8000);
345363

346364
});

‎test/helpers/assertFail.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const chai = require('chai');
2+
const assert = chai.assert;
3+
14
module.exports = async function(callback) {
25
let web3_error_thrown = false;
36
try {

‎tmp/xx.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('runethtx')
2+
3+
console.log('hh');
4+

0 commit comments

Comments
 (0)
This repository has been archived.