Unverified Commit 376820d5 by Nicolás Venturo Committed by GitHub

Hardcode ERC777 granularity to 1, remove tests. (#1739)

* Hardcode ERC777 granularity to 1, remove tests.

* Add clarifying title comment.
parent b84c145c
...@@ -8,7 +8,7 @@ import "../../utils/Address.sol"; ...@@ -8,7 +8,7 @@ import "../../utils/Address.sol";
import "../IERC1820Registry.sol"; import "../IERC1820Registry.sol";
/** /**
* @title ERC777 token implementation * @title ERC777 token implementation, with granularity harcoded to 1.
* @author etsvigun <utgarda@gmail.com>, Bertrand Masius <github@catageeks.tk> * @author etsvigun <utgarda@gmail.com>, Bertrand Masius <github@catageeks.tk>
*/ */
contract ERC777 is IERC777 { contract ERC777 is IERC777 {
...@@ -25,8 +25,6 @@ contract ERC777 is IERC777 { ...@@ -25,8 +25,6 @@ contract ERC777 is IERC777 {
uint256 private _totalSupply; uint256 private _totalSupply;
uint256 private _granularity;
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender"); bytes32 constant private TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient"); bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
...@@ -43,14 +41,10 @@ contract ERC777 is IERC777 { ...@@ -43,14 +41,10 @@ contract ERC777 is IERC777 {
constructor( constructor(
string memory name, string memory name,
string memory symbol, string memory symbol,
uint256 granularity,
address[] memory defaultOperators address[] memory defaultOperators
) public { ) public {
require(granularity > 0);
_name = name; _name = name;
_symbol = symbol; _symbol = symbol;
_granularity = granularity;
_defaultOperatorsArray = defaultOperators; _defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) { for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
...@@ -182,7 +176,7 @@ contract ERC777 is IERC777 { ...@@ -182,7 +176,7 @@ contract ERC777 is IERC777 {
* @return uint256 granularity * @return uint256 granularity
*/ */
function granularity() public view returns (uint256) { function granularity() public view returns (uint256) {
return _granularity; return 1;
} }
/** /**
...@@ -228,7 +222,6 @@ contract ERC777 is IERC777 { ...@@ -228,7 +222,6 @@ contract ERC777 is IERC777 {
internal internal
{ {
require(to != address(0)); require(to != address(0));
require((amount % _granularity) == 0);
// Update state variables // Update state variables
_totalSupply = _totalSupply.add(amount); _totalSupply = _totalSupply.add(amount);
...@@ -260,7 +253,6 @@ contract ERC777 is IERC777 { ...@@ -260,7 +253,6 @@ contract ERC777 is IERC777 {
{ {
require(from != address(0)); require(from != address(0));
require(to != address(0)); require(to != address(0));
require((amount % _granularity) == 0);
_callTokensToSend(operator, from, to, amount, userData, operatorData); _callTokensToSend(operator, from, to, amount, userData, operatorData);
...@@ -291,7 +283,6 @@ contract ERC777 is IERC777 { ...@@ -291,7 +283,6 @@ contract ERC777 is IERC777 {
private private
{ {
require(from != address(0)); require(from != address(0));
require((amount % _granularity) == 0);
_callTokensToSend(operator, from, address(0), amount, data, operatorData); _callTokensToSend(operator, from, address(0), amount, data, operatorData);
......
...@@ -8,9 +8,8 @@ contract ERC777Mock is ERC777 { ...@@ -8,9 +8,8 @@ contract ERC777Mock is ERC777 {
uint256 initialBalance, uint256 initialBalance,
string memory name, string memory name,
string memory symbol, string memory symbol,
uint256 granularity,
address[] memory defaultOperators address[] memory defaultOperators
) public ERC777(name, symbol, granularity, defaultOperators) { ) public ERC777(name, symbol, defaultOperators) {
_mint(msg.sender, initialHolder, initialBalance, "", ""); _mint(msg.sender, initialHolder, initialBalance, "", "");
} }
......
...@@ -524,10 +524,7 @@ module.exports = { ...@@ -524,10 +524,7 @@ module.exports = {
shouldBehaveLikeERC777DirectSendBurn, shouldBehaveLikeERC777DirectSendBurn,
shouldBehaveLikeERC777OperatorSendBurn, shouldBehaveLikeERC777OperatorSendBurn,
shouldBehaveLikeERC777UnauthorizedOperatorSendBurn, shouldBehaveLikeERC777UnauthorizedOperatorSendBurn,
shouldDirectSendTokens,
shouldDirectBurnTokens,
shouldBehaveLikeERC777InternalMint, shouldBehaveLikeERC777InternalMint,
shouldInternalMintTokens,
shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook, shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook,
shouldBehaveLikeERC777SendBurnWithSendHook, shouldBehaveLikeERC777SendBurnWithSendHook,
}; };
...@@ -4,10 +4,7 @@ const { ...@@ -4,10 +4,7 @@ const {
shouldBehaveLikeERC777DirectSendBurn, shouldBehaveLikeERC777DirectSendBurn,
shouldBehaveLikeERC777OperatorSendBurn, shouldBehaveLikeERC777OperatorSendBurn,
shouldBehaveLikeERC777UnauthorizedOperatorSendBurn, shouldBehaveLikeERC777UnauthorizedOperatorSendBurn,
shouldDirectSendTokens,
shouldDirectBurnTokens,
shouldBehaveLikeERC777InternalMint, shouldBehaveLikeERC777InternalMint,
shouldInternalMintTokens,
shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook, shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook,
shouldBehaveLikeERC777SendBurnWithSendHook, shouldBehaveLikeERC777SendBurnWithSendHook,
} = require('./ERC777.behavior'); } = require('./ERC777.behavior');
...@@ -30,16 +27,9 @@ contract('ERC777', function ([ ...@@ -30,16 +27,9 @@ contract('ERC777', function ([
this.erc1820 = await singletons.ERC1820Registry(registryFunder); this.erc1820 = await singletons.ERC1820Registry(registryFunder);
}); });
it('reverts with a granularity of zero', async function () {
await shouldFail.reverting(ERC777.new(holder, initialSupply, name, symbol, 0, []));
});
context('with a granularity of one', function () {
const granularity = new BN('1');
context('with default operators', function () { context('with default operators', function () {
beforeEach(async function () { beforeEach(async function () {
this.token = await ERC777.new(holder, initialSupply, name, symbol, granularity, defaultOperators); this.token = await ERC777.new(holder, initialSupply, name, symbol, defaultOperators);
}); });
it.skip('does not emit AuthorizedOperator events for default operators', async function () { it.skip('does not emit AuthorizedOperator events for default operators', async function () {
...@@ -55,8 +45,8 @@ contract('ERC777', function ([ ...@@ -55,8 +45,8 @@ contract('ERC777', function ([
(await this.token.symbol()).should.equal(symbol); (await this.token.symbol()).should.equal(symbol);
}); });
it('returns the granularity', async function () { it('has a granularity of 1', async function () {
(await this.token.granularity()).should.be.bignumber.equal(granularity); (await this.token.granularity()).should.be.bignumber.equal('1');
}); });
it('returns the default operators', async function () { it('returns the default operators', async function () {
...@@ -393,56 +383,11 @@ contract('ERC777', function ([ ...@@ -393,56 +383,11 @@ contract('ERC777', function ([
context('with no default operators', function () { context('with no default operators', function () {
beforeEach(async function () { beforeEach(async function () {
this.token = await ERC777.new(holder, initialSupply, name, symbol, granularity, []); this.token = await ERC777.new(holder, initialSupply, name, symbol, []);
}); });
it('default operators list is empty', async function () { it('default operators list is empty', async function () {
(await this.token.defaultOperators()).should.deep.equal([]); (await this.token.defaultOperators()).should.deep.equal([]);
}); });
}); });
});
context('with granularity larger than 1', function () {
const granularity = new BN('4');
beforeEach(async function () {
initialSupply.mod(granularity).should.be.bignumber.equal('0');
this.token = await ERC777.new(holder, initialSupply, name, symbol, granularity, defaultOperators);
});
it('returns the granularity', async function () {
(await this.token.granularity()).should.be.bignumber.equal(granularity);
});
context('when the sender has tokens', function () {
const from = holder;
shouldDirectSendTokens(from, anyone, new BN('0'), data);
shouldDirectSendTokens(from, anyone, granularity, data);
shouldDirectSendTokens(from, anyone, granularity.muln(2), data);
it('reverts when sending an amount non-multiple of the granularity', async function () {
await shouldFail.reverting(this.token.send(anyone, granularity.subn(1), data, { from }));
});
shouldDirectBurnTokens(from, new BN('0'), data);
shouldDirectBurnTokens(from, granularity, data);
shouldDirectBurnTokens(from, granularity.muln(2), data);
it('reverts when burning an amount non-multiple of the granularity', async function () {
await shouldFail.reverting(this.token.burn(granularity.subn(1), data, { from }));
});
});
shouldInternalMintTokens(anyone, defaultOperatorA, new BN('0'), data, operatorData);
shouldInternalMintTokens(anyone, defaultOperatorA, granularity, data, operatorData);
shouldInternalMintTokens(anyone, defaultOperatorA, granularity.muln(2), data, operatorData);
it('reverts when minting an amount non-multiple of the granularity', async function () {
await shouldFail.reverting(
this.token.mintInternal(defaultOperatorA, anyone, granularity.subn(1), data, operatorData)
);
});
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment