Hardcode ERC777 granularity to 1, remove tests. (#1739)
* Hardcode ERC777 granularity to 1, remove tests. * Add clarifying title comment.
This commit is contained in:
@ -8,7 +8,7 @@ import "../../utils/Address.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>
|
||||
*/
|
||||
contract ERC777 is IERC777 {
|
||||
@ -25,8 +25,6 @@ contract ERC777 is IERC777 {
|
||||
|
||||
uint256 private _totalSupply;
|
||||
|
||||
uint256 private _granularity;
|
||||
|
||||
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH = keccak256("ERC777TokensSender");
|
||||
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");
|
||||
|
||||
@ -43,14 +41,10 @@ contract ERC777 is IERC777 {
|
||||
constructor(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
uint256 granularity,
|
||||
address[] memory defaultOperators
|
||||
) public {
|
||||
require(granularity > 0);
|
||||
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_granularity = granularity;
|
||||
|
||||
_defaultOperatorsArray = defaultOperators;
|
||||
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
|
||||
@ -182,7 +176,7 @@ contract ERC777 is IERC777 {
|
||||
* @return uint256 granularity
|
||||
*/
|
||||
function granularity() public view returns (uint256) {
|
||||
return _granularity;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +222,6 @@ contract ERC777 is IERC777 {
|
||||
internal
|
||||
{
|
||||
require(to != address(0));
|
||||
require((amount % _granularity) == 0);
|
||||
|
||||
// Update state variables
|
||||
_totalSupply = _totalSupply.add(amount);
|
||||
@ -260,7 +253,6 @@ contract ERC777 is IERC777 {
|
||||
{
|
||||
require(from != address(0));
|
||||
require(to != address(0));
|
||||
require((amount % _granularity) == 0);
|
||||
|
||||
_callTokensToSend(operator, from, to, amount, userData, operatorData);
|
||||
|
||||
@ -291,7 +283,6 @@ contract ERC777 is IERC777 {
|
||||
private
|
||||
{
|
||||
require(from != address(0));
|
||||
require((amount % _granularity) == 0);
|
||||
|
||||
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
|
||||
|
||||
|
||||
@ -8,9 +8,8 @@ contract ERC777Mock is ERC777 {
|
||||
uint256 initialBalance,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
uint256 granularity,
|
||||
address[] memory defaultOperators
|
||||
) public ERC777(name, symbol, granularity, defaultOperators) {
|
||||
) public ERC777(name, symbol, defaultOperators) {
|
||||
_mint(msg.sender, initialHolder, initialBalance, "", "");
|
||||
}
|
||||
|
||||
|
||||
@ -524,10 +524,7 @@ module.exports = {
|
||||
shouldBehaveLikeERC777DirectSendBurn,
|
||||
shouldBehaveLikeERC777OperatorSendBurn,
|
||||
shouldBehaveLikeERC777UnauthorizedOperatorSendBurn,
|
||||
shouldDirectSendTokens,
|
||||
shouldDirectBurnTokens,
|
||||
shouldBehaveLikeERC777InternalMint,
|
||||
shouldInternalMintTokens,
|
||||
shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook,
|
||||
shouldBehaveLikeERC777SendBurnWithSendHook,
|
||||
};
|
||||
|
||||
@ -4,10 +4,7 @@ const {
|
||||
shouldBehaveLikeERC777DirectSendBurn,
|
||||
shouldBehaveLikeERC777OperatorSendBurn,
|
||||
shouldBehaveLikeERC777UnauthorizedOperatorSendBurn,
|
||||
shouldDirectSendTokens,
|
||||
shouldDirectBurnTokens,
|
||||
shouldBehaveLikeERC777InternalMint,
|
||||
shouldInternalMintTokens,
|
||||
shouldBehaveLikeERC777SendBurnMintInternalWithReceiveHook,
|
||||
shouldBehaveLikeERC777SendBurnWithSendHook,
|
||||
} = require('./ERC777.behavior');
|
||||
@ -30,16 +27,9 @@ contract('ERC777', function ([
|
||||
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 () {
|
||||
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 () {
|
||||
@ -55,8 +45,8 @@ contract('ERC777', function ([
|
||||
(await this.token.symbol()).should.equal(symbol);
|
||||
});
|
||||
|
||||
it('returns the granularity', async function () {
|
||||
(await this.token.granularity()).should.be.bignumber.equal(granularity);
|
||||
it('has a granularity of 1', async function () {
|
||||
(await this.token.granularity()).should.be.bignumber.equal('1');
|
||||
});
|
||||
|
||||
it('returns the default operators', async function () {
|
||||
@ -393,7 +383,7 @@ contract('ERC777', function ([
|
||||
|
||||
context('with no default operators', 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 () {
|
||||
@ -401,48 +391,3 @@ contract('ERC777', function ([
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user