mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-13 07:14:29 +00:00
991d958436
[PR 1318][PR1318] introduces a monorepo member that's used as a DApp dependency, but the present arrangement whereby `test_dapps/` is an embedded monorepo makes it difficult to develop and test such packages in tandem with changes to `test_dapps/packages/*`. Reorganize `test_dapps/*` as members of the root monorepo and make various adjustments accordingly. This makes it easy to develop test dapps and any packages they depend on simultaneously, but we lose the CI/QA arrangement where test dapps are run with an embark installed from fresh tarballs. That arrangement, which is quite worthwhile as a means to detect problems arising from transitive dependencies as soon as possible, will be re-introduced in another PR, possibly involving an auxiliary repository such as embark-framework/dapp-bin. Since the `package.json` `"test"` scripts of `test_dapps/*` are now kicked off as part of `yarn test` in the root, and since port allocation isn't fully dynamic, it's important to run `yarn test` with `lerna run`'s `--concurrency=1` option. For the same reasons, the root `ci` and `qa` scripts are similarly restricted. In the future, this setup can be refactored and improved, along with use of `lerna run`'s `--since` option to increase testing efficiency in CI. [PR1318]: https://github.com/embark-framework/embark/pull/1318
67 lines
2.1 KiB
Solidity
67 lines
2.1 KiB
Solidity
// https://github.com/nexusdev/erc20/blob/master/contracts/base.sol
|
|
|
|
pragma solidity ^0.4.17;
|
|
contract Token {
|
|
|
|
event Transfer(address indexed from, address indexed to, uint value);
|
|
event Approval( address indexed owner, address indexed spender, uint value);
|
|
|
|
mapping( address => uint ) _balances;
|
|
mapping( address => mapping( address => uint ) ) _approvals;
|
|
uint public _supply;
|
|
//uint public _supply2;
|
|
constructor( uint initial_balance ) public {
|
|
_balances[msg.sender] = initial_balance;
|
|
_supply = initial_balance;
|
|
}
|
|
function totalSupply() public constant returns (uint supply) {
|
|
return _supply;
|
|
}
|
|
function balanceOf( address who ) public constant returns (uint value) {
|
|
return _balances[who];
|
|
}
|
|
function transfer( address to, uint value) public returns (bool ok) {
|
|
if( _balances[msg.sender] < value ) {
|
|
revert();
|
|
}
|
|
if( !safeToAdd(_balances[to], value) ) {
|
|
revert();
|
|
}
|
|
_balances[msg.sender] -= value;
|
|
_balances[to] += value;
|
|
emit Transfer( msg.sender, to, value );
|
|
return true;
|
|
}
|
|
function transferFrom( address from, address to, uint value) public returns (bool ok) {
|
|
// if you don't have enough balance, throw
|
|
if( _balances[from] < value ) {
|
|
revert();
|
|
}
|
|
// if you don't have approval, throw
|
|
if( _approvals[from][msg.sender] < value ) {
|
|
revert();
|
|
}
|
|
if( !safeToAdd(_balances[to], value) ) {
|
|
revert();
|
|
}
|
|
// transfer and return true
|
|
_approvals[from][msg.sender] -= value;
|
|
_balances[from] -= value;
|
|
_balances[to] += value;
|
|
emit Transfer( from, to, value );
|
|
return true;
|
|
}
|
|
function approve(address spender, uint value) public returns (bool ok) {
|
|
// TODO: should increase instead
|
|
_approvals[msg.sender][spender] = value;
|
|
emit Approval( msg.sender, spender, value );
|
|
return true;
|
|
}
|
|
function allowance(address owner, address spender) public constant returns (uint _allowance) {
|
|
return _approvals[owner][spender];
|
|
}
|
|
function safeToAdd(uint a, uint b) internal pure returns (bool) {
|
|
return (a + b >= a);
|
|
}
|
|
}
|