-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
- Loading branch information
1 parent
5748034
commit 883116e
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.2; | ||
|
||
import "../token/ERC20/ERC20Burnable.sol"; | ||
|
||
/** | ||
* @dev {ERC20} token, including: | ||
* | ||
* - Preminted initial supply | ||
* - Ability for holders to burn (destroy) their tokens | ||
* - No access control mechanism (for minting/pausing) and hence no governance | ||
* | ||
* This contract uses {ERC20Burnable} to include burn capabilities - head to | ||
* its documentation for details. | ||
*/ | ||
contract ERC20PresetFixedSupply is ERC20Burnable { | ||
/** | ||
* @dev Mints `initialSupply` amount of token and transfers them to `owner`. | ||
* | ||
* See {ERC20-constructor}. | ||
*/ | ||
constructor( | ||
string memory name, | ||
string memory symbol, | ||
uint256 initialSupply, | ||
address owner | ||
) public ERC20(name, symbol) { | ||
_mint(owner, initialSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.2; | ||
|
||
import "../token/ERC777/ERC777.sol"; | ||
|
||
/** | ||
* @dev {ERC777} token, including: | ||
* | ||
* - Preminted initial supply | ||
* - No access control mechanism (for minting/pausing) and hence no governance | ||
*/ | ||
contract ERC777PresetFixedSupply is ERC777 { | ||
/** | ||
* @dev Mints `initialSupply` amount of token and transfers them to `owner`. | ||
* | ||
* See {ERC777-constructor}. | ||
*/ | ||
constructor( | ||
string memory name, | ||
string memory symbol, | ||
address[] memory defaultOperators, | ||
uint256 initialSupply, | ||
address owner | ||
) public ERC777(name, symbol, defaultOperators) { | ||
_mint(owner, initialSupply, "", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { BN, constants, expectEvent } = require('@openzeppelin/test-helpers'); | ||
const { ZERO_ADDRESS } = constants; | ||
|
||
const { expect } = require('chai'); | ||
|
||
const ERC20PresetFixedSupply = artifacts.require('ERC20PresetFixedSupply'); | ||
|
||
contract('ERC20PresetFixedSupply', function (accounts) { | ||
const [deployer, owner] = accounts; | ||
|
||
const name = 'PresetFixedSupply'; | ||
const symbol = 'PFS'; | ||
|
||
const initialSupply = new BN('50000'); | ||
const amount = new BN('10000'); | ||
|
||
before(async function () { | ||
this.token = await ERC20PresetFixedSupply.new(name, symbol, initialSupply, owner, { from: deployer }); | ||
}); | ||
|
||
it('deployer has the balance equal to initial supply', async function () { | ||
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(initialSupply); | ||
}); | ||
|
||
it('total supply is equal to initial supply', async function () { | ||
expect(await this.token.totalSupply()).to.be.bignumber.equal(initialSupply); | ||
}); | ||
|
||
describe('burning', function () { | ||
it('holders can burn their tokens', async function () { | ||
const remainingBalance = initialSupply.sub(amount); | ||
const receipt = await this.token.burn(amount, { from: owner }); | ||
expectEvent(receipt, 'Transfer', { from: owner, to: ZERO_ADDRESS, value: amount }); | ||
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(remainingBalance); | ||
}); | ||
|
||
it('decrements totalSupply', async function () { | ||
const expectedSupply = initialSupply.sub(amount); | ||
expect(await this.token.totalSupply()).to.be.bignumber.equal(expectedSupply); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { BN, singletons } = require('@openzeppelin/test-helpers'); | ||
|
||
const { expect } = require('chai'); | ||
|
||
const ERC777PresetFixedSupply = artifacts.require('ERC777PresetFixedSupply'); | ||
|
||
contract('ERC777PresetFixedSupply', function (accounts) { | ||
const [registryFunder, owner, defaultOperatorA, defaultOperatorB, anyone] = accounts; | ||
|
||
const initialSupply = new BN('10000'); | ||
const name = 'ERC777Preset'; | ||
const symbol = '777P'; | ||
|
||
const defaultOperators = [defaultOperatorA, defaultOperatorB]; | ||
|
||
before(async function () { | ||
await singletons.ERC1820Registry(registryFunder); | ||
}); | ||
|
||
beforeEach(async function () { | ||
this.token = await ERC777PresetFixedSupply.new(name, symbol, defaultOperators, initialSupply, owner); | ||
}); | ||
|
||
it('returns the name', async function () { | ||
expect(await this.token.name()).to.equal(name); | ||
}); | ||
|
||
it('returns the symbol', async function () { | ||
expect(await this.token.symbol()).to.equal(symbol); | ||
}); | ||
|
||
it('returns the default operators', async function () { | ||
expect(await this.token.defaultOperators()).to.deep.equal(defaultOperators); | ||
}); | ||
|
||
it('default operators are operators for all accounts', async function () { | ||
for (const operator of defaultOperators) { | ||
expect(await this.token.isOperatorFor(operator, anyone)).to.equal(true); | ||
} | ||
}); | ||
|
||
it('returns the total supply equal to initial supply', async function () { | ||
expect(await this.token.totalSupply()).to.be.bignumber.equal(initialSupply); | ||
}); | ||
|
||
it('returns the balance of owner equal to initial supply', async function () { | ||
expect(await this.token.balanceOf(owner)).to.be.bignumber.equal(initialSupply); | ||
}); | ||
}); |