Skip to content

Commit bd4eb69

Browse files
authored
Merge pull request #129 from ethereum/cli-tests
Use stderr for errors in solcjs
2 parents ae27539 + c2b8e0d commit bd4eb69

File tree

6 files changed

+55
-52
lines changed

6 files changed

+55
-52
lines changed

solcjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var files = argv._;
4747
var destination = argv['output-dir'] || '.'
4848

4949
function abort (msg) {
50-
console.log(msg || 'Error occured');
50+
console.error(msg || 'Error occured');
5151
process.exit(1);
5252
}
5353

@@ -90,7 +90,7 @@ if (!output) {
9090
abort('No output from compiler');
9191
} else if (output['errors']) {
9292
for (var error in output['errors']) {
93-
console.log(output['errors'][error]);
93+
console.error(output['errors'][error]);
9494
}
9595
}
9696

@@ -100,7 +100,7 @@ function writeFile (file, content) {
100100
file = path.join(destination, file);
101101
fs.writeFile(file, content, function (err) {
102102
if (err) {
103-
console.log('Failed to write ' + file + ': ' + err);
103+
console.error('Failed to write ' + file + ': ' + err);
104104
}
105105
});
106106
}

test/DAO/DAO.sol

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
353353

354354
// Modifier that allows only shareholders to vote and create new proposals
355355
modifier onlyTokenholders {
356-
if (balanceOf(msg.sender) == 0) throw;
356+
if (balanceOf(msg.sender) == 0) revert();
357357
_;
358358
}
359359

@@ -381,9 +381,9 @@ contract DAO is DAOInterface, Token, TokenCreation {
381381
rewardAccount = new ManagedAccount(address(this), false);
382382
DAOrewardAccount = new ManagedAccount(address(this), false);
383383
if (address(rewardAccount) == 0)
384-
throw;
384+
revert();
385385
if (address(DAOrewardAccount) == 0)
386-
throw;
386+
revert();
387387
lastTimeMinQuorumMet = now;
388388
minQuorumDivisor = 5; // sets the minimal quorum to 20%
389389
proposals.length = 1; // avoids a proposal with ID 0 because it is used
@@ -421,30 +421,30 @@ contract DAO is DAOInterface, Token, TokenCreation {
421421
|| _recipient == curator
422422
|| msg.value > 0
423423
|| _debatingPeriod < minSplitDebatePeriod)) {
424-
throw;
424+
revert();
425425
} else if (
426426
!_newCurator
427427
&& (!isRecipientAllowed(_recipient) || (_debatingPeriod < minProposalDebatePeriod))
428428
) {
429-
throw;
429+
revert();
430430
}
431431

432432
if (_debatingPeriod > 8 weeks)
433-
throw;
433+
revert();
434434

435435
if (!isFueled
436436
|| now < closingTime
437437
|| (msg.value < proposalDeposit && !_newCurator)) {
438438

439-
throw;
439+
revert();
440440
}
441441

442442
if (now + _debatingPeriod < now) // prevents overflow
443-
throw;
443+
revert();
444444

445445
// to prevent a 51% attacker to convert the ether into deposit
446446
if (msg.sender == address(this))
447-
throw;
447+
revert();
448448

449449
// to prevent curator from halving quorum before first proposal
450450
if (proposals.length == 1) // initial length is 1 (see constructor)
@@ -498,7 +498,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
498498
|| p.votedNo[msg.sender]
499499
|| now >= p.votingDeadline) {
500500

501-
throw;
501+
revert();
502502
}
503503

504504
if (_supportsProposal) {
@@ -545,7 +545,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
545545
// Does the transaction code match the proposal?
546546
|| p.proposalHash != sha3(p.recipient, p.amount, _transactionData)) {
547547

548-
throw;
548+
revert();
549549
}
550550

551551
// If the curator removed the recipient from the whitelist, close the proposal
@@ -574,7 +574,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
574574

575575
if (quorum >= minQuorum(p.amount)) {
576576
if (!p.creator.send(p.proposalDeposit))
577-
throw;
577+
revert();
578578

579579
lastTimeMinQuorumMet = now;
580580
// set the minQuorum to 20% again, in the case it has been reached
@@ -591,7 +591,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
591591
p.proposalPassed = true;
592592

593593
if (!p.recipient.call.value(p.amount)(_transactionData))
594-
throw;
594+
revert();
595595

596596
_success = true;
597597

@@ -642,7 +642,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
642642
// Did you already vote on another proposal?
643643
|| (blocked[msg.sender] != _proposalID && blocked[msg.sender] != 0) ) {
644644

645-
throw;
645+
revert();
646646
}
647647

