basic setup

This commit is contained in:
haydenadams
2019-08-28 16:31:10 -04:00
commit 36a59fb592
6 changed files with 7217 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.sol linguist-language=Solidity

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
build/

View File

@ -0,0 +1,15 @@
pragma solidity ^0.5.11;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
// Example class - a mock class using delivering from ERC20
contract Token is ERC20, ERC20Detailed {
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 initialBalance)
public
ERC20Detailed(_name, _symbol, _decimals)
{
super._mint(msg.sender, initialBalance);
}
}

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"dependencies": {
"solc": "^0.5.11"
},
"devDependencies": {
"chai": "^4.2.0",
"ethereum-waffle": "^2.1.0",
"mocha": "^6.2.0",
"openzeppelin-solidity": "^2.3.0"
},
"scripts": {
"test": "waffle && mocha"
}
}

47
test/testToken.js Normal file
View File

@ -0,0 +1,47 @@
const chai = require('chai');
const {createMockProvider, deployContract, getWallets, solidity} = require('ethereum-waffle');
const BasicTokenMock = require('../build/Token');
chai.use(solidity);
const {expect} = chai;
describe('INTEGRATION: Example', () => {
let provider = createMockProvider();
let [wallet, walletTo] = getWallets(provider);
let token;
beforeEach(async () => {
token = await deployContract(wallet, BasicTokenMock, ['HayCoin', 'HAY', 18, 1000]);
});
it('Is named HayCoin', async () => {
expect(await token.name()).to.eq('HayCoin');
});
it('Assigns initial balance', async () => {
expect(await token.balanceOf(wallet.address)).to.eq(1000);
});
it('Transfer adds amount to destination account', async () => {
await token.transfer(walletTo.address, 7);
expect(await token.balanceOf(walletTo.address)).to.eq(7);
});
it('Transfer emits event', async () => {
await expect(token.transfer(walletTo.address, 7))
.to.emit(token, 'Transfer')
.withArgs(wallet.address, walletTo.address, 7);
});
it('Can not transfer above the amount', async () => {
await expect(token.transfer(walletTo.address, 1007)).to.be.reverted;
});
it('Can not transfer from empty account', async () => {
const tokenFromOtherWallet = token.connect(walletTo);
await expect(tokenFromOtherWallet.transfer(wallet.address, 1))
.to.be.reverted;
});
});

7138
yarn.lock Normal file

File diff suppressed because it is too large Load Diff