From f5e354aa240e51195f29177aebdc2306ba6c0239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 25 Oct 2019 13:19:10 -0300 Subject: [PATCH] Rename sendEther to sendValue --- CHANGELOG.md | 2 +- contracts/mocks/AddressImpl.sol | 6 +++--- contracts/utils/Address.sol | 8 ++++---- test/utils/Address.test.js | 19 ++++++++++--------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f9e66407ff..b2b85952a20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/contracts/mocks/AddressImpl.sol b/contracts/mocks/AddressImpl.sol index 468a9a65c97..52563608f28 100644 --- a/contracts/mocks/AddressImpl.sol +++ b/contracts/mocks/AddressImpl.sol @@ -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 } diff --git a/contracts/utils/Address.sol b/contracts/utils/Address.sol index 55f753ebd43..c9e7711b355 100644 --- a/contracts/utils/Address.sol +++ b/contracts/utils/Address.sol @@ -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]. * @@ -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"); } } diff --git a/test/utils/Address.test.js b/test/utils/Address.test.js index 4f675c29dad..7013ed13a6e 100644 --- a/test/utils/Address.test.js +++ b/test/utils/Address.test.js @@ -37,20 +37,20 @@ contract('Address', function ([_, recipient, other]) { }); }); - describe('sendEther', function () { + describe('sendValue', function () { beforeEach(async function () { this.recipientTracker = await balance.tracker(recipient); }); context('when sender contract has no funds', function () { it('sends 0 wei', async function () { - await this.mock.sendEther(other, 0); + await this.mock.sendValue(other, 0); expect(await this.recipientTracker.delta()).to.be.bignumber.equal('0'); }); 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.sendValue(other, 1), 'Address: insufficient balance'); }); }); @@ -61,23 +61,23 @@ contract('Address', function ([_, recipient, other]) { }); it('sends 0 wei', async function () { - await this.mock.sendEther(recipient, 0); + await this.mock.sendValue(recipient, 0); expect(await this.recipientTracker.delta()).to.be.bignumber.equal('0'); }); it('sends non-zero amounts', async function () { - await this.mock.sendEther(recipient, funds.subn(1)); + await this.mock.sendValue(recipient, funds.subn(1)); expect(await this.recipientTracker.delta()).to.be.bignumber.equal(funds.subn(1)); }); it('sends the whole balance', async function () { - await this.mock.sendEther(recipient, funds); + await this.mock.sendValue(recipient, funds); expect(await this.recipientTracker.delta()).to.be.bignumber.equal(funds); expect(await balance.current(this.mock.address)).to.be.bignumber.equal('0'); }); 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.sendValue(recipient, funds.addn(1)), 'Address: insufficient balance'); }); context('with contract recipient', function () { @@ -89,14 +89,15 @@ contract('Address', function ([_, recipient, other]) { const tracker = await balance.tracker(this.contractRecipient.address); await this.contractRecipient.setAcceptEther(true); - await this.mock.sendEther(this.contractRecipient.address, funds); + await this.mock.sendValue(this.contractRecipient.address, funds); expect(await tracker.delta()).to.be.bignumber.equal(funds); }); 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.sendValue(this.contractRecipient.address, funds), + 'Address: unable to send value, recipient may have reverted' ); }); });