From 77cc33fc5c4d0b0d03aec1d8bba77edc9a7196ae Mon Sep 17 00:00:00 2001 From: Radek Ostrowski Date: Sat, 21 Apr 2018 05:01:05 +1000 Subject: [PATCH 1/8] cleaned up unsued variable definition (#753) --- contracts/token/ERC20/BasicToken.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/BasicToken.sol b/contracts/token/ERC20/BasicToken.sol index bdcf58c9d..905128fa2 100644 --- a/contracts/token/ERC20/BasicToken.sol +++ b/contracts/token/ERC20/BasicToken.sol @@ -43,7 +43,7 @@ contract BasicToken is ERC20Basic { * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ - function balanceOf(address _owner) public view returns (uint256 balance) { + function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } From 16535fbb87136eb22edc591e3e40d87826b33baa Mon Sep 17 00:00:00 2001 From: Elie Date: Mon, 23 Apr 2018 14:39:34 +0300 Subject: [PATCH 2/8] Update ERC827.sol to not use function overloading (#871) * Update ERC827.sol to not use function overloading * updated tests for erc827 function name changes * fixed broken test * removed findMethod from erc827 tests that is no longer necessary --- contracts/token/ERC827/ERC827.sol | 6 +- contracts/token/ERC827/ERC827Token.sol | 10 +-- test/token/ERC827/ERC827Token.js | 117 +++++-------------------- 3 files changed, 29 insertions(+), 104 deletions(-) diff --git a/contracts/token/ERC827/ERC827.sol b/contracts/token/ERC827/ERC827.sol index a0ee18036..83187f90f 100644 --- a/contracts/token/ERC827/ERC827.sol +++ b/contracts/token/ERC827/ERC827.sol @@ -12,9 +12,9 @@ import "../ERC20/ERC20.sol"; * @dev approvals. */ contract ERC827 is ERC20 { - function approve(address _spender, uint256 _value, bytes _data) public returns (bool); - function transfer(address _to, uint256 _value, bytes _data) public returns (bool); - function transferFrom( + function approveAndCall( address _spender, uint256 _value, bytes _data) public returns (bool); + function transferAndCall( address _to, uint256 _value, bytes _data) public returns (bool); + function transferFromAndCall( address _from, address _to, uint256 _value, diff --git a/contracts/token/ERC827/ERC827Token.sol b/contracts/token/ERC827/ERC827Token.sol index 28dbfceea..28e15d08f 100644 --- a/contracts/token/ERC827/ERC827Token.sol +++ b/contracts/token/ERC827/ERC827Token.sol @@ -34,7 +34,7 @@ contract ERC827Token is ERC827, StandardToken { * * @return true if the call function was executed successfully */ - function approve(address _spender, uint256 _value, bytes _data) public returns (bool) { + function approveAndCall(address _spender, uint256 _value, bytes _data) public returns (bool) { require(_spender != address(this)); super.approve(_spender, _value); @@ -54,7 +54,7 @@ contract ERC827Token is ERC827, StandardToken { * * @return true if the call function was executed successfully */ - function transfer(address _to, uint256 _value, bytes _data) public returns (bool) { + function transferAndCall(address _to, uint256 _value, bytes _data) public returns (bool) { require(_to != address(this)); super.transfer(_to, _value); @@ -74,7 +74,7 @@ contract ERC827Token is ERC827, StandardToken { * * @return true if the call function was executed successfully */ - function transferFrom( + function transferFromAndCall( address _from, address _to, uint256 _value, @@ -103,7 +103,7 @@ contract ERC827Token is ERC827, StandardToken { * @param _addedValue The amount of tokens to increase the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ - function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) { + function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public returns (bool) { require(_spender != address(this)); super.increaseApproval(_spender, _addedValue); @@ -126,7 +126,7 @@ contract ERC827Token is ERC827, StandardToken { * @param _subtractedValue The amount of tokens to decrease the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ - function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) { + function decreaseApprovalAndCall(address _spender, uint _subtractedValue, bytes _data) public returns (bool) { require(_spender != address(this)); super.decreaseApproval(_spender, _subtractedValue); diff --git a/test/token/ERC827/ERC827Token.js b/test/token/ERC827/ERC827Token.js index f82f3fdf0..7302d3a2d 100644 --- a/test/token/ERC827/ERC827Token.js +++ b/test/token/ERC827/ERC827Token.js @@ -4,8 +4,6 @@ var Message = artifacts.require('MessageHelper'); var ERC827TokenMock = artifacts.require('ERC827TokenMock'); var BigNumber = web3.BigNumber; -var _ = require('lodash'); -var ethjsABI = require('ethjs-abi'); require('chai') .use(require('chai-as-promised')) .use(require('chai-bignumber')(BigNumber)) @@ -14,15 +12,6 @@ require('chai') contract('ERC827 Token', function (accounts) { let token; - function findMethod (abi, name, args) { - for (var i = 0; i < abi.length; i++) { - const methodArgs = _.map(abi[i].inputs, 'type').join(','); - if ((abi[i].name === name) && (methodArgs === args)) { - return abi[i]; - } - } - } - beforeEach(async function () { token = await ERC827TokenMock.new(accounts[0], 100); }); @@ -94,13 +83,7 @@ contract('ERC827 Token', function (accounts) { }); it('should increase by 50 then decrease by 10', async function () { - const abiMethod = findMethod(token.abi, 'increaseApproval', 'address,uint256'); - const increaseApprovalData = ethjsABI.encodeMethod(abiMethod, - [accounts[1], 50] - ); - await token.sendTransaction( - { from: accounts[0], data: increaseApprovalData } - ); + await token.increaseApproval(accounts[1], 50); let postIncrease = await token.allowance(accounts[0], accounts[1]); preApproved.plus(50).should.be.bignumber.equal(postIncrease); await token.decreaseApproval(accounts[1], 10); @@ -135,13 +118,8 @@ contract('ERC827 Token', function (accounts) { const extraData = message.contract.showMessage.getData( web3.toHex(123456), 666, 'Transfer Done' ); - const abiMethod = findMethod(token.abi, 'transfer', 'address,uint256,bytes'); - const transferData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 100, extraData] - ); - const transaction = await token.sendTransaction( - { from: accounts[0], data: transferData } - ); + + const transaction = await token.transferAndCall(message.contract.address, 100, extraData); assert.equal(2, transaction.receipt.logs.length); @@ -159,13 +137,7 @@ contract('ERC827 Token', function (accounts) { web3.toHex(123456), 666, 'Transfer Done' ); - const abiMethod = findMethod(token.abi, 'approve', 'address,uint256,bytes'); - const approveData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 100, extraData] - ); - const transaction = await token.sendTransaction( - { from: accounts[0], data: approveData } - ); + const transaction = await token.approveAndCall(message.contract.address, 100, extraData); assert.equal(2, transaction.receipt.logs.length); @@ -188,13 +160,7 @@ contract('ERC827 Token', function (accounts) { await token.allowance(accounts[0], message.contract.address) ); - const abiMethod = findMethod(token.abi, 'increaseApproval', 'address,uint256,bytes'); - const increaseApprovalData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 50, extraData] - ); - const transaction = await token.sendTransaction( - { from: accounts[0], data: increaseApprovalData } - ); + const transaction = await token.increaseApprovalAndCall(message.contract.address, 50, extraData); assert.equal(2, transaction.receipt.logs.length); @@ -218,13 +184,7 @@ contract('ERC827 Token', function (accounts) { web3.toHex(123456), 666, 'Transfer Done' ); - const abiMethod = findMethod(token.abi, 'decreaseApproval', 'address,uint256,bytes'); - const decreaseApprovalData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 60, extraData] - ); - const transaction = await token.sendTransaction( - { from: accounts[0], data: decreaseApprovalData } - ); + const transaction = await token.decreaseApprovalAndCall(message.contract.address, 60, extraData); assert.equal(2, transaction.receipt.logs.length); @@ -248,13 +208,9 @@ contract('ERC827 Token', function (accounts) { await token.allowance(accounts[0], accounts[1]) ); - const abiMethod = findMethod(token.abi, 'transferFrom', 'address,address,uint256,bytes'); - const transferFromData = ethjsABI.encodeMethod(abiMethod, - [accounts[0], message.contract.address, 100, extraData] - ); - const transaction = await token.sendTransaction( - { from: accounts[1], data: transferFromData } - ); + const transaction = await token.transferFromAndCall(accounts[0], message.contract.address, 100, extraData, { + from: accounts[1], + }); assert.equal(2, transaction.receipt.logs.length); @@ -268,13 +224,8 @@ contract('ERC827 Token', function (accounts) { const extraData = message.contract.fail.getData(); - const abiMethod = findMethod(token.abi, 'approve', 'address,uint256,bytes'); - const approveData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 10, extraData] - ); - await token.sendTransaction( - { from: accounts[0], data: approveData } - ).should.be.rejectedWith(EVMRevert); + await token.approveAndCall(message.contract.address, 10, extraData) + .should.be.rejectedWith(EVMRevert); // approval should not have gone through so allowance is still 0 new BigNumber(0).should.be.bignumber @@ -286,13 +237,8 @@ contract('ERC827 Token', function (accounts) { const extraData = message.contract.fail.getData(); - const abiMethod = findMethod(token.abi, 'transfer', 'address,uint256,bytes'); - const transferData = ethjsABI.encodeMethod(abiMethod, - [message.contract.address, 10, extraData] - ); - await token.sendTransaction( - { from: accounts[0], data: transferData } - ).should.be.rejectedWith(EVMRevert); + await token.transferAndCall(message.contract.address, 10, extraData) + .should.be.rejectedWith(EVMRevert); // transfer should not have gone through, so balance is still 0 new BigNumber(0).should.be.bignumber @@ -305,14 +251,8 @@ contract('ERC827 Token', function (accounts) { const extraData = message.contract.fail.getData(); await token.approve(accounts[1], 10, { from: accounts[2] }); - - const abiMethod = findMethod(token.abi, 'transferFrom', 'address,address,uint256,bytes'); - const transferFromData = ethjsABI.encodeMethod(abiMethod, - [accounts[2], message.contract.address, 10, extraData] - ); - await token.sendTransaction( - { from: accounts[1], data: transferFromData } - ).should.be.rejectedWith(EVMRevert); + await token.transferFromAndCall(accounts[2], message.contract.address, 10, extraData, { from: accounts[1] }) + .should.be.rejectedWith(EVMRevert); // transferFrom should have failed so balance is still 0 but allowance is 10 new BigNumber(10).should.be.bignumber @@ -328,13 +268,8 @@ contract('ERC827 Token', function (accounts) { web3.toHex(123456), 666, 'Transfer Done' ); - const abiMethod = findMethod(token.abi, 'approve', 'address,uint256,bytes'); - const approveData = ethjsABI.encodeMethod(abiMethod, - [token.contract.address, 100, extraData] - ); - await token.sendTransaction( - { from: accounts[0], data: approveData } - ).should.be.rejectedWith(EVMRevert); + await token.approveAndCall(token.contract.address, 100, extraData, { from: accounts[0] }) + .should.be.rejectedWith(EVMRevert); }); it('should fail transfer (with data) when using token contract address as receiver', async function () { @@ -344,13 +279,8 @@ contract('ERC827 Token', function (accounts) { web3.toHex(123456), 666, 'Transfer Done' ); - const abiMethod = findMethod(token.abi, 'transfer', 'address,uint256,bytes'); - const transferData = ethjsABI.encodeMethod(abiMethod, - [token.contract.address, 100, extraData] - ); - await token.sendTransaction( - { from: accounts[0], data: transferData } - ).should.be.rejectedWith(EVMRevert); + await token.transferAndCall(token.contract.address, 100, extraData) + .should.be.rejectedWith(EVMRevert); }); it('should fail transferFrom (with data) when using token contract address as receiver', async function () { @@ -362,13 +292,8 @@ contract('ERC827 Token', function (accounts) { await token.approve(accounts[1], 1, { from: accounts[0] }); - const abiMethod = findMethod(token.abi, 'transferFrom', 'address,address,uint256,bytes'); - const transferFromData = ethjsABI.encodeMethod(abiMethod, - [accounts[0], token.contract.address, 1, extraData] - ); - await token.sendTransaction( - { from: accounts[1], data: transferFromData } - ).should.be.rejectedWith(EVMRevert); + await token.transferFromAndCall(accounts[0], token.contract.address, 1, extraData, { from: accounts[1] }) + .should.be.rejectedWith(EVMRevert); }); }); }); From 8f2a4785cb8a772fc0d84d8dd494879e591c6254 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Mon, 23 Apr 2018 16:16:55 +0300 Subject: [PATCH 3/8] Make ERC827 methods payable (#838) * Make ERC827 methods payable * Suppress linter errors * Add some ERC827 payable tests * Remove failOnBuy method from MessageHelper * Fix linter warning * Fix tests --- contracts/mocks/MessageHelper.sol | 10 ++ contracts/token/ERC827/ERC827.sol | 5 +- contracts/token/ERC827/ERC827Token.sol | 25 ++-- test/token/ERC827/ERC827Token.js | 190 +++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 12 deletions(-) diff --git a/contracts/mocks/MessageHelper.sol b/contracts/mocks/MessageHelper.sol index b44b6496a..97caf9899 100644 --- a/contracts/mocks/MessageHelper.sol +++ b/contracts/mocks/MessageHelper.sol @@ -4,12 +4,22 @@ pragma solidity ^0.4.21; contract MessageHelper { event Show(bytes32 b32, uint256 number, string text); + event Buy(bytes32 b32, uint256 number, string text, uint256 value); function showMessage( bytes32 message, uint256 number, string text ) public returns (bool) { emit Show(message, number, text); return true; } + function buyMessage( bytes32 message, uint256 number, string text ) public payable returns (bool) { + emit Buy( + message, + number, + text, + msg.value); + return true; + } + function fail() public { require(false); } diff --git a/contracts/token/ERC827/ERC827.sol b/contracts/token/ERC827/ERC827.sol index 83187f90f..a3ec481ea 100644 --- a/contracts/token/ERC827/ERC827.sol +++ b/contracts/token/ERC827/ERC827.sol @@ -12,8 +12,8 @@ import "../ERC20/ERC20.sol"; * @dev approvals. */ contract ERC827 is ERC20 { - function approveAndCall( address _spender, uint256 _value, bytes _data) public returns (bool); - function transferAndCall( address _to, uint256 _value, bytes _data) public returns (bool); + function approveAndCall( address _spender, uint256 _value, bytes _data) public payable returns (bool); + function transferAndCall( address _to, uint256 _value, bytes _data) public payable returns (bool); function transferFromAndCall( address _from, address _to, @@ -21,5 +21,6 @@ contract ERC827 is ERC20 { bytes _data ) public + payable returns (bool); } diff --git a/contracts/token/ERC827/ERC827Token.sol b/contracts/token/ERC827/ERC827Token.sol index 28e15d08f..c8c7eee84 100644 --- a/contracts/token/ERC827/ERC827Token.sol +++ b/contracts/token/ERC827/ERC827Token.sol @@ -34,12 +34,13 @@ contract ERC827Token is ERC827, StandardToken { * * @return true if the call function was executed successfully */ - function approveAndCall(address _spender, uint256 _value, bytes _data) public returns (bool) { + function approveAndCall(address _spender, uint256 _value, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.approve(_spender, _value); - require(_spender.call(_data)); + // solium-disable-next-line security/no-call-value + require(_spender.call.value(msg.value)(_data)); return true; } @@ -54,12 +55,13 @@ contract ERC827Token is ERC827, StandardToken { * * @return true if the call function was executed successfully */ - function transferAndCall(address _to, uint256 _value, bytes _data) public returns (bool) { + function transferAndCall(address _to, uint256 _value, bytes _data) public payable returns (bool) { require(_to != address(this)); super.transfer(_to, _value); - require(_to.call(_data)); + // solium-disable-next-line security/no-call-value + require(_to.call.value(msg.value)(_data)); return true; } @@ -80,13 +82,14 @@ contract ERC827Token is ERC827, StandardToken { uint256 _value, bytes _data ) - public returns (bool) + public payable returns (bool) { require(_to != address(this)); super.transferFrom(_from, _to, _value); - require(_to.call(_data)); + // solium-disable-next-line security/no-call-value + require(_to.call.value(msg.value)(_data)); return true; } @@ -103,12 +106,13 @@ contract ERC827Token is ERC827, StandardToken { * @param _addedValue The amount of tokens to increase the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ - function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public returns (bool) { + function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.increaseApproval(_spender, _addedValue); - require(_spender.call(_data)); + // solium-disable-next-line security/no-call-value + require(_spender.call.value(msg.value)(_data)); return true; } @@ -126,12 +130,13 @@ contract ERC827Token is ERC827, StandardToken { * @param _subtractedValue The amount of tokens to decrease the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ - function decreaseApprovalAndCall(address _spender, uint _subtractedValue, bytes _data) public returns (bool) { + function decreaseApprovalAndCall(address _spender, uint _subtractedValue, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.decreaseApproval(_spender, _subtractedValue); - require(_spender.call(_data)); + // solium-disable-next-line security/no-call-value + require(_spender.call.value(msg.value)(_data)); return true; } diff --git a/test/token/ERC827/ERC827Token.js b/test/token/ERC827/ERC827Token.js index 7302d3a2d..3cfed9683 100644 --- a/test/token/ERC827/ERC827Token.js +++ b/test/token/ERC827/ERC827Token.js @@ -110,6 +110,196 @@ contract('ERC827 Token', function (accounts) { }); describe('Test ERC827 methods', function () { + it( + 'should allow payment through transfer' + , async function () { + const message = await Message.new(); + + const extraData = message.contract.buyMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + const transaction = await token.transferAndCall( + message.contract.address, 100, extraData, { from: accounts[0], value: 1000 } + ); + + assert.equal(2, transaction.receipt.logs.length); + + new BigNumber(100).should.be.bignumber.equal( + await token.balanceOf(message.contract.address) + ); + new BigNumber(1000).should.be.bignumber.equal( + await web3.eth.getBalance(message.contract.address) + ); + }); + + it( + 'should allow payment through approve' + , async function () { + const message = await Message.new(); + + const extraData = message.contract.buyMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + const transaction = await token.approveAndCall( + message.contract.address, 100, extraData, { from: accounts[0], value: 1000 } + ); + + assert.equal(2, transaction.receipt.logs.length); + + new BigNumber(100).should.be.bignumber.equal( + await token.allowance(accounts[0], message.contract.address) + ); + new BigNumber(1000).should.be.bignumber.equal( + await web3.eth.getBalance(message.contract.address) + ); + }); + + it( + 'should allow payment through increaseApproval' + , async function () { + const message = await Message.new(); + + const extraData = message.contract.buyMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + await token.approve(message.contract.address, 10); + new BigNumber(10).should.be.bignumber.equal( + await token.allowance(accounts[0], message.contract.address) + ); + + const transaction = await token.increaseApprovalAndCall( + message.contract.address, 50, extraData, { from: accounts[0], value: 1000 } + ); + + assert.equal(2, transaction.receipt.logs.length); + + new BigNumber(60).should.be.bignumber.equal( + await token.allowance(accounts[0], message.contract.address) + ); + new BigNumber(1000).should.be.bignumber.equal( + await web3.eth.getBalance(message.contract.address) + ); + }); + + it( + 'should allow payment through decreaseApproval' + , async function () { + const message = await Message.new(); + + await token.approve(message.contract.address, 100); + + new BigNumber(100).should.be.bignumber.equal( + await token.allowance(accounts[0], message.contract.address) + ); + + const extraData = message.contract.buyMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + const transaction = await token.decreaseApprovalAndCall( + message.contract.address, 60, extraData, { from: accounts[0], value: 1000 } + ); + + assert.equal(2, transaction.receipt.logs.length); + + new BigNumber(40).should.be.bignumber.equal( + await token.allowance(accounts[0], message.contract.address) + ); + new BigNumber(1000).should.be.bignumber.equal( + await web3.eth.getBalance(message.contract.address) + ); + }); + + it( + 'should allow payment through transferFrom' + , async function () { + const message = await Message.new(); + + const extraData = message.contract.buyMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + await token.approve(accounts[1], 100, { from: accounts[0] }); + + new BigNumber(100).should.be.bignumber.equal( + await token.allowance(accounts[0], accounts[1]) + ); + + const transaction = await token.transferFromAndCall( + accounts[0], message.contract.address, 100, extraData, { from: accounts[1], value: 1000 } + ); + + assert.equal(2, transaction.receipt.logs.length); + + new BigNumber(100).should.be.bignumber.equal( + await token.balanceOf(message.contract.address) + ); + new BigNumber(1000).should.be.bignumber.equal( + await web3.eth.getBalance(message.contract.address) + ); + }); + + it('should revert funds of failure inside approve (with data)', async function () { + const message = await Message.new(); + + const extraData = message.contract.showMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + await token.approveAndCall( + message.contract.address, 10, extraData, { from: accounts[0], value: 1000 } + ).should.be.rejectedWith(EVMRevert); + + // approval should not have gone through so allowance is still 0 + new BigNumber(0).should.be.bignumber + .equal(await token.allowance(accounts[1], message.contract.address)); + new BigNumber(0).should.be.bignumber + .equal(await web3.eth.getBalance(message.contract.address)); + }); + + it('should revert funds of failure inside transfer (with data)', async function () { + const message = await Message.new(); + + const extraData = message.contract.showMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + await token.transferAndCall( + message.contract.address, 10, extraData, { from: accounts[0], value: 1000 } + ).should.be.rejectedWith(EVMRevert); + + // transfer should not have gone through, so balance is still 0 + new BigNumber(0).should.be.bignumber + .equal(await token.balanceOf(message.contract.address)); + new BigNumber(0).should.be.bignumber + .equal(await web3.eth.getBalance(message.contract.address)); + }); + + it('should revert funds of failure inside transferFrom (with data)', async function () { + const message = await Message.new(); + + const extraData = message.contract.showMessage.getData( + web3.toHex(123456), 666, 'Transfer Done' + ); + + await token.approve(accounts[1], 10, { from: accounts[2] }); + + await token.transferFromAndCall( + accounts[2], message.contract.address, 10, extraData, { from: accounts[2], value: 1000 } + ).should.be.rejectedWith(EVMRevert); + + // transferFrom should have failed so balance is still 0 but allowance is 10 + new BigNumber(10).should.be.bignumber + .equal(await token.allowance(accounts[2], accounts[1])); + new BigNumber(0).should.be.bignumber + .equal(await token.balanceOf(message.contract.address)); + new BigNumber(0).should.be.bignumber + .equal(await web3.eth.getBalance(message.contract.address)); + }); + it( 'should return correct balances after transfer (with data) and show the event on receiver contract' , async function () { From 76fe1548aee183dfcc395364f0745fe153a56141 Mon Sep 17 00:00:00 2001 From: Vittorio Minacori Date: Tue, 24 Apr 2018 01:36:47 +0200 Subject: [PATCH 4/8] Fix ERC721 test is not checking name and symbol properly #910 (#911) --- test/token/ERC721/ERC721Token.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/token/ERC721/ERC721Token.test.js b/test/token/ERC721/ERC721Token.test.js index a1aabc241..46e0cfc68 100644 --- a/test/token/ERC721/ERC721Token.test.js +++ b/test/token/ERC721/ERC721Token.test.js @@ -80,13 +80,13 @@ contract('ERC721Token', function (accounts) { const sampleUri = 'mock://mytoken'; it('has a name', async function () { - const name = await this.token.name(); - name.should.be.equal(name); + const tokenName = await this.token.name(); + tokenName.should.be.equal(name); }); it('has a symbol', async function () { - const symbol = await this.token.symbol(); - symbol.should.be.equal(symbol); + const tokenSymbol = await this.token.symbol(); + tokenSymbol.should.be.equal(symbol); }); it('sets and returns metadata for a token id', async function () { From 9c262571aea52cbb877ab18bd75f21b5b4cc7797 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 25 Apr 2018 15:03:20 -0300 Subject: [PATCH 5/8] rename to openzeppelin-solidity --- CONTRIBUTING.md | 14 +++++++------- README.md | 22 +++++++++++----------- contracts/token/ERC20/MintableToken.sol | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 57a387830..9a62762f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ We really appreciate and value contributions to OpenZeppelin. Please take 5' to ## Contribution guidelines -Smart contracts manage value and are highly vulnerable to errors and attacks. We have very strict guidelines, please make sure to review them: ["Contribution guidelines wiki entry"](https://github.com/OpenZeppelin/zeppelin-solidity/wiki/Contribution-guidelines). +Smart contracts manage value and are highly vulnerable to errors and attacks. We have very strict guidelines, please make sure to review them: ["Contribution guidelines wiki entry"](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/Contribution-guidelines). ## Creating Pull Requests (PRs) @@ -13,19 +13,19 @@ As a contributor, you are expected to fork this repository, work on your own for *IMPORTANT* * Please use `rebase` instead of `merge` when updating your fork. -* Please see ["Git flow wiki entry"](https://github.com/OpenZeppelin/zeppelin-solidity/wiki/Git-flow) for understanding how to use branches in this repository. +* Please see ["Git flow wiki entry"](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/Git-flow) for understanding how to use branches in this repository. ## A typical workflow 1) Make sure your fork is up to date with the main repository: ``` -cd zeppelin-solidity +cd openzeppelin-solidity git fetch upstream git checkout development git pull --rebase upstream development ``` -NOTE: The directory `zeppelin-solidity` represents your fork's local copy. +NOTE: The directory `openzeppelin-solidity` represents your fork's local copy. 2) Branch out from `development` into `fix/some-bug-#123`: (Postfixing #123 will associate your PR with the issue #123 and make everyone's life easier =D) @@ -41,7 +41,7 @@ git commit "Fix some bug #123" git push origin fix/some-bug-#123 ``` -4) Go to [github.com/OpenZeppelin/zeppelin-solidity](https://github.com/OpenZeppelin/zeppelin-solidity) in your web browser and issue a new pull request. +4) Go to [github.com/OpenZeppelin/openzeppelin-solidity](https://github.com/OpenZeppelin/zeppelin-solidity) in your web browser and issue a new pull request. *IMPORTANT* Read the PR template very carefully and make sure to follow all the instructions. These instructions refer to some very important conditions that your PR must meet in order to be accepted, such as making sure that all tests pass, JS linting tests pass, solidity linting tests pass, etc. @@ -52,8 +52,8 @@ refer to some very important conditions that your PR must meet in order to be ac ## All set! -If you have any questions feel free to post them to github.com/OpenZeppelin/zeppelin-solidity/issues. +If you have any questions feel free to post them to github.com/OpenZeppelin/openzeppelin-solidity/issues. -Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as ["Good first issue"](https://github.com/OpenZeppelin/zeppelin-solidity/labels/good%20first%20issue). +Finally, if you're looking to collaborate and want to find easy tasks to start, look at the issues we marked as ["Good first issue"](https://github.com/OpenZeppelin/openzeppelin-solidity/labels/good%20first%20issue). Thanks for your time and code! diff --git a/README.md b/README.md index 45710fe97..214d86ecb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Zeppelin Solidity -[![NPM Package](https://img.shields.io/npm/v/zeppelin-solidity.svg?style=flat-square)](https://www.npmjs.org/package/zeppelin-solidity) -[![Build Status](https://img.shields.io/travis/OpenZeppelin/zeppelin-solidity.svg?branch=master&style=flat-square)](https://travis-ci.org/OpenZeppelin/zeppelin-solidity) -[![Coverage Status](https://img.shields.io/coveralls/github/OpenZeppelin/zeppelin-solidity/master.svg?style=flat-square)](https://coveralls.io/github/OpenZeppelin/zeppelin-solidity?branch=master) +# OpenZeppelin Solidity +[![NPM Package](https://img.shields.io/npm/v/openzeppelin-solidity.svg?style=flat-square)](https://www.npmjs.org/package/openzeppelin-solidity) +[![Build Status](https://img.shields.io/travis/OpenZeppelin/openzeppelin-solidity.svg?branch=master&style=flat-square)](https://travis-ci.org/OpenZeppelin/openzeppelin-solidity) +[![Coverage Status](https://img.shields.io/coveralls/github/OpenZeppelin/openzeppelin-solidity/master.svg?style=flat-square)](https://coveralls.io/github/OpenZeppelin/openzeppelin-solidity?branch=master) OpenZeppelin is a library for writing secure [Smart Contracts](https://en.wikipedia.org/wiki/Smart_contract) on Ethereum. @@ -24,15 +24,15 @@ truffle init To install the OpenZeppelin library, run the following in your Solidity project root directory: ```sh npm init -y -npm install -E zeppelin-solidity +npm install -E openzeppelin-solidity ``` **Note that OpenZeppelin does not currently follow semantic versioning.** You may encounter breaking changes upon a minor version bump. We recommend pinning the version of OpenZeppelin you use, as done by the `-E` (`--save-exact`) option. -After that, you'll get all the library's contracts in the `node_modules/zeppelin-solidity/contracts` folder. You can use the contracts in the library like so: +After that, you'll get all the library's contracts in the `node_modules/openzeppelin-solidity/contracts` folder. You can use the contracts in the library like so: ```js -import 'zeppelin-solidity/contracts/ownership/Ownable.sol'; +import 'openzeppelin-solidity/contracts/ownership/Ownable.sol'; contract MyContract is Ownable { ... @@ -56,9 +56,9 @@ Building a distributed application, protocol or organization with OpenZeppelin? Interested in contributing to OpenZeppelin? - Framework proposal and roadmap: https://medium.com/zeppelin-blog/zeppelin-framework-proposal-and-development-roadmap-fdfa9a3a32ab#.iain47pak -- Issue tracker: https://github.com/OpenZeppelin/zeppelin-solidity/issues -- Contribution guidelines: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/CONTRIBUTING.md -- Wiki: https://github.com/OpenZeppelin/zeppelin-solidity/wiki +- Issue tracker: https://github.com/OpenZeppelin/openzeppelin-solidity/issues +- Contribution guidelines: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md +- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki ## Collaborating organizations and audits by OpenZeppelin - [Golem](https://golem.network/) @@ -79,4 +79,4 @@ among others... ## License -Code released under the [MIT License](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/LICENSE). +Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE). diff --git a/contracts/token/ERC20/MintableToken.sol b/contracts/token/ERC20/MintableToken.sol index 21915ea15..b0ebf1de1 100644 --- a/contracts/token/ERC20/MintableToken.sol +++ b/contracts/token/ERC20/MintableToken.sol @@ -7,7 +7,7 @@ import "../../ownership/Ownable.sol"; /** * @title Mintable token * @dev Simple ERC20 Token example, with mintable token creation - * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 + * @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol */ contract MintableToken is StandardToken, Ownable { diff --git a/package-lock.json b/package-lock.json index a97ecfee1..2ad0d576b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "zeppelin-solidity", + "name": "openzeppelin-solidity", "version": "1.7.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index 360cc9b27..a72657d7b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "zeppelin-solidity", + "name": "openzeppelin-solidity", "version": "1.8.0", "description": "Secure Smart Contract library for Solidity", "scripts": { From 90413e75f11d57bfafcba72d752f9fe906a5f9f8 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 25 Apr 2018 20:32:09 -0300 Subject: [PATCH 6/8] add version script to update ethpm.json (#906) --- package.json | 3 ++- scripts/version.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 scripts/version.js diff --git a/package.json b/package.json index 613b38c8a..e69e50410 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "lint:all": "npm run lint && npm run lint:sol", "lint:all:fix": "npm run lint:fix && npm run lint:sol:fix", "console": "truffle console", - "coverage": "scripts/coverage.sh" + "coverage": "scripts/coverage.sh", + "version": "scripts/version.js" }, "repository": { "type": "git", diff --git a/scripts/version.js b/scripts/version.js new file mode 100755 index 000000000..1fcc07354 --- /dev/null +++ b/scripts/version.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +// Synchronizes ethpm.json version number with package.json. +// Useful to run as an npm script alogn with `npm version`. + +const fs = require('fs'); +const cp = require('child_process'); + +const pkg = require('../package.json'); +const ethpm = require('../ethpm.json'); + +ethpm.version = pkg.version; + +fs.writeFileSync('ethpm.json', JSON.stringify(ethpm, null, 2) + '\n'); + +cp.execSync('git add ethpm.json'); From 0e5799c93b81a58b1aab6f3684a9ca673185ed26 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 26 Apr 2018 12:36:41 -0300 Subject: [PATCH 7/8] Clean up npm package (#904) * ignore everything but official contracts for npm * add tests to npm package * remove truffle migrations stuff * remove seemingly unused npm dependency * clean up dependencies --- contracts/.npmignore | 2 ++ contracts/lifecycle/Migrations.sol | 21 --------------------- migrations/.gitkeep | 0 migrations/1_initial_migration.js | 5 ----- migrations/2_deploy_contracts.js | 9 --------- package-lock.json | 9 ++------- package.json | 9 +++++---- 7 files changed, 9 insertions(+), 46 deletions(-) create mode 100644 contracts/.npmignore delete mode 100644 contracts/lifecycle/Migrations.sol create mode 100644 migrations/.gitkeep delete mode 100644 migrations/1_initial_migration.js delete mode 100644 migrations/2_deploy_contracts.js diff --git a/contracts/.npmignore b/contracts/.npmignore new file mode 100644 index 000000000..e792d8bc6 --- /dev/null +++ b/contracts/.npmignore @@ -0,0 +1,2 @@ +mocks +examples diff --git a/contracts/lifecycle/Migrations.sol b/contracts/lifecycle/Migrations.sol deleted file mode 100644 index b12a39b2d..000000000 --- a/contracts/lifecycle/Migrations.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity ^0.4.21; - -import "../ownership/Ownable.sol"; - - -/** - * @title Migrations - * @dev This is a truffle contract, needed for truffle integration, not meant for use by Zeppelin users. - */ -contract Migrations is Ownable { - uint256 public lastCompletedMigration; - - function setCompleted(uint256 completed) onlyOwner public { - lastCompletedMigration = completed; - } - - function upgrade(address newAddress) onlyOwner public { - Migrations upgraded = Migrations(newAddress); - upgraded.setCompleted(lastCompletedMigration); - } -} diff --git a/migrations/.gitkeep b/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index fbe302cd4..000000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require('Migrations'); - -module.exports = function (deployer) { - deployer.deploy(Migrations); -}; diff --git a/migrations/2_deploy_contracts.js b/migrations/2_deploy_contracts.js deleted file mode 100644 index a79df71b6..000000000 --- a/migrations/2_deploy_contracts.js +++ /dev/null @@ -1,9 +0,0 @@ -// var Ownable = artifacts.require("Ownable"); - -// NOTE: Use this file to easily deploy the contracts you're writing. -// (but make sure to reset this file before committing -// with `git checkout HEAD -- migrations/2_deploy_contracts.js`) - -module.exports = function (deployer) { - // deployer.deploy(Ownable); -}; diff --git a/package-lock.json b/package-lock.json index 9e56a7db8..5993fe51f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1974,7 +1974,8 @@ "dotenv": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-4.0.0.tgz", - "integrity": "sha1-hk7xN5rO1Vzm+V3r7NzhefegzR0=" + "integrity": "sha1-hk7xN5rO1Vzm+V3r7NzhefegzR0=", + "dev": true }, "drbg.js": { "version": "1.0.1", @@ -6205,12 +6206,6 @@ } } }, - "mocha-lcov-reporter": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/mocha-lcov-reporter/-/mocha-lcov-reporter-1.3.0.tgz", - "integrity": "sha1-Rpve9PivyaEWBW8HnfYYLQr7A4Q=", - "dev": true - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index e69e50410..2df0e14c2 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,10 @@ "name": "zeppelin-solidity", "version": "1.8.0", "description": "Secure Smart Contract library for Solidity", + "files": [ + "contracts", + "test" + ], "scripts": { "test": "scripts/test.sh", "lint": "eslint .", @@ -42,6 +46,7 @@ "chai-as-promised": "^7.0.0", "chai-bignumber": "^2.0.0", "coveralls": "^2.13.1", + "dotenv": "^4.0.0", "eslint": "^4.11.0", "eslint-config-standard": "^10.2.1", "eslint-plugin-import": "^2.8.0", @@ -51,13 +56,9 @@ "ethereumjs-util": "^5.1.2", "ethjs-abi": "^0.2.1", "ganache-cli": "6.1.0", - "mocha-lcov-reporter": "^1.3.0", "solidity-coverage": "^0.4.15", "solium": "^1.1.6", "truffle": "^4.1.5", "truffle-hdwallet-provider": "0.0.3" - }, - "dependencies": { - "dotenv": "^4.0.0" } } From 4a10f727c4756a8f6433f272a49e7a15db5e4b8f Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 26 Apr 2018 16:36:06 -0300 Subject: [PATCH 8/8] 1.9.0 --- ethpm.json | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ethpm.json b/ethpm.json index 5c6e9bd82..807438c3a 100644 --- a/ethpm.json +++ b/ethpm.json @@ -1,6 +1,6 @@ { "package_name": "zeppelin", - "version": "1.8.0", + "version": "1.9.0", "description": "Secure Smart Contract library for Solidity", "authors": [ "Manuel Araoz " diff --git a/package-lock.json b/package-lock.json index 9a613c03b..9eff778d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "openzeppelin-solidity", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ce7c8c754..e019769ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openzeppelin-solidity", - "version": "1.8.0", + "version": "1.9.0", "description": "Secure Smart Contract library for Solidity", "files": [ "contracts",