mirror of
https://github.com/status-im/topic-democracy.git
synced 2025-02-24 08:08:11 +00:00
merge bootstrap-embark31
This commit is contained in:
parent
b5e3c4be34
commit
fcad9c9acf
4
.babelrc
Normal file
4
.babelrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["transform-object-rest-spread"],
|
||||
"presets": ["stage-2"]
|
||||
}
|
9
.eslintrc.json
Normal file
9
.eslintrc.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "airbnb",
|
||||
"plugins": [
|
||||
"react"
|
||||
],
|
||||
"rules": {
|
||||
"react/prop-types": 0
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
# status.im contracts
|
||||
|
||||
Requires https://github.com/creationix/nvm
|
||||
Usage:
|
||||
```
|
||||
nvm install v8.9.4
|
||||
nvm use v8.9.4
|
||||
npm install -g embark
|
||||
git clone https://github.com/status-im/contracts.git
|
||||
cd contracts
|
||||
|
19
app/actions/accounts.js
Normal file
19
app/actions/accounts.js
Normal file
@ -0,0 +1,19 @@
|
||||
import ERC20Token from 'Embark/contracts/ERC20Token';
|
||||
import { actions as accountActions } from '../reducers/accounts'
|
||||
|
||||
const { receiveAccounts } = accountActions
|
||||
export const fetchAndDispatchAccountsWithBalances = (web3, dispatch) => {
|
||||
web3.eth.getAccounts((err, addresses) => {
|
||||
if (addresses) {
|
||||
const defaultAccount = web3.eth.defaultAccount || addresses[0]
|
||||
const accounts = addresses.map(async address => {
|
||||
const balance = await web3.eth.getBalance(address, 'latest')
|
||||
const ERC20TokenBalance = await ERC20Token.methods.balanceOf(address).call()
|
||||
return { address, balance, ERC20TokenBalance }
|
||||
})
|
||||
Promise.all(accounts).then(accounts => {
|
||||
dispatch(receiveAccounts(defaultAccount, accounts))
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
@ -1,112 +1,66 @@
|
||||
import web3 from "Embark/web3"
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import web3 from 'Embark/web3'
|
||||
import React from 'react';
|
||||
import { Nav, MenuItem , NavDropdown} from 'react-bootstrap';
|
||||
import { connect } from 'react-redux';
|
||||
import { Nav, MenuItem, NavDropdown } from 'react-bootstrap';
|
||||
import Blockies from 'react-blockies';
|
||||
|
||||
import { string, bool, func, arrayOf, shape } from 'prop-types';
|
||||
import { getAccounts, getDefaultAccount, accountsIsLoading, actions as accountActions } from '../reducers/accounts';
|
||||
import './accountlist.css';
|
||||
|
||||
class AccList extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
classNameNavDropdown: props.classNameNavDropdown,
|
||||
defaultAccount: "0x0000000000000000000000000000000000000000",
|
||||
addresses: [],
|
||||
balances: []
|
||||
}
|
||||
__embarkContext.execWhenReady(() => {
|
||||
this.load()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
load() {
|
||||
web3.eth.getAccounts((err, addresses) => {
|
||||
if (addresses) {
|
||||
var defaultAccount = web3.eth.defaultAccount;
|
||||
if(!defaultAccount){
|
||||
web3.eth.defaultAccount = addresses[0];
|
||||
}
|
||||
|
||||
var balances = [];
|
||||
balances.length == addresses.length;
|
||||
addresses.forEach((address, index) => {
|
||||
web3.eth.getBalance(address, 'latest', (err, balance) => {
|
||||
balances[index] = balance;
|
||||
if(index+1 == balances.length){
|
||||
this.setState({
|
||||
balances: balances
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
this.setState({
|
||||
defaultAccount: defaultAccount,
|
||||
addresses: addresses
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log("No addresses available.");
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
setDefaultAccount(index) {
|
||||
var defaultAcc = this.state.addresses[index];
|
||||
if(defaultAcc){
|
||||
web3.eth.defaultAccount = defaultAcc;
|
||||
this.setState({defaultAccount: defaultAcc });
|
||||
} else {
|
||||
console.log("invalid account")
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
var accsTitle;
|
||||
var accsList = [];
|
||||
if (this.state.addresses) {
|
||||
accsTitle = this.state.defaultAccount;
|
||||
this.state.addresses.forEach(
|
||||
(name, index) => {
|
||||
accsList.push(
|
||||
<MenuItem key={index} onClick={(e) => this.setDefaultAccount(index) }>
|
||||
<div className="account">
|
||||
<div className="accountIdenticon">
|
||||
<Blockies seed={name} />
|
||||
</div>
|
||||
<div className="accountHexString">
|
||||
{name}
|
||||
</div>
|
||||
<div className="accountBalance">
|
||||
Ξ {this.state.balances[index] / (10**18)}
|
||||
</div>
|
||||
</div>
|
||||
</MenuItem>);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
const AccList = ({
|
||||
accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown,
|
||||
}) => (
|
||||
<React.Fragment>
|
||||
{!isLoading ?
|
||||
<div className="accounts">
|
||||
<div className="selectedIdenticon">
|
||||
<Blockies seed={ this.state.defaultAccount } />
|
||||
<Blockies seed={defaultAccount} />
|
||||
</div>
|
||||
<div className="accountList">
|
||||
<Nav>
|
||||
<NavDropdown key={1} title={accsTitle} id="basic-nav-dropdown" className={ this.state.classNameNavDropdown }>
|
||||
{accsList}
|
||||
<NavDropdown key={1} title={defaultAccount} id="basic-nav-dropdown" className={classNameNavDropdown}>
|
||||
{accounts.map(account => (
|
||||
<MenuItem key={account.address} onClick={() => changeAccount(account.address)}>
|
||||
<div className="account">
|
||||
<div className="accountIdenticon">
|
||||
<Blockies seed={account.address} />
|
||||
</div>
|
||||
<div className="accountHexString">
|
||||
{account.address}
|
||||
</div>
|
||||
<div className="accountBalance">
|
||||
Ξ {account.balance / (10 ** 18)}
|
||||
</div>
|
||||
</div>
|
||||
</MenuItem>
|
||||
))}
|
||||
</NavDropdown>
|
||||
</Nav>
|
||||
</div>
|
||||
</div>
|
||||
: <div>Loading...</div>}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
AccList.propTypes = {
|
||||
accounts: arrayOf(shape({ address: string, balance: string })).isRequired,
|
||||
defaultAccount: string,
|
||||
changeAccount: func.isRequired,
|
||||
isLoading: bool.isRequired,
|
||||
classNameNavDropdown: string
|
||||
}
|
||||
|
||||
export default AccList;
|
||||
const mapStateToProps = state => ({
|
||||
accounts: getAccounts(state),
|
||||
defaultAccount: getDefaultAccount(state),
|
||||
isLoading: accountsIsLoading(state),
|
||||
});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
changeAccount(address) {
|
||||
web3.eth.defaultAccount = address;
|
||||
dispatch(accountActions.updateDefaultAccount(address));
|
||||
},
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(AccList);
|
||||
|
@ -1,27 +1,24 @@
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import ERC20Token from 'Embark/contracts/ERC20Token';
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
|
||||
import { getCurrentAccount, accountsIsLoading } from '../reducers/accounts';
|
||||
|
||||
class ERC20TokenUI extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
ERC20Token.options.address = props.address;
|
||||
this.state = {
|
||||
|
||||
balanceOf: 0,
|
||||
transferTo: "",
|
||||
transferAmount: 0,
|
||||
logs: []
|
||||
accountBalance: 0,
|
||||
accountB: web3.eth.defaultAccount,
|
||||
}
|
||||
}
|
||||
|
||||
contractAddress(e){
|
||||
e.preventDefault();
|
||||
var tokenAddress = e.target.value;
|
||||
ERC20Token.options.address = tokenAddress;
|
||||
}
|
||||
|
||||
update_transferTo(e){
|
||||
this.setState({transferTo: e.target.value});
|
||||
}
|
||||
@ -50,7 +47,6 @@ class ERC20TokenUI extends React.Component {
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
ERC20Token.methods.balanceOf(who).call()
|
||||
.then(_value => this.setState({balanceOf: _value}))
|
||||
|
||||
} else {
|
||||
ERC20Token.balanceOf(who)
|
||||
.then(_value => this.x({balanceOf: _value}));
|
||||
@ -58,25 +54,32 @@ class ERC20TokenUI extends React.Component {
|
||||
this._addToLog(ERC20Token.options.address+".balanceOf(" + who + ")");
|
||||
}
|
||||
|
||||
|
||||
_addToLog(txt){
|
||||
this.state.logs.push(txt);
|
||||
this.setState({logs: this.state.logs});
|
||||
getDefaultAccountBalance(){
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
ERC20Token.methods.balanceOf(web3.eth.defaultAccount).call()
|
||||
.then(_value => this.setState({accountBalance: _value}))
|
||||
} else {
|
||||
ERC20Token.balanceOf(web3.eth.defaultAccount)
|
||||
.then(_value => this.x({valueGet: _value}))
|
||||
}
|
||||
this._addToLog(ERC20Token.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")");
|
||||
}
|
||||
|
||||
render(){
|
||||
return (<React.Fragment>
|
||||
_addToLog(txt){
|
||||
console.log(txt);
|
||||
}
|
||||
|
||||
<h2> Set token contract address</h2>
|
||||
render() {
|
||||
const { account, isLoading } = this.props;
|
||||
return (
|
||||
<React.Fragment>
|
||||
<h3> Read your account token balance </h3>
|
||||
<Form inline>
|
||||
<FormGroup>
|
||||
<FormControl
|
||||
type="text"
|
||||
onChange={(e) => this.contractAddress(e)} />
|
||||
{!isLoading && <HelpBlock>Your test token balance is <span className="accountBalance">{account.ERC20TokenBalance}</span></HelpBlock>}
|
||||
</FormGroup>
|
||||
</Form>
|
||||
|
||||
|
||||
<h3> Read account token balance</h3>
|
||||
<Form inline>
|
||||
<FormGroup>
|
||||
@ -116,16 +119,14 @@ class ERC20TokenUI extends React.Component {
|
||||
</FormGroup>
|
||||
</Form>
|
||||
|
||||
<h3> Contract Calls </h3>
|
||||
<p>Javascript calls being made: </p>
|
||||
<div className="logs">
|
||||
{
|
||||
this.state.logs.map((item, i) => <p key={i}>{item}</p>)
|
||||
}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ERC20TokenUI;
|
||||
const mapStateToProps = state => ({
|
||||
account: getCurrentAccount(state),
|
||||
isLoading: accountsIsLoading(state),
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(ERC20TokenUI);
|
||||
|
@ -2,6 +2,9 @@ import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import TestToken from 'Embark/contracts/TestToken';
|
||||
import React from 'react';
|
||||
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
|
||||
import ERC20TokenUI from './erc20token';
|
||||
import { connect } from 'react-redux';
|
||||
import { actions as accountActions } from '../reducers/accounts';
|
||||
|
||||
class TestTokenUI extends React.Component {
|
||||
|
||||
@ -9,10 +12,6 @@ class TestTokenUI extends React.Component {
|
||||
super(props);
|
||||
this.state = {
|
||||
amountToMint: 100,
|
||||
accountBalance: 0,
|
||||
accountB: web3.eth.defaultAccount,
|
||||
balanceOf: 0,
|
||||
logs: []
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,40 +20,24 @@ class TestTokenUI extends React.Component {
|
||||
}
|
||||
|
||||
mint(e){
|
||||
const { addToBalance } = this.props;
|
||||
e.preventDefault();
|
||||
|
||||
var value = parseInt(this.state.amountToMint, 10);
|
||||
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
TestToken.methods.mint(value).send({from: web3.eth.defaultAccount});
|
||||
TestToken.methods.mint(value).send({from: web3.eth.defaultAccount})
|
||||
.then(r => { addToBalance(value) });
|
||||
} else {
|
||||
TestToken.mint(value);
|
||||
this._addToLog("#blockchain", "TestToken.mint(" + value + ")");
|
||||
TestToken.mint(value).send({from: web3.eth.defaultAccount})
|
||||
.then(r => { addToBalance(value) });
|
||||
}
|
||||
this._addToLog(TestToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
|
||||
}
|
||||
|
||||
getBalance(e){
|
||||
e.preventDefault();
|
||||
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
TestToken.methods.balanceOf(web3.eth.defaultAccount).call()
|
||||
.then(_value => this.setState({accountBalance: _value}))
|
||||
} else {
|
||||
TestToken.balanceOf(web3.eth.defaultAccount)
|
||||
.then(_value => this.x({valueGet: _value}))
|
||||
}
|
||||
this._addToLog(TestToken.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")");
|
||||
}
|
||||
|
||||
_addToLog(txt){
|
||||
this.state.logs.push(txt);
|
||||
this.setState({logs: this.state.logs});
|
||||
console.log(TestToken.options.address +".mint("+value+").send({from: " + web3.eth.defaultAccount + "})");
|
||||
}
|
||||
|
||||
render(){
|
||||
return (<React.Fragment>
|
||||
<h3> 1. Mint Test Token</h3>
|
||||
<h3> Mint Test Token</h3>
|
||||
<Form inline>
|
||||
<FormGroup>
|
||||
<FormControl
|
||||
@ -65,24 +48,17 @@ class TestTokenUI extends React.Component {
|
||||
</FormGroup>
|
||||
</Form>
|
||||
|
||||
<h3> 2. Read your account token balance </h3>
|
||||
<Form inline>
|
||||
<FormGroup>
|
||||
<HelpBlock>Your test token balance is <span className="accountBalance">{this.state.accountBalance}</span></HelpBlock>
|
||||
<Button bsStyle="primary" onClick={(e) => this.getBalance(e)}>Get Balance</Button>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
<ERC20TokenUI address={ TestToken.options.address } />
|
||||
|
||||
<h3> 3. Contract Calls </h3>
|
||||
<p>Javascript calls being made: </p>
|
||||
<div className="logs">
|
||||
{
|
||||
this.state.logs.map((item, i) => <p key={i}>{item}</p>)
|
||||
}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default TestTokenUI;
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
addToBalance(amount) {
|
||||
dispatch(accountActions.addToErc20TokenBalance(amount));
|
||||
},
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps)(TestTokenUI);
|
||||
|
@ -5,7 +5,6 @@ import { Tabs, Tab } from 'react-bootstrap';
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import TopNavbar from './components/topnavbar';
|
||||
import TestTokenUI from './components/testtoken';
|
||||
import ERC20TokenUI from './components/erc20token';
|
||||
|
||||
import './dapp.css';
|
||||
|
||||
@ -40,12 +39,9 @@ class App extends React.Component {
|
||||
<Tab eventKey={1} title="TestToken">
|
||||
<TestTokenUI />
|
||||
</Tab>
|
||||
<Tab eventKey={2} title="ERC20Token">
|
||||
<ERC20TokenUI />
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</div>);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<App></App>, document.getElementById('app'));
|
||||
export default App;
|
||||
|
@ -7,6 +7,6 @@
|
||||
<body class="container">
|
||||
<div id="app">
|
||||
</div>
|
||||
<script src="js/dapp.js"></script>
|
||||
<script src="js/index.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
16
app/index.js
Normal file
16
app/index.js
Normal file
@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import store from './store/configureStore';
|
||||
import App from './dapp';
|
||||
import init from './store/init'
|
||||
import './dapp.css';
|
||||
|
||||
init();
|
||||
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<App />
|
||||
</Provider>,
|
||||
document.getElementById('app')
|
||||
);
|
54
app/reducers/accounts.js
Normal file
54
app/reducers/accounts.js
Normal file
@ -0,0 +1,54 @@
|
||||
import { createTypes, actionCreator } from 'redux-action-creator'
|
||||
import { createSelector } from 'reselect'
|
||||
|
||||
export const types = createTypes([
|
||||
'RECEIVE_ACCOUNTS',
|
||||
'UPDATE_DEFAULT_ACCOUNT',
|
||||
'ADD_TO_ERC20_TOKEN_BALANCE'
|
||||
], 'ACCOUNTS')
|
||||
export const actions = {
|
||||
receiveAccounts: actionCreator(types.RECEIVE_ACCOUNTS, 'defaultAccount','accounts'),
|
||||
updateDefaultAccount: actionCreator(types.UPDATE_DEFAULT_ACCOUNT, 'defaultAccount'),
|
||||
addToErc20TokenBalance: actionCreator(types.ADD_TO_ERC20_TOKEN_BALANCE, 'amount')
|
||||
}
|
||||
|
||||
export default function(state = { loading: true, accounts: [] }, action) {
|
||||
switch (action.type) {
|
||||
case types.RECEIVE_ACCOUNTS: {
|
||||
const { defaultAccount, accounts } = action.payload
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
defaultAccount,
|
||||
accounts
|
||||
}
|
||||
}
|
||||
case types.UPDATE_DEFAULT_ACCOUNT: {
|
||||
const { defaultAccount } = action.payload
|
||||
return { ...state, defaultAccount }
|
||||
}
|
||||
case types.ADD_TO_ERC20_TOKEN_BALANCE: {
|
||||
const currentAccount = { ...getCurrentAccount({accounts: state}) }
|
||||
currentAccount.ERC20TokenBalance = Number(currentAccount.ERC20TokenBalance) + Number(action.payload.amount)
|
||||
const accounts = [ ...state.accounts ]
|
||||
const idx = accounts.findIndex(a => a.address === currentAccount.address)
|
||||
accounts[idx] = currentAccount
|
||||
return {
|
||||
...state,
|
||||
accounts
|
||||
}
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const getAccountState = state => state.acounts;
|
||||
export const getAccounts = state => state.accounts.accounts;
|
||||
export const getDefaultAccount = state => state.accounts.defaultAccount;
|
||||
export const accountsIsLoading = state => state.accounts.loading;
|
||||
export const getCurrentAccount = createSelector(
|
||||
getDefaultAccount,
|
||||
getAccounts,
|
||||
(defaultAccount, accounts) => accounts.find(a => a.address === defaultAccount)
|
||||
)
|
8
app/reducers/rootReducer.js
Normal file
8
app/reducers/rootReducer.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import accounts from './accounts'
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
accounts
|
||||
});
|
||||
|
||||
export default rootReducer;
|
11
app/store/configureStore.js
Normal file
11
app/store/configureStore.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import rootReducer from '../reducers/rootReducer';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
const store = createStore(
|
||||
rootReducer,
|
||||
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
|
||||
applyMiddleware(thunk)
|
||||
);
|
||||
|
||||
export default store;
|
12
app/store/init.js
Normal file
12
app/store/init.js
Normal file
@ -0,0 +1,12 @@
|
||||
import web3 from "Embark/web3"
|
||||
import EmbarkJS from 'Embark/EmbarkJS'
|
||||
import store from './configureStore'
|
||||
import { fetchAndDispatchAccountsWithBalances } from '../actions/accounts'
|
||||
|
||||
const dispatch = action => store.dispatch(action)
|
||||
|
||||
export default () => {
|
||||
__embarkContext.execWhenReady(async () => {
|
||||
fetchAndDispatchAccountsWithBalances(web3, dispatch)
|
||||
})
|
||||
}
|
62
config/blockchain.js
Normal file
62
config/blockchain.js
Normal file
@ -0,0 +1,62 @@
|
||||
module.exports = {
|
||||
development: {
|
||||
enabled: true,
|
||||
networkType: "custom", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId
|
||||
networkId: "1337", // Network id used when networkType is custom
|
||||
isDev: true, // Uses and ephemeral proof-of-authority network with a pre-funded developer account, mining enabled
|
||||
genesisBlock: "config/development/genesis.json", // Genesis block to initiate on first creation of a development node
|
||||
datadir: ".embark/development/datadir", // Data directory for the databases and keystore
|
||||
mineWhenNeeded: true, // Uses our custom script (if isDev is false) to mine only when needed
|
||||
nodiscover: true, // Disables the peer discovery mechanism (manual peer addition)
|
||||
maxpeers: 0, // Maximum number of network peers (network disabled if set to 0) (default: 25)
|
||||
rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost")
|
||||
rpcPort: 8545, // HTTP-RPC server listening port (default: 8545)
|
||||
rpcCorsDomain: "auto", // Comma separated list of domains from which to accept cross origin requests (browser enforced)
|
||||
// When set to "auto", Embark will automatically set the cors to the address of the webserver
|
||||
proxy: true, // Proxy is used to present meaningful information about transactions
|
||||
account: {
|
||||
// "address": "", // When specified, uses that address instead of the default one for the network
|
||||
password: "config/development/password" // Password to unlock the account
|
||||
},
|
||||
targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine
|
||||
wsRPC: true, // Enable the WS-RPC server
|
||||
wsOrigins: "auto", // Origins from which to accept websockets requests
|
||||
// When set to "auto", Embark will automatically set the cors to the address of the webserver
|
||||
wsHost: "localhost", // WS-RPC server listening interface (default: "localhost")
|
||||
wsPort: 8546, // WS-RPC server listening port (default: 8546)
|
||||
simulatorMnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", // Mnemonic used by the simulator to generate a wallet
|
||||
simulatorBlocktime: 0 // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining.
|
||||
},
|
||||
testnet: {
|
||||
enabled: true,
|
||||
networkType: "testnet",
|
||||
light: true,
|
||||
rpcHost: "localhost",
|
||||
rpcPort: 8545,
|
||||
rpcCorsDomain: "http://localhost:8000",
|
||||
account: {
|
||||
password: "config/testnet/password"
|
||||
}
|
||||
},
|
||||
livenet: {
|
||||
enabled: true,
|
||||
networkType: "livenet",
|
||||
light: true,
|
||||
rpcHost: "localhost",
|
||||
rpcPort: 8545,
|
||||
rpcCorsDomain: "http://localhost:8000",
|
||||
account: {
|
||||
password: "config/livenet/password"
|
||||
}
|
||||
},
|
||||
privatenet: {
|
||||
enabled: true,
|
||||
networkType: "custom",
|
||||
rpcHost: "localhost",
|
||||
rpcPort: 8545,
|
||||
rpcCorsDomain: "http://localhost:8000",
|
||||
datadir: "yourdatadir",
|
||||
networkId: "123",
|
||||
bootnodes: ""
|
||||
}
|
||||
};
|
@ -1,56 +0,0 @@
|
||||
{
|
||||
"development": {
|
||||
"enabled": true,
|
||||
"networkType": "custom",
|
||||
"genesisBlock": "config/development/genesis.json",
|
||||
"datadir": ".embark/development/datadir",
|
||||
"mineWhenNeeded": true,
|
||||
"nodiscover": true,
|
||||
"maxpeers": 0,
|
||||
"rpcHost": "localhost",
|
||||
"rpcPort": 8545,
|
||||
"rpcCorsDomain": "auto",
|
||||
"account": {
|
||||
"password": "config/development/password"
|
||||
},
|
||||
"targetGasLimit": 8000000,
|
||||
"wsOrigins": "auto",
|
||||
"wsRPC": true,
|
||||
"wsHost": "localhost",
|
||||
"wsPort": 8546,
|
||||
"simulatorMnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm",
|
||||
"simulatorBlocktime": 0
|
||||
},
|
||||
"testnet": {
|
||||
"enabled": true,
|
||||
"networkType": "testnet",
|
||||
"light": true,
|
||||
"rpcHost": "localhost",
|
||||
"rpcPort": 8545,
|
||||
"rpcCorsDomain": "http://localhost:8000",
|
||||
"account": {
|
||||
"password": "config/testnet/password"
|
||||
}
|
||||
},
|
||||
"livenet": {
|
||||
"enabled": true,
|
||||
"networkType": "livenet",
|
||||
"light": true,
|
||||
"rpcHost": "localhost",
|
||||
"rpcPort": 8545,
|
||||
"rpcCorsDomain": "http://localhost:8000",
|
||||
"account": {
|
||||
"password": "config/livenet/password"
|
||||
}
|
||||
},
|
||||
"privatenet": {
|
||||
"enabled": true,
|
||||
"networkType": "custom",
|
||||
"rpcHost": "localhost",
|
||||
"rpcPort": 8545,
|
||||
"rpcCorsDomain": "http://localhost:8000",
|
||||
"datadir": "yourdatadir",
|
||||
"networkId": "123",
|
||||
"bootnodes": ""
|
||||
}
|
||||
}
|
12
config/communication.js
Normal file
12
config/communication.js
Normal file
@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
default: {
|
||||
enabled: true,
|
||||
provider: "whisper", // Communication provider. Currently, Embark only supports whisper
|
||||
available_providers: ["whisper"], // Array of available providers
|
||||
connection: {
|
||||
host: "localhost", // Host of the blockchain node
|
||||
port: 8546, // Port of the blockchain node
|
||||
type: "ws" // Type of connection (ws or rpc)
|
||||
}
|
||||
}
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"default": {
|
||||
"enabled": true,
|
||||
"provider": "whisper",
|
||||
"available_providers": ["whisper", "orbit"],
|
||||
"connection": {
|
||||
"host": "localhost",
|
||||
"port": 8546,
|
||||
"type": "ws"
|
||||
}
|
||||
}
|
||||
}
|
33
config/contracts.js
Normal file
33
config/contracts.js
Normal file
@ -0,0 +1,33 @@
|
||||
module.exports = {
|
||||
// default applies to all environments
|
||||
default: {
|
||||
// Blockchain node to deploy the contracts
|
||||
deployment: {
|
||||
host: "localhost", // Host of the blockchain node
|
||||
port: 8545, // Port of the blockchain node
|
||||
type: "rpc" // Type of connection (ws or rpc),
|
||||
},
|
||||
// order of connections the dapp should connect to
|
||||
dappConnection: [
|
||||
"$WEB3", // uses pre existing web3 object if available (e.g in Mist)
|
||||
"ws://localhost:8546",
|
||||
"http://localhost:8545"
|
||||
],
|
||||
gas: "auto",
|
||||
contracts: {
|
||||
TestToken: {
|
||||
deploy: false
|
||||
},
|
||||
ERC20Receiver: {
|
||||
deploy: false
|
||||
}
|
||||
}
|
||||
},
|
||||
development: {
|
||||
contracts: {
|
||||
TestToken: {
|
||||
deploy: true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
6
config/namesystem.js
Normal file
6
config/namesystem.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
default: {
|
||||
available_providers: ["ens"],
|
||||
provider: "ens"
|
||||
}
|
||||
};
|
35
config/storage.js
Normal file
35
config/storage.js
Normal file
@ -0,0 +1,35 @@
|
||||
module.exports = {
|
||||
default: {
|
||||
enabled: true,
|
||||
ipfs_bin: "ipfs",
|
||||
provider: "ipfs",
|
||||
available_providers: ["ipfs"],
|
||||
upload: {
|
||||
host: "localhost",
|
||||
port: 5001
|
||||
},
|
||||
dappConnection: [
|
||||
{
|
||||
provider:"ipfs",
|
||||
host: "localhost",
|
||||
port: 5001,
|
||||
getUrl: "http://localhost:8080/ipfs/"
|
||||
}
|
||||
]
|
||||
// Configuration to start Swarm in the same terminal as `embark run`
|
||||
/*,account: {
|
||||
address: "YOUR_ACCOUNT_ADDRESS", // Address of account accessing Swarm
|
||||
password: "PATH/TO/PASSWORD/FILE" // File containing the password of the account
|
||||
},
|
||||
swarmPath: "PATH/TO/SWARM/EXECUTABLE" // Path to swarm executable (default: swarm)*/
|
||||
},
|
||||
development: {
|
||||
enabled: true,
|
||||
provider: "ipfs",
|
||||
upload: {
|
||||
host: "localhost",
|
||||
port: 5001,
|
||||
getUrl: "http://localhost:8080/ipfs/"
|
||||
}
|
||||
}
|
||||
};
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"default": {
|
||||
"versions": {
|
||||
"ipfs-api": "17.2.4"
|
||||
},
|
||||
"enabled": true,
|
||||
"ipfs_bin": "ipfs",
|
||||
"provider": "ipfs",
|
||||
"available_providers": ["ipfs"],
|
||||
"host": "localhost",
|
||||
"port": 5001
|
||||
},
|
||||
"development": {
|
||||
"enabled": true,
|
||||
"provider": "ipfs",
|
||||
"host": "localhost",
|
||||
"port": 5001,
|
||||
"getUrl": "http://localhost:8080/ipfs/"
|
||||
}
|
||||
}
|
5
config/webserver.js
Normal file
5
config/webserver.js
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
enabled: true,
|
||||
host: "localhost",
|
||||
port: 8000
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"host": "localhost",
|
||||
"port": 8000
|
||||
}
|
@ -46,7 +46,7 @@ contract MessageSigned {
|
||||
internal
|
||||
returns (bytes32 signHash)
|
||||
{
|
||||
signHash = keccak256("\x19Ethereum Signed Message:\n32", _hash);
|
||||
signHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,11 @@ contract StandardToken is ERC20Token {
|
||||
{
|
||||
if (balances[_from] >= _value && _value > 0) {
|
||||
balances[_from] -= _value;
|
||||
if(_to == address(0)) {
|
||||
supply -= _value;
|
||||
} else {
|
||||
balances[_to] += _value;
|
||||
}
|
||||
emit Transfer(_from, _to, _value);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -2,6 +2,7 @@
|
||||
"contracts": ["contracts/**"],
|
||||
"app": {
|
||||
"js/dapp.js": ["app/dapp.js"],
|
||||
"js/index.js": ["app/index.js"],
|
||||
"index.html": "app/index.html",
|
||||
"images/": ["app/images/**"]
|
||||
},
|
||||
@ -9,7 +10,7 @@
|
||||
"config": "config/",
|
||||
"versions": {
|
||||
"web3": "1.0.0-beta",
|
||||
"solc": "0.4.23",
|
||||
"solc": "0.4.24",
|
||||
"ipfs-api": "17.2.4"
|
||||
},
|
||||
"plugins": {
|
||||
|
20
package.json
20
package.json
@ -4,7 +4,8 @@
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"solidity-coverage": "./node_modules/.bin/solidity-coverage",
|
||||
"test": "embark test"
|
||||
"test": "embark test",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -17,9 +18,24 @@
|
||||
},
|
||||
"homepage": "https://github.com/status-im/contracts#readme",
|
||||
"dependencies": {
|
||||
"prop-types": "^15.6.1",
|
||||
"react": "^16.3.2",
|
||||
"react-blockies": "^1.3.0",
|
||||
"react-bootstrap": "^0.32.1",
|
||||
"react-dom": "^16.3.2"
|
||||
"react-dom": "^16.3.2",
|
||||
"react-redux": "^5.0.7",
|
||||
"redux": "^4.0.0",
|
||||
"redux-action-creator": "^2.3.0",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"reselect": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"eslint": "^4.19.1",
|
||||
"eslint-config-airbnb": "^16.1.0",
|
||||
"eslint-plugin-import": "^2.12.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.0.3",
|
||||
"eslint-plugin-react": "^7.8.2"
|
||||
}
|
||||
}
|
||||
|
25
test/abstract/controlled.js
Normal file
25
test/abstract/controlled.js
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
exports.Test = (Controlled) => {
|
||||
describe("Controlled", async function() {
|
||||
this.timeout(0);
|
||||
var accounts;
|
||||
before(function(done) {
|
||||
web3.eth.getAccounts().then(function (res) {
|
||||
accounts = res;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("should start with msg.sender as controller", async function() {
|
||||
var controller = await Controlled.methods.controller().call();
|
||||
assert(controller, accounts[0]);
|
||||
});
|
||||
|
||||
it("should allow controller to set new controller", async function() {
|
||||
await Controlled.methods.changeController(accounts[1]).send({from: accounts[0]});
|
||||
var controller = await Controlled.methods.controller().call();
|
||||
assert(controller, accounts[1]);
|
||||
});
|
||||
});
|
||||
}
|
85
test/abstract/erc20tokenspec.js
Normal file
85
test/abstract/erc20tokenspec.js
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
const ERC20Receiver = require('Embark/contracts/ERC20Receiver');
|
||||
|
||||
exports.config = {
|
||||
contracts : {
|
||||
"ERC20Receiver": {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.Test = (ERC20Token) => {
|
||||
describe("ERC20Token", function() {
|
||||
|
||||
var accounts;
|
||||
before(function(done) {
|
||||
web3.eth.getAccounts().then(function (res) {
|
||||
accounts = res;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should transfer 1 token", async function() {
|
||||
let initialBalance0 = await ERC20Token.methods.balanceOf(accounts[0]).call();
|
||||
let initialBalance1 = await ERC20Token.methods.balanceOf(accounts[1]).call();
|
||||
await ERC20Token.methods.transfer(accounts[1],1).send({from: accounts[0]});
|
||||
let result0 = await ERC20Token.methods.balanceOf(accounts[0]).call();
|
||||
let result1 = await ERC20Token.methods.balanceOf(accounts[1]).call();
|
||||
|
||||
assert.equal(result0, +initialBalance0-1, "account 0 balance unexpected");
|
||||
assert.equal(result1, +initialBalance1+1, "account 1 balance unexpected");
|
||||
});
|
||||
|
||||
it("should set approved amount", async function() {
|
||||
await ERC20Token.methods.approve(accounts[2],10000000).send({from: accounts[0]});
|
||||
let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call();
|
||||
assert.equal(result, 10000000);
|
||||
});
|
||||
|
||||
it("should consume allowance amount", async function() {
|
||||
let initialAllowance = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call();
|
||||
await ERC20Token.methods.transferFrom(accounts[0], accounts[0],1).send({from: accounts[2]});
|
||||
let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call();
|
||||
|
||||
assert.equal(result, +initialAllowance-1);
|
||||
});
|
||||
|
||||
it("should transfer approved amount", async function() {
|
||||
let initialBalance0 = await ERC20Token.methods.balanceOf(accounts[0]).call();
|
||||
let initialBalance1 = await ERC20Token.methods.balanceOf(accounts[1]).call();
|
||||
await ERC20Token.methods.transferFrom(accounts[0], accounts[1],1).send({from: accounts[2]});
|
||||
let result0 = await ERC20Token.methods.balanceOf(accounts[0]).call();
|
||||
let result1 = await ERC20Token.methods.balanceOf(accounts[1]).call();
|
||||
|
||||
assert.equal(result0, +initialBalance0-1);
|
||||
assert.equal(result1, +initialBalance1+1);
|
||||
});
|
||||
|
||||
|
||||
it("should unset approved amount", async function() {
|
||||
await ERC20Token.methods.approve(accounts[2],0).send({from: accounts[0]});
|
||||
let result = await ERC20Token.methods.allowance(accounts[0], accounts[2]).call();
|
||||
assert.equal(result, 0);
|
||||
});
|
||||
|
||||
it("should deposit approved amount to contract ERC20Receiver", async function() {
|
||||
//ERC20Receiver = await ERC20Receiver.deploy().send();
|
||||
//console.log(ERC20Receiver.address);
|
||||
await ERC20Token.methods.approve(ERC20Receiver.address, 10).send({from: accounts[0]});
|
||||
await ERC20Receiver.methods.depositToken(ERC20Token.address, 10).send({from: accounts[0]});
|
||||
let result = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call();
|
||||
assert.equal(result, 10, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accounts[0]+") wrong");
|
||||
});
|
||||
|
||||
it("should witdraw approved amount from contract ERC20Receiver", async function() {
|
||||
let tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call();
|
||||
await ERC20Receiver.methods.withdrawToken(ERC20Token.address, tokenBalance).send({from: accounts[0]});
|
||||
tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accounts[0]).call();
|
||||
assert.equal(tokenBalance, 0, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accounts[0]+") wrong");
|
||||
});
|
||||
|
||||
//TODO: include checks for expected events fired
|
||||
|
||||
|
||||
});
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
|
||||
exports.Test = (contractsConfig, afterDeploy) => {
|
||||
|
||||
describe("Controlled", async function() {
|
||||
this.timeout(0);
|
||||
var Controlled;
|
||||
var accountsArr;
|
||||
before(function(done) {
|
||||
EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
|
||||
Controlled = Contract;
|
||||
accountsArr = accounts;
|
||||
await afterDeploy(accounts, Contract);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("should start with msg.sender as controller", async function() {
|
||||
var controller = await Controlled.methods.controller().call();
|
||||
assert(controller, accountsArr[0]);
|
||||
});
|
||||
|
||||
it("should allow controller to set new controller", async function() {
|
||||
await Controlled.methods.changeController(accountsArr[1]).send({from: accountsArr[0]});
|
||||
var controller = await Controlled.methods.controller().call();
|
||||
assert(controller, accountsArr[1]);
|
||||
});
|
||||
});
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
|
||||
exports.Test = (contractsConfig, afterDeploy) => {
|
||||
describe("ERC20Token", async function() {
|
||||
this.timeout(0);
|
||||
var ERC20Token;
|
||||
var accountsArr;
|
||||
before(function(done) {
|
||||
contractsConfig["ERC20Receiver"] = {};
|
||||
EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
|
||||
ERC20Token = Contract;
|
||||
accountsArr = accounts;
|
||||
await afterDeploy(accounts, Contract);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
it("should transfer 1 token", async function() {
|
||||
let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
|
||||
let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
|
||||
await ERC20Token.methods.transfer(accountsArr[1],1).send({from: accountsArr[0]});
|
||||
let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
|
||||
let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
|
||||
|
||||
assert.equal(result0, +initialBalance0-1, "account 0 balance unexpected");
|
||||
assert.equal(result1, +initialBalance1+1, "account 1 balance unexpected");
|
||||
});
|
||||
|
||||
it("should set approved amount", async function() {
|
||||
await ERC20Token.methods.approve(accountsArr[2],10000000).send({from: accountsArr[0]});
|
||||
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
|
||||
assert.equal(result, 10000000);
|
||||
});
|
||||
|
||||
it("should consume allowance amount", async function() {
|
||||
let initialAllowance = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
|
||||
await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[0],1).send({from: accountsArr[2]});
|
||||
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
|
||||
|
||||
assert.equal(result, +initialAllowance-1);
|
||||
});
|
||||
|
||||
it("should transfer approved amount", async function() {
|
||||
let initialBalance0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
|
||||
let initialBalance1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
|
||||
await ERC20Token.methods.transferFrom(accountsArr[0], accountsArr[1],1).send({from: accountsArr[2]});
|
||||
let result0 = await ERC20Token.methods.balanceOf(accountsArr[0]).call();
|
||||
let result1 = await ERC20Token.methods.balanceOf(accountsArr[1]).call();
|
||||
|
||||
assert.equal(result0, +initialBalance0-1);
|
||||
assert.equal(result1, +initialBalance1+1);
|
||||
});
|
||||
|
||||
|
||||
it("should unset approved amount", async function() {
|
||||
await ERC20Token.methods.approve(accountsArr[2],0).send({from: accountsArr[0]});
|
||||
let result = await ERC20Token.methods.allowance(accountsArr[0], accountsArr[2]).call();
|
||||
assert.equal(result, 0);
|
||||
});
|
||||
|
||||
it("should deposit approved amount to contract ERC20Receiver", async function() {
|
||||
await ERC20Token.methods.approve(ERC20Receiver.address,10).send({from: accountsArr[0]});
|
||||
await ERC20Receiver.methods.depositToken(ERC20Token.address).send({from: accountsArr[0]});
|
||||
let result = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call();
|
||||
assert.equal(result, 10, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accountsArr[0]+") wrong");
|
||||
});
|
||||
|
||||
it("should witdraw approved amount from contract ERC20Receiver", async function() {
|
||||
let tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call();
|
||||
await ERC20Receiver.methods.withdrawToken(ERC20Token.address, tokenBalance).send({from: accountsArr[0]});
|
||||
tokenBalance = await ERC20Receiver.methods.tokenBalanceOf(ERC20Token.address, accountsArr[0]).call();
|
||||
assert.equal(tokenBalance, 0, "ERC20Receiver.tokenBalanceOf("+ERC20Token.address+","+accountsArr[0]+") wrong");
|
||||
});
|
||||
|
||||
//TODO: include checks for expected events fired
|
||||
|
||||
|
||||
});
|
||||
}
|
@ -1,39 +1,55 @@
|
||||
const ERC20Token = require('./erc20token');
|
||||
const Utils = require('../utils/testUtils');
|
||||
const TestToken = require('Embark/contracts/TestToken');
|
||||
const ERC20TokenSpec = require('./abstract/erc20tokenspec');
|
||||
|
||||
describe("TestToken", async function() {
|
||||
this.timeout(0);
|
||||
var accountsArr;
|
||||
|
||||
before(function(done) {
|
||||
var contractsConfig = {
|
||||
config({
|
||||
contracts: {
|
||||
"TestToken": {
|
||||
},
|
||||
...ERC20TokenSpec.config.contracts
|
||||
}
|
||||
};
|
||||
EmbarkSpec.deployAll(contractsConfig, async function(accounts) {
|
||||
accountsArr = accounts
|
||||
done()
|
||||
});
|
||||
|
||||
contract("TestToken", function() {
|
||||
this.timeout(0);
|
||||
var accounts;
|
||||
before(function(done) {
|
||||
web3.eth.getAccounts().then(function (res) {
|
||||
accounts = res;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should increase totalSupply in mint", async function() {
|
||||
let initialSupply = await TestToken.methods.totalSupply().call();
|
||||
await TestToken.methods.mint(100).send({from: accountsArr[0]});
|
||||
await TestToken.methods.mint(100).send();
|
||||
let result = await TestToken.methods.totalSupply().call();
|
||||
assert.equal(result, +initialSupply+100);
|
||||
});
|
||||
|
||||
it("should increase accountBalance in mint", async function() {
|
||||
let initialBalance = await TestToken.methods.balanceOf(accountsArr[0]).call();
|
||||
await TestToken.methods.mint(100).send({from: accountsArr[0]});
|
||||
let result = await TestToken.methods.balanceOf(accountsArr[0]).call();
|
||||
let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call();
|
||||
await TestToken.methods.mint(100).send({from: accounts[0]});
|
||||
let result = await TestToken.methods.balanceOf(accounts[0]).call();
|
||||
assert.equal(result, +initialBalance+100);
|
||||
});
|
||||
var erc20tokenConfig = {
|
||||
"Contract": { "instanceOf" : "TestToken" }
|
||||
}
|
||||
ERC20Token.Test(erc20tokenConfig, async function (accounts, TestToken) {
|
||||
|
||||
it("should burn account supply", async function() {
|
||||
let initialBalance = await TestToken.methods.balanceOf(accounts[0]).call();
|
||||
await TestToken.methods.transfer(Utils.zeroAddress, initialBalance).send({from: accounts[0]});
|
||||
assert.equal(await TestToken.methods.totalSupply().call(), 0);
|
||||
assert.equal(await TestToken.methods.balanceOf(accounts[0]).call(), 0);
|
||||
})
|
||||
|
||||
it("should mint balances for ERC20TokenSpec", async function() {
|
||||
let initialBalance = 7 * 10 ^ 18;
|
||||
for(i=0;i<accounts.length;i++){
|
||||
await TestToken.methods.mint(7 * 10 ^ 18).send({from: accounts[i]})
|
||||
await TestToken.methods.mint(initialBalance).send({from: accounts[i]})
|
||||
assert.equal(await TestToken.methods.balanceOf(accounts[i]).call(), initialBalance);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
ERC20TokenSpec.Test(TestToken);
|
||||
|
||||
|
||||
});
|
||||
|
@ -214,12 +214,12 @@ exports.increaseTime = async (amount) => {
|
||||
params: [+amount],
|
||||
id: new Date().getSeconds()
|
||||
},
|
||||
(error) => {
|
||||
async (error) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return reject(err);
|
||||
}
|
||||
web3.currentProvider.sendAsync(
|
||||
await web3.currentProvider.sendAsync(
|
||||
{
|
||||
jsonrpc: '2.0',
|
||||
method: 'evm_mine',
|
||||
|
Loading…
x
Reference in New Issue
Block a user