648648
// If the new DAO doesn't exist yet, create the new DAO and store the
@@ -651,10 +651,10 @@ contract DAO is DAOInterface, Token, TokenCreation {
651651
p.splitData[0].newDAO = createNewDAO(_newCurator);
652652
// Call depth limit reached, etc.
653653
if (address(p.splitData[0].newDAO) == 0)
654-
throw;
654+
revert();
655655
// should never happen
656656
if (this.balance < sumOfProposalDeposits)
657-
throw;
657+
revert();
658658
p.splitData[0].splitBalance = actualBalance();
659659
p.splitData[0].rewardToken = rewardToken[address(this)];
660660
p.splitData[0].totalSupply = totalSupply;
@@ -666,7 +666,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
666666
(balances[msg.sender] * p.splitData[0].splitBalance) /
667667
p.splitData[0].totalSupply;
668668
if (p.splitData[0].newDAO.createTokenProxy.value(fundsToBeMoved)(msg.sender) == false)
669-
throw;
669+
revert();
670670

671671

672672
// Assign reward rights to new DAO
@@ -679,12 +679,12 @@ contract DAO is DAOInterface, Token, TokenCreation {
679679

680680
rewardToken[address(p.splitData[0].newDAO)] += rewardTokenToBeMoved;
681681
if (rewardToken[address(this)] < rewardTokenToBeMoved)
682-
throw;
682+
revert();
683683
rewardToken[address(this)] -= rewardTokenToBeMoved;
684684

685685
DAOpaidOut[address(p.splitData[0].newDAO)] += paidOutToBeMoved;
686686
if (DAOpaidOut[address(this)] < paidOutToBeMoved)
687-
throw;
687+
revert();
688688
DAOpaidOut[address(this)] -= paidOutToBeMoved;
689689

690690
// Burn DAO Tokens
@@ -700,7 +700,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
700700
if (msg.sender != address(this) || !allowedRecipients[_newContract]) return;
701701
// move all ether
702702
if (!_newContract.call.value(address(this).balance)()) {
703-
throw;
703+
revert();
704704
}
705705

706706
//move all reward tokens
@@ -716,7 +716,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
716716

717717
if ((rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
718718
totalRewardToken < DAOpaidOut[msg.sender])
719-
throw;
719+
revert();
720720

721721
uint reward =
722722
(rewardToken[msg.sender] * DAOrewardAccount.accumulatedInput()) /
@@ -726,11 +726,11 @@ contract DAO is DAOInterface, Token, TokenCreation {
726726

727727
if(_toMembers) {
728728
if (!DAOrewardAccount.payOut(dao.rewardAccount(), reward))
729-
throw;
729+
revert();
730730
}
731731
else {
732732
if (!DAOrewardAccount.payOut(dao, reward))
733-
throw;
733+
revert();
734734
}
735735
DAOpaidOut[msg.sender] += reward;
736736
return true;
@@ -743,15 +743,15 @@ contract DAO is DAOInterface, Token, TokenCreation {
743743

744744
function withdrawRewardFor(address _account) noEther internal returns (bool _success) {
745745
if ((balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply < paidOut[_account])
746-
throw;
746+
revert();
747747

748748
uint reward =
749749
(balanceOf(_account) * rewardAccount.accumulatedInput()) / totalSupply - paidOut[_account];
750750

751751
reward = rewardAccount.balance < reward ? rewardAccount.balance : reward;
752752

753753
if (!rewardAccount.payOut(_account, reward))
754-
throw;
754+
revert();
755755
paidOut[_account] += reward;
756756
return true;
757757
}
@@ -767,14 +767,14 @@ contract DAO is DAOInterface, Token, TokenCreation {
767767

768768
return true;
769769
} else {
770-
throw;
770+
revert();
771771
}
772772
}
773773

774774

775775
function transferWithoutReward(address _to, uint256 _value) returns (bool success) {
776776
if (!getMyReward())
777-
throw;
777+
revert();
778778
return transfer(_to, _value);
779779
}
780780

@@ -789,7 +789,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
789789

790790
return true;
791791
} else {
792-
throw;
792+
revert();
793793
}
794794
}
795795

@@ -801,7 +801,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
801801
) returns (bool success) {
802802

803803
if (!withdrawRewardFor(_from))
804-
throw;
804+
revert();
805805
return transferFrom(_from, _to, _value);
806806
}
807807

@@ -814,7 +814,7 @@ contract DAO is DAOInterface, Token, TokenCreation {
814814

815815
uint transferPaidOut = paidOut[_from] * _value / balanceOf(_from);
816816
if (transferPaidOut > paidOut[_from])
817-
throw;
817+
revert();
818818
paidOut[_from] -= transferPaidOut;
819819
paidOut[_to] += transferPaidOut;
820820
return true;
@@ -825,15 +825,15 @@ contract DAO is DAOInterface, Token, TokenCreation {
825825
if (msg.sender != address(this) || _proposalDeposit > (actualBalance() + rewardToken[address(this)])
826826
/ maxDepositDivisor) {
827827

828-
throw;
828+
revert();
829829
}
830830
proposalDeposit = _proposalDeposit;
831831
}
832832

833833

834834
function changeAllowedRecipients(address _recipient, bool _allowed) noEther external returns (bool _success) {
835835
if (msg.sender != curator)
836-
throw;
836+
revert();
837837
allowedRecipients[_recipient] = _allowed;
838838
AllowedRecipientChanged(_recipient, _allowed);
839839
return true;

test/DAO/ManagedAccount.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract ManagedAccount is ManagedAccountInterface{
5656

5757
function payOut(address _recipient, uint _amount) returns (bool) {
5858
if (msg.sender != owner || msg.value > 0 || (payOwnerOnly && _recipient != owner))
59-
throw;
59+
revert();
6060
if (_recipient.call.value(_amount)()) {
6161
PayOut(_recipient, _amount);
6262
return true;

test/DAO/Token.sol

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Which is itself based on the Ethereum standardized contract APIs:
2828
https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs
2929
*/
3030

31+
pragma solidity ^0.4.0;
32+
3133
/// @title Standard Token Contract.
3234

3335
contract TokenInterface {
@@ -45,28 +47,28 @@ contract TokenInterface {
4547

4648
/// @param _owner The address from which the balance will be retrieved
4749
/// @return The balance
48-
function balanceOf(address _owner) constant returns (uint256 balance);
50+
function balanceOf(address _owner) public constant returns (uint256 balance);
4951

5052
/// @notice Send `_amount` tokens to `_to` from `msg.sender`
5153
/// @param _to The address of the recipient
5254
/// @param _amount The amount of tokens to be transferred
5355
/// @return Whether the transfer was successful or not
54-
function transfer(address _to, uint256 _amount) returns (bool success);
56+
function transfer(address _to, uint256 _amount) public returns (bool success);
5557

5658
/// @notice Send `_amount` tokens to `_to` from `_from` on the condition it
5759
/// is approved by `_from`
5860
/// @param _from The address of the origin of the transfer
5961
/// @param _to The address of the recipient
6062
/// @param _amount The amount of tokens to be transferred
6163
/// @return Whether the transfer was successful or not
62-
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);
64+
function transferFrom(address _from, address _to, uint256 _amount) public returns (bool success);
6365

6466
/// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
6567
/// its behalf
6668
/// @param _spender The address of the account able to transfer the tokens
6769
/// @param _amount The amount of tokens to be approved for transfer
6870
/// @return Whether the approval was successful or not
69-
function approve(address _spender, uint256 _amount) returns (bool success);
71+
function approve(address _spender, uint256 _amount) public returns (bool success);
7072

7173
/// @param _owner The address of the account owning tokens
7274
/// @param _spender The address of the account able to transfer the tokens
@@ -75,7 +77,7 @@ contract TokenInterface {
7577
function allowance(
7678
address _owner,
7779
address _spender
78-
) constant returns (uint256 remaining);
80+
) public constant returns (uint256 remaining);
7981

8082
event Transfer(address indexed _from, address indexed _to, uint256 _amount);
8183
event Approval(
@@ -86,19 +88,19 @@ contract TokenInterface {
8688
}
8789

8890
contract tokenRecipient {
89-
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);
91+
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public;
9092
}
9193

9294
contract Token is TokenInterface {
9395
// Protects users by preventing the execution of method calls that
9496
// inadvertently also transferred ether
95-
modifier noEther() {if (msg.value > 0) throw; _; }
97+
modifier noEther() {if (msg.value > 0) revert(); _; }
9698

97-
function balanceOf(address _owner) constant returns (uint256 balance) {
99+
function balanceOf(address _owner) public constant returns (uint256 balance) {
98100
return balances[_owner];
99101
}
100102

101-
function transfer(address _to, uint256 _amount) noEther returns (bool success) {
103+
function transfer(address _to, uint256 _amount) noEther public returns (bool success) {
102104
if (balances[msg.sender] >= _amount && _amount > 0) {
103105
balances[msg.sender] -= _amount;
104106
balances[_to] += _amount;
@@ -113,7 +115,7 @@ contract Token is TokenInterface {
113115
address _from,
114116
address _to,
115117
uint256 _amount
116-
) noEther returns (bool success) {
118+
) noEther public returns (bool success) {
117119

118120
if (balances[_from] >= _amount
119121
&& allowed[_from][msg.sender] >= _amount
@@ -129,22 +131,22 @@ contract Token is TokenInterface {
129131
}
130132
}
131133

132-
function approve(address _spender, uint256 _amount) returns (bool success) {
134+
function approve(address _spender, uint256 _amount) public returns (bool success) {
133135
allowed[msg.sender][_spender] = _amount;
134136
Approval(msg.sender, _spender, _amount);
135137
return true;
136138
}
137139

138140
/// Allow another contract to spend some tokens in your behalf
139141
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
140-
returns (bool success) {
142+
public returns (bool success) {
141143
allowed[msg.sender][_spender] = _value;
142144
tokenRecipient spender = tokenRecipient(_spender);
143145
spender.receiveApproval(msg.sender, _value, this, _extraData);
144146
return true;
145147
}
146148

147-
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
149+
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
148150
return allowed[_owner][_spender];
149151
}
150152
}

0 commit comments

Comments
 (0)