Skip to content

Commit

Permalink
Rename sendEther to sendValue
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Oct 25, 2019
1 parent c87140a commit 4e57636
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### New features:
* `Address.toPayable`: added a helper to convert between address types without having to resort to low-level casting. ([#1773](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1773))
* Facilities to make metatransaction-enabled contracts through the Gas Station Network. ([#1844](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1844))
* `Address.sendEther`: added a replacement to Solidity's `transfer`, removing the fixed gas stipend. ([#1961](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1961))
* `Address.sendValue`: added a replacement to Solidity's `transfer`, removing the fixed gas stipend. ([#1961](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1961))

### Improvements:
* `Address.isContract`: switched from `extcodesize` to `extcodehash` for less gas usage. ([#1802](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1802))
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/AddressImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ contract AddressImpl {
return Address.toPayable(account);
}

function sendEther(address payable receiver, uint256 amount) external {
Address.sendEther(receiver, amount);
function sendValue(address payable receiver, uint256 amount) external {
Address.sendValue(receiver, amount);
}

function () external payable { } // sendEther's tests require the contract to hold Ether
function () external payable { } // sendValue's tests require the contract to hold Ether
}
8 changes: 4 additions & 4 deletions contracts/utils/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library Address {
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendEther} removes this limitation.
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
Expand All @@ -57,11 +57,11 @@ library Address {
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendEther(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: not enough ether to send");
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");

// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send ether");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
7 changes: 4 additions & 3 deletions test/utils/Address.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract('Address', function ([_, recipient, other]) {
});

it('reverts when sending non-zero amounts', async function () {
await expectRevert(this.mock.sendEther(other, 1), 'Address: not enough ether to send');
await expectRevert(this.mock.sendEther(other, 1), 'Address: insufficient balance');
});
});

Expand All @@ -77,7 +77,7 @@ contract('Address', function ([_, recipient, other]) {
});

it('reverts when sending more than the balance', async function () {
await expectRevert(this.mock.sendEther(recipient, funds.addn(1)), 'Address: not enough ether to send');
await expectRevert(this.mock.sendEther(recipient, funds.addn(1)), 'Address: insufficient balance');
});

context('with contract recipient', function () {
Expand All @@ -96,7 +96,8 @@ contract('Address', function ([_, recipient, other]) {
it('reverts on recipient revert', async function () {
await this.contractRecipient.setAcceptEther(false);
await expectRevert(
this.mock.sendEther(this.contractRecipient.address, funds), 'Address: unable to send ether'
this.mock.sendEther(this.contractRecipient.address, funds),
'Address: unable to send value, recipient may have reverted'
);
});
});
Expand Down

0 comments on commit 4e57636

Please sign in to comment.