From 879251a78b2d4e26dc71299d2d7ca989d0855d61 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 12 Sep 2018 16:21:43 +0200 Subject: Update test suite to use address payable. --- test/compilationTests/corion/ico.sol | 14 ++--- test/compilationTests/corion/module.sol | 22 ++++---- test/compilationTests/corion/moduleHandler.sol | 8 +-- test/compilationTests/corion/premium.sol | 4 +- test/compilationTests/corion/provider.sol | 12 ++--- test/compilationTests/corion/publisher.sol | 8 +-- test/compilationTests/corion/schelling.sol | 6 +-- test/compilationTests/corion/token.sol | 8 +-- test/compilationTests/zeppelin/MultisigWallet.sol | 2 +- .../zeppelin/crowdsale/Crowdsale.sol | 4 +- .../zeppelin/crowdsale/RefundVault.sol | 8 +-- .../zeppelin/lifecycle/Destructible.sol | 2 +- .../zeppelin/ownership/Claimable.sol | 4 +- .../zeppelin/ownership/Ownable.sol | 4 +- .../zeppelin/payment/PullPayment.sol | 2 +- test/contracts/AuctionRegistrar.cpp | 8 +-- test/contracts/FixedFeeRegistrar.cpp | 2 +- test/contracts/Wallet.cpp | 2 +- test/libsolidity/SolidityEndToEndTest.cpp | 62 +++++++++++++++++++--- .../nameAndTypeResolution/413_address_methods.sol | 2 +- .../535_address_overload_resolution.sol | 2 + .../types/address/address_members_in_contract.sol | 6 +++ .../types/address/address_to_contract.sol | 6 +++ .../types/address/contract_to_address.sol | 7 +++ .../address/contract_to_address_implicitly.sol | 8 +++ .../types/address_members_in_contract.sol | 6 --- .../syntaxTests/types/address_to_contract.sol | 6 --- .../syntaxTests/types/contract_to_address.sol | 7 --- .../types/contract_to_address_implicitly.sol | 8 --- .../builtin_functions_view_fail.sol | 2 + 30 files changed, 148 insertions(+), 94 deletions(-) create mode 100644 test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol create mode 100644 test/libsolidity/syntaxTests/types/address/address_to_contract.sol create mode 100644 test/libsolidity/syntaxTests/types/address/contract_to_address.sol create mode 100644 test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol delete mode 100644 test/libsolidity/syntaxTests/types/address_members_in_contract.sol delete mode 100644 test/libsolidity/syntaxTests/types/address_to_contract.sol delete mode 100644 test/libsolidity/syntaxTests/types/contract_to_address.sol delete mode 100644 test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol (limited to 'test') diff --git a/test/compilationTests/corion/ico.sol b/test/compilationTests/corion/ico.sol index b1e0bf75..e660389b 100644 --- a/test/compilationTests/corion/ico.sol +++ b/test/compilationTests/corion/ico.sol @@ -27,12 +27,12 @@ contract ico is safeMath { uint256 constant oneSegment = 40320; - address public owner; - address public tokenAddr; - address public premiumAddr; + address payable public owner; + address payable public tokenAddr; + address payable public premiumAddr; uint256 public startBlock; uint256 public icoDelay; - address public foundationAddress; + address payable public foundationAddress; address public icoEtcPriceAddr; uint256 public icoExchangeRate; uint256 public icoExchangeRateSetBlock; @@ -50,7 +50,7 @@ contract ico is safeMath { uint256 public totalMint; uint256 public totalPremiumMint; - constructor(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] memory genesisAddr, uint256[] memory genesisValue) public { + constructor(address payable foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] memory genesisAddr, uint256[] memory genesisValue) public { /* Installation function. @@ -248,7 +248,7 @@ contract ico is safeMath { aborted = true; } - function connectTokens(address tokenContractAddr, address premiumContractAddr) external { + function connectTokens(address payable tokenContractAddr, address payable premiumContractAddr) external { /* Installation function which joins the two token contracts with this contract. Only callable by the owner @@ -284,7 +284,7 @@ contract ico is safeMath { require( buy(msg.sender, address(0x00)) ); } - function buy(address beneficiaryAddress, address affilateAddress) public payable returns (bool success) { + function buy(address payable beneficiaryAddress, address affilateAddress) public payable returns (bool success) { /* Buying a token diff --git a/test/compilationTests/corion/module.sol b/test/compilationTests/corion/module.sol index da4dd344..bd6952b1 100644 --- a/test/compilationTests/corion/module.sol +++ b/test/compilationTests/corion/module.sol @@ -1,8 +1,8 @@ pragma solidity ^0.4.11; contract abstractModuleHandler { - function transfer(address from, address to, uint256 value, bool fee) external returns (bool success) {} - function balanceOf(address owner) public view returns (bool success, uint256 value) {} + function transfer(address payable from, address payable to, uint256 value, bool fee) external returns (bool success) {} + function balanceOf(address payable owner) public view returns (bool success, uint256 value) {} } contract module { @@ -19,7 +19,7 @@ contract module { status public moduleStatus; uint256 public disabledUntil; - address public moduleHandlerAddress; + address payable public moduleHandlerAddress; function disableModule(bool forever) external onlyForModuleHandler returns (bool success) { _disableModule(forever); @@ -36,11 +36,11 @@ contract module { else { disabledUntil = block.number + 5760; } } - function replaceModuleHandler(address newModuleHandlerAddress) external onlyForModuleHandler returns (bool success) { + function replaceModuleHandler(address payable newModuleHandlerAddress) external onlyForModuleHandler returns (bool success) { _replaceModuleHandler(newModuleHandlerAddress); return true; } - function _replaceModuleHandler(address newModuleHandlerAddress) internal { + function _replaceModuleHandler(address payable newModuleHandlerAddress) internal { /* Replace the ModuleHandler address. This function calls the Publisher module. @@ -77,11 +77,11 @@ contract module { moduleStatus = status.Disconnected; } - function replaceModule(address newModuleAddress) external onlyForModuleHandler returns (bool success) { + function replaceModule(address payable newModuleAddress) external onlyForModuleHandler returns (bool success) { _replaceModule(newModuleAddress); return true; } - function _replaceModule(address newModuleAddress) internal { + function _replaceModule(address payable newModuleAddress) internal { /* Replace the module for an another new module. This function calls the Publisher module. @@ -101,20 +101,20 @@ contract module { moduleStatus = status.Disconnected; } - function transferEvent(address from, address to, uint256 value) external onlyForModuleHandler returns (bool success) { + function transferEvent(address payable from, address payable to, uint256 value) external onlyForModuleHandler returns (bool success) { return true; } function newSchellingRoundEvent(uint256 roundID, uint256 reward) external onlyForModuleHandler returns (bool success) { return true; } - function registerModuleHandler(address _moduleHandlerAddress) internal { + function registerModuleHandler(address payable _moduleHandlerAddress) internal { /* Module constructor function for registering ModuleHandler address. */ moduleHandlerAddress = _moduleHandlerAddress; } - function isModuleHandler(address addr) internal returns (bool ret) { + function isModuleHandler(address payable addr) internal returns (bool ret) { /* Test for ModuleHandler address. If the module is not connected then returns always false. @@ -140,4 +140,6 @@ contract module { require( msg.sender == moduleHandlerAddress ); _; } + function() external payable { + } } diff --git a/test/compilationTests/corion/moduleHandler.sol b/test/compilationTests/corion/moduleHandler.sol index 2b513eb1..6b0daf0d 100644 --- a/test/compilationTests/corion/moduleHandler.sol +++ b/test/compilationTests/corion/moduleHandler.sol @@ -25,7 +25,7 @@ contract abstractModule { contract moduleHandler is multiOwner, announcementTypes { struct modules_s { - address addr; + address payable addr; bytes32 name; bool schellingEvent; bool transferEvent; @@ -37,7 +37,7 @@ contract moduleHandler is multiOwner, announcementTypes { constructor(address[] memory newOwners) multiOwner(newOwners) public {} - function load(address foundation, bool forReplace, address Token, address Premium, address Publisher, address Schelling, address Provider) public { + function load(address payable foundation, bool forReplace, address payable Token, address payable Premium, address payable Publisher, address payable Schelling, address payable Provider) public { /* Loading modulest to ModuleHandler. @@ -140,7 +140,7 @@ contract moduleHandler is multiOwner, announcementTypes { } return (true, false, 0); } - function replaceModule(string calldata name, address addr, bool callCallback) external returns (bool success) { + function replaceModule(string calldata name, address payable addr, bool callCallback) external returns (bool success) { /* Module replace, can be called only by the Publisher contract. @@ -178,7 +178,7 @@ contract moduleHandler is multiOwner, announcementTypes { return true; } - function newModule(string calldata name, address addr, bool schellingEvent, bool transferEvent) external returns (bool success) { + function newModule(string calldata name, address payable addr, bool schellingEvent, bool transferEvent) external returns (bool success) { /* Adding new module to the database. Can be called only by the Publisher contract. diff --git a/test/compilationTests/corion/premium.sol b/test/compilationTests/corion/premium.sol index 84277a99..4952a740 100644 --- a/test/compilationTests/corion/premium.sol +++ b/test/compilationTests/corion/premium.sol @@ -12,7 +12,7 @@ contract thirdPartyPContractAbstract { contract ptokenDB is tokenDB {} contract premium is module, safeMath { - function replaceModule(address addr) external returns (bool success) { + function replaceModule(address payable addr) external returns (bool success) { require( super.isModuleHandler(msg.sender) ); require( db.replaceOwner(addr) ); super._replaceModule(addr); @@ -40,7 +40,7 @@ contract premium is module, safeMath { mapping(address => bool) public genesis; - constructor(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] memory genesisAddr, uint256[] memory genesisValue) public { + constructor(bool forReplace, address payable moduleHandler, address dbAddress, address icoContractAddr, address[] memory genesisAddr, uint256[] memory genesisValue) public { /* Setup function. If an ICOaddress is defined then the balance of the genesis addresses will be set as well. diff --git a/test/compilationTests/corion/provider.sol b/test/compilationTests/corion/provider.sol index 41857e54..b3b5e8ca 100644 --- a/test/compilationTests/corion/provider.sol +++ b/test/compilationTests/corion/provider.sol @@ -16,7 +16,7 @@ contract provider is module, safeMath, announcementTypes { require( _success ); return true; } - function transferEvent(address from, address to, uint256 value) external returns (bool success) { + function transferEvent(address payable from, address payable to, uint256 value) external returns (bool success) { /* Transaction completed. This function is only available for the modulehandler. It should be checked if the sender or the acceptor does not connect to the provider or it is not a provider itself if so than the change should be recorded. @@ -118,7 +118,7 @@ contract provider is module, safeMath, announcementTypes { uint256 private currentSchellingRound = 1; - constructor(address _moduleHandler) public { + constructor(address payable _moduleHandler) public { /* Install function. @@ -147,7 +147,7 @@ contract provider is module, safeMath, announcementTypes { else { return false; } return true; } - function getUserDetails(address addr, uint256 schellingRound) public view returns (address ProviderAddress, uint256 ProviderHeight, uint256 ConnectedOn, uint256 value) { + function getUserDetails(address payable addr, uint256 schellingRound) public view returns (address ProviderAddress, uint256 ProviderHeight, uint256 ConnectedOn, uint256 value) { /* Collecting the datas of the client. @@ -213,7 +213,7 @@ contract provider is module, safeMath, announcementTypes { return ( ! priv && ( rate >= publicMinRate && rate <= publicMaxRate ) ) || ( priv && ( rate >= privateMinRate && rate <= privateMaxRate ) ); } - function createProvider(bool priv, string calldata name, string calldata website, string calldata country, string calldata info, uint8 rate, bool isForRent, address admin) isReady external { + function createProvider(bool priv, string calldata name, string calldata website, string calldata country, string calldata info, uint8 rate, bool isForRent, address payable admin) isReady external { /* Creating a provider. During the ICO its not allowed to create provider. @@ -270,7 +270,7 @@ contract provider is module, safeMath, announcementTypes { } emit EProviderOpen(msg.sender, currHeight); } - function setProviderDetails(address addr, string calldata website, string calldata country, string calldata info, uint8 rate, address admin) isReady external { + function setProviderDetails(address payable addr, string calldata website, string calldata country, string calldata info, uint8 rate, address payable admin) isReady external { /* Modifying the datas of the provider. This can only be invited by the provider’s admin. @@ -321,7 +321,7 @@ contract provider is module, safeMath, announcementTypes { info = providers[addr].data[height].info; create = providers[addr].data[height].create; } - function getProviderDetails(address addr, uint256 height) public view returns (uint8 rate, bool isForRent, uint256 clientsCount, bool priv, bool getInterest, bool valid) { + function getProviderDetails(address payable addr, uint256 height) public view returns (uint8 rate, bool isForRent, uint256 clientsCount, bool priv, bool getInterest, bool valid) { /* Asking for the datas of the provider. In case the height is unknown then the system will use the last known height. diff --git a/test/compilationTests/corion/publisher.sol b/test/compilationTests/corion/publisher.sol index 6a77bc9e..48090d02 100644 --- a/test/compilationTests/corion/publisher.sol +++ b/test/compilationTests/corion/publisher.sol @@ -9,7 +9,7 @@ contract publisher is announcementTypes, module, safeMath { /* module callbacks */ - function transferEvent(address from, address to, uint256 value) external returns (bool success) { + function transferEvent(address payable from, address payable to, uint256 value) external returns (bool success) { /* Transaction completed. This function is available only for moduleHandler If a transaction is carried out from or to an address which participated in the objection of an announcement, its objection purport is automatically set @@ -54,14 +54,14 @@ contract publisher is announcementTypes, module, safeMath { string _str; uint256 _uint; - address _addr; + address payable _addr; } mapping(uint256 => announcements_s) public announcements; uint256 announcementsLength = 1; mapping (address => uint256[]) public opponents; - constructor(address moduleHandler) public { + constructor(address payable moduleHandler) public { /* Installation function. The installer will be registered in the admin list automatically @@ -116,7 +116,7 @@ contract publisher is announcementTypes, module, safeMath { return _amount * oppositeRate / 100 > weight; } - function newAnnouncement(announcementType Type, string calldata Announcement, string calldata Link, bool Oppositable, string calldata _str, uint256 _uint, address _addr) onlyOwner external { + function newAnnouncement(announcementType Type, string calldata Announcement, string calldata Link, bool Oppositable, string calldata _str, uint256 _uint, address payable _addr) onlyOwner external { /* New announcement. Can be called only by those in the admin list diff --git a/test/compilationTests/corion/schelling.sol b/test/compilationTests/corion/schelling.sol index e9288332..2a327ba0 100644 --- a/test/compilationTests/corion/schelling.sol +++ b/test/compilationTests/corion/schelling.sol @@ -133,13 +133,13 @@ contract schelling is module, announcementTypes, schellingVars { /* module callbacks */ - function replaceModule(address addr) external returns (bool) { + function replaceModule(address payable addr) external returns (bool) { require( super.isModuleHandler(msg.sender) ); require( db.replaceOwner(addr) ); super._replaceModule(addr); return true; } - function transferEvent(address from, address to, uint256 value) external returns (bool) { + function transferEvent(address payable from, address payable to, uint256 value) external returns (bool) { /* Transaction completed. This function can be called only by the ModuleHandler. If this contract is the receiver, the amount will be added to the prize pool of the current round. @@ -247,7 +247,7 @@ contract schelling is module, announcementTypes, schellingVars { bytes1 public belowChar = 0x30; schellingDB private db; - constructor(address _moduleHandler, address _db, bool _forReplace) public { + constructor(address payable _moduleHandler, address _db, bool _forReplace) public { /* Installation function. diff --git a/test/compilationTests/corion/token.sol b/test/compilationTests/corion/token.sol index 6d3f1a1e..f55dc9e6 100644 --- a/test/compilationTests/corion/token.sol +++ b/test/compilationTests/corion/token.sol @@ -15,7 +15,7 @@ contract token is safeMath, module, announcementTypes { /* module callbacks */ - function replaceModule(address addr) external returns (bool success) { + function replaceModule(address payable addr) external returns (bool success) { require( super.isModuleHandler(msg.sender) ); require( db.replaceOwner(addr) ); super._replaceModule(addr); @@ -37,18 +37,18 @@ contract token is safeMath, module, announcementTypes { uint8 public decimals = 6; tokenDB public db; - address public icoAddr; + address payable public icoAddr; uint256 public transactionFeeRate = 20; uint256 public transactionFeeRateM = 1e3; uint256 public transactionFeeMin = 20000; uint256 public transactionFeeMax = 5000000; uint256 public transactionFeeBurn = 80; - address public exchangeAddress; + address payable public exchangeAddress; bool public isICO = true; mapping(address => bool) public genesis; - constructor(bool forReplace, address moduleHandler, address dbAddr, address icoContractAddr, address exchangeContractAddress, address[] memory genesisAddr, uint256[] memory genesisValue) public payable { + constructor(bool forReplace, address payable moduleHandler, address dbAddr, address payable icoContractAddr, address payable exchangeContractAddress, address payable[] memory genesisAddr, uint256[] memory genesisValue) public payable { /* Installation function diff --git a/test/compilationTests/zeppelin/MultisigWallet.sol b/test/compilationTests/zeppelin/MultisigWallet.sol index abad0a01..74a54c7f 100644 --- a/test/compilationTests/zeppelin/MultisigWallet.sol +++ b/test/compilationTests/zeppelin/MultisigWallet.sol @@ -32,7 +32,7 @@ contract MultisigWallet is Multisig, Shareable, DayLimit { /** * @dev destroys the contract sending everything to `_to`. */ - function destroy(address _to) onlymanyowners(keccak256(msg.data)) external { + function destroy(address payable _to) onlymanyowners(keccak256(msg.data)) external { selfdestruct(_to); } diff --git a/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol b/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol index 51eeb7b8..612afc25 100644 --- a/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol +++ b/test/compilationTests/zeppelin/crowdsale/Crowdsale.sol @@ -22,7 +22,7 @@ contract Crowdsale { uint256 public endBlock; // address where funds are collected - address public wallet; + address payable public wallet; // how many token units a buyer gets per wei uint256 public rate; @@ -40,7 +40,7 @@ contract Crowdsale { event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount); - constructor(uint256 _startBlock, uint256 _endBlock, uint256 _rate, address _wallet) public { + constructor(uint256 _startBlock, uint256 _endBlock, uint256 _rate, address payable _wallet) public { require(_startBlock >= block.number); require(_endBlock >= _startBlock); require(_rate > 0); diff --git a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol index b7db8ef2..ef1d8061 100644 --- a/test/compilationTests/zeppelin/crowdsale/RefundVault.sol +++ b/test/compilationTests/zeppelin/crowdsale/RefundVault.sol @@ -15,20 +15,20 @@ contract RefundVault is Ownable { enum State { Active, Refunding, Closed } mapping (address => uint256) public deposited; - address public wallet; + address payable public wallet; State public state; event Closed(); event RefundsEnabled(); event Refunded(address indexed beneficiary, uint256 weiAmount); - constructor(address _wallet) public { + constructor(address payable _wallet) public { require(_wallet != address(0x0)); wallet = _wallet; state = State.Active; } - function deposit(address investor) public onlyOwner payable { + function deposit(address payable investor) public onlyOwner payable { require(state == State.Active); deposited[investor] = deposited[investor].add(msg.value); } @@ -46,7 +46,7 @@ contract RefundVault is Ownable { emit RefundsEnabled(); } - function refund(address investor) public { + function refund(address payable investor) public { require(state == State.Refunding); uint256 depositedValue = deposited[investor]; deposited[investor] = 0; diff --git a/test/compilationTests/zeppelin/lifecycle/Destructible.sol b/test/compilationTests/zeppelin/lifecycle/Destructible.sol index 8b57924d..9b9d8223 100644 --- a/test/compilationTests/zeppelin/lifecycle/Destructible.sol +++ b/test/compilationTests/zeppelin/lifecycle/Destructible.sol @@ -19,7 +19,7 @@ contract Destructible is Ownable { selfdestruct(owner); } - function destroyAndSend(address _recipient) public onlyOwner { + function destroyAndSend(address payable _recipient) public onlyOwner { selfdestruct(_recipient); } } diff --git a/test/compilationTests/zeppelin/ownership/Claimable.sol b/test/compilationTests/zeppelin/ownership/Claimable.sol index 7778e2de..148ad535 100644 --- a/test/compilationTests/zeppelin/ownership/Claimable.sol +++ b/test/compilationTests/zeppelin/ownership/Claimable.sol @@ -10,7 +10,7 @@ import './Ownable.sol'; * This allows the new owner to accept the transfer. */ contract Claimable is Ownable { - address public pendingOwner; + address payable public pendingOwner; /** * @dev Modifier throws if called by any account other than the pendingOwner. @@ -26,7 +26,7 @@ contract Claimable is Ownable { * @dev Allows the current owner to set the pendingOwner address. * @param newOwner The address to transfer ownership to. */ - function transferOwnership(address newOwner) public onlyOwner { + function transferOwnership(address payable newOwner) public onlyOwner { pendingOwner = newOwner; } diff --git a/test/compilationTests/zeppelin/ownership/Ownable.sol b/test/compilationTests/zeppelin/ownership/Ownable.sol index bd175077..3c95127d 100644 --- a/test/compilationTests/zeppelin/ownership/Ownable.sol +++ b/test/compilationTests/zeppelin/ownership/Ownable.sol @@ -7,7 +7,7 @@ pragma solidity ^0.4.11; * functions, this simplifies the implementation of "user permissions". */ contract Ownable { - address public owner; + address payable public owner; /** @@ -34,7 +34,7 @@ contract Ownable { * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ - function transferOwnership(address newOwner) public onlyOwner { + function transferOwnership(address payable newOwner) public onlyOwner { if (newOwner != address(0)) { owner = newOwner; } diff --git a/test/compilationTests/zeppelin/payment/PullPayment.sol b/test/compilationTests/zeppelin/payment/PullPayment.sol index bac1d019..5682d3c2 100644 --- a/test/compilationTests/zeppelin/payment/PullPayment.sol +++ b/test/compilationTests/zeppelin/payment/PullPayment.sol @@ -29,7 +29,7 @@ contract PullPayment { * @dev withdraw accumulated balance, called by payee. */ function withdrawPayments() public { - address payee = msg.sender; + address payable payee = msg.sender; uint256 payment = payments[payee]; if (payment == 0) { diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp index e178748f..70503605 100644 --- a/test/contracts/AuctionRegistrar.cpp +++ b/test/contracts/AuctionRegistrar.cpp @@ -66,7 +66,7 @@ contract AuctionSystem { /// Function that is called once an auction ends. function onAuctionEnd(string memory _name) internal; - function bid(string memory _name, address _bidder, uint _value) internal { + function bid(string memory _name, address payable _bidder, uint _value) internal { Auction storage auction = m_auctions[_name]; if (auction.endDate > 0 && now > auction.endDate) { @@ -91,7 +91,7 @@ contract AuctionSystem { uint constant c_biddingTime = 7 days; struct Auction { - address highestBidder; + address payable highestBidder; uint highestBid; uint secondHighestBid; uint sumOfBids; @@ -102,7 +102,7 @@ contract AuctionSystem { contract GlobalRegistrar is Registrar, AuctionSystem { struct Record { - address owner; + address payable owner; address primary; address subRegistrar; bytes32 content; @@ -156,7 +156,7 @@ contract GlobalRegistrar is Registrar, AuctionSystem { modifier onlyrecordowner(string memory _name) { if (m_toRecord[_name].owner == msg.sender) _; } - function transfer(string memory _name, address _newOwner) onlyrecordowner(_name) public { + function transfer(string memory _name, address payable _newOwner) onlyrecordowner(_name) public { m_toRecord[_name].owner = _newOwner; emit Changed(_name); } diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index 78db4761..ae921a96 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -81,7 +81,7 @@ contract FixedFeeRegistrar is Registrar { emit Changed(_name); } } - function disown(string memory _name, address _refund) onlyrecordowner(_name) public { + function disown(string memory _name, address payable _refund) onlyrecordowner(_name) public { delete m_recordData[uint(keccak256(bytes(_name))) / 8]; if (!_refund.send(c_fee)) revert(); diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index a2e764fb..e0e3045c 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -375,7 +375,7 @@ contract Wallet is multisig, multiowned, daylimit { } // destroys the contract sending everything to `_to`. - function kill(address _to) onlymanyowners(keccak256(msg.data)) external { + function kill(address payable _to) onlymanyowners(keccak256(msg.data)) external { selfdestruct(_to); } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 6be9d95b..642c9929 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2215,7 +2215,7 @@ BOOST_AUTO_TEST_CASE(send_ether) char const* sourceCode = R"( contract test { constructor() payable public {} - function a(address addr, uint amount) public returns (uint ret) { + function a(address payable addr, uint amount) public returns (uint ret) { addr.send(amount); return address(this).balance; } @@ -2233,11 +2233,11 @@ BOOST_AUTO_TEST_CASE(transfer_ether) char const* sourceCode = R"( contract A { constructor() public payable {} - function a(address addr, uint amount) public returns (uint) { + function a(address payable addr, uint amount) public returns (uint) { addr.transfer(amount); return address(this).balance; } - function b(address addr, uint amount) public { + function b(address payable addr, uint amount) public { addr.transfer(amount); } } @@ -2406,7 +2406,7 @@ BOOST_AUTO_TEST_CASE(selfdestruct) char const* sourceCode = R"( contract test { constructor() public payable {} - function a(address receiver) public returns (uint ret) { + function a(address payable receiver) public returns (uint ret) { selfdestruct(receiver); return 10; } @@ -7151,7 +7151,7 @@ BOOST_AUTO_TEST_CASE(failing_send) } contract Main { constructor() public payable {} - function callHelper(address _a) public returns (bool r, uint bal) { + function callHelper(address payable _a) public returns (bool r, uint bal) { r = !_a.send(5); bal = address(this).balance; } @@ -8838,7 +8838,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library) library lib {} contract c { constructor() public payable {} - function f(address x) public returns (bool) { + function f(address payable x) public returns (bool) { return x.send(1); } function () external payable {} @@ -10095,6 +10095,54 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types_shortening) ABI_CHECK(callContractFunction("f()"), encodeArgs("\xff\xff\xff\xff")); } +BOOST_AUTO_TEST_CASE(cleanup_address_types) +{ + // Checks that address types are properly cleaned before they are compared. + char const* sourceCode = R"( + contract C { + function f(address a) public returns (uint) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + function g(address payable a) public returns (uint) { + if (a != 0x1234567890123456789012345678901234567890) return 1; + return 0; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + // We input longer data on purpose. + ABI_CHECK(callContractFunction("f(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0)); + ABI_CHECK(callContractFunction("g(address)", u256("0xFFFF1234567890123456789012345678901234567890")), encodeArgs(0)); +} + +BOOST_AUTO_TEST_CASE(cleanup_address_types_shortening) +{ + char const* sourceCode = R"( + contract C { + function f() public pure returns (address r) { + bytes21 x = 0x1122334455667788990011223344556677889900ff; + bytes20 y; + assembly { y := x } + address z = address(y); + assembly { r := z } + require(z == 0x1122334455667788990011223344556677889900); + } + function g() public pure returns (address payable r) { + bytes21 x = 0x1122334455667788990011223344556677889900ff; + bytes20 y; + assembly { y := x } + address payable z = address(y); + assembly { r := z } + require(z == 0x1122334455667788990011223344556677889900); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + ABI_CHECK(callContractFunction("f()"), encodeArgs(u256("0x1122334455667788990011223344556677889900"))); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256("0x1122334455667788990011223344556677889900"))); +} + BOOST_AUTO_TEST_CASE(skip_dynamic_types) { // The EVM cannot provide access to dynamically-sized return values, so we have to skip them. @@ -12446,7 +12494,7 @@ BOOST_AUTO_TEST_CASE(interface_contract) } contract C { - function f(address _interfaceAddress) public returns (bool) { + function f(address payable _interfaceAddress) public returns (bool) { I i = I(_interfaceAddress); return i.f(); } diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol index b63d2a55..ad57224c 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/413_address_methods.sol @@ -1,6 +1,6 @@ contract C { function f() public { - address addr; + address payable addr; uint balance = addr.balance; (bool callSuc,) = addr.call(""); (bool delegatecallSuc,) = addr.delegatecall(""); diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol index 157ea36b..01b7b294 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol @@ -6,6 +6,8 @@ contract C { function transfer(uint amount) public { address(this).transfer(amount); // to avoid pureness warning } + function() payable external { + } } contract D { function f() public { diff --git a/test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol b/test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol new file mode 100644 index 00000000..eafc8268 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_members_in_contract.sol @@ -0,0 +1,6 @@ +contract C { + function f() public returns (C) { return this; } + function g() public returns (uint) { return f().balance(); } +} +// ---- +// TypeError: (114-125): Member "balance" not found or not visible after argument-dependent lookup in contract C. Use "address(...).balance" to access this address member. diff --git a/test/libsolidity/syntaxTests/types/address/address_to_contract.sol b/test/libsolidity/syntaxTests/types/address/address_to_contract.sol new file mode 100644 index 00000000..629a3df0 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_to_contract.sol @@ -0,0 +1,6 @@ +contract C { + function f() public pure returns (C c) { + c = C(address(2)); + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/contract_to_address.sol b/test/libsolidity/syntaxTests/types/address/contract_to_address.sol new file mode 100644 index 00000000..ec2f8184 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_to_address.sol @@ -0,0 +1,7 @@ +contract C { + function f() public view { + address a = address(this); + a; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol b/test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol new file mode 100644 index 00000000..8be9daac --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_to_address_implicitly.sol @@ -0,0 +1,8 @@ +contract C { + function f() public view { + address a = this; + a; + } +} +// ---- +// TypeError: (46-62): Type contract C is not implicitly convertible to expected type address. diff --git a/test/libsolidity/syntaxTests/types/address_members_in_contract.sol b/test/libsolidity/syntaxTests/types/address_members_in_contract.sol deleted file mode 100644 index eafc8268..00000000 --- a/test/libsolidity/syntaxTests/types/address_members_in_contract.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - function f() public returns (C) { return this; } - function g() public returns (uint) { return f().balance(); } -} -// ---- -// TypeError: (114-125): Member "balance" not found or not visible after argument-dependent lookup in contract C. Use "address(...).balance" to access this address member. diff --git a/test/libsolidity/syntaxTests/types/address_to_contract.sol b/test/libsolidity/syntaxTests/types/address_to_contract.sol deleted file mode 100644 index 629a3df0..00000000 --- a/test/libsolidity/syntaxTests/types/address_to_contract.sol +++ /dev/null @@ -1,6 +0,0 @@ -contract C { - function f() public pure returns (C c) { - c = C(address(2)); - } -} -// ---- diff --git a/test/libsolidity/syntaxTests/types/contract_to_address.sol b/test/libsolidity/syntaxTests/types/contract_to_address.sol deleted file mode 100644 index ec2f8184..00000000 --- a/test/libsolidity/syntaxTests/types/contract_to_address.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - function f() public view { - address a = address(this); - a; - } -} -// ---- diff --git a/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol b/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol deleted file mode 100644 index 8be9daac..00000000 --- a/test/libsolidity/syntaxTests/types/contract_to_address_implicitly.sol +++ /dev/null @@ -1,8 +0,0 @@ -contract C { - function f() public view { - address a = this; - a; - } -} -// ---- -// TypeError: (46-62): Type contract C is not implicitly convertible to expected type address. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol index f951feb4..5356f0b8 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol @@ -16,6 +16,8 @@ contract C { (bool success,) = address(this).call(""); require(success); } + function() payable external { + } } // ---- // TypeError: (52-77): Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. -- cgit