Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plain solc #74

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 108 additions & 77 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,125 @@
aliases:
- &update-npm
name: Update npm to the latest version
command: sudo npm install -g npm@latest
version: 2.1

- &save-dependencies-cache
key: v1-dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
executors:
node:
docker:
- image: circleci/node:11.10.0
working_directory: ~/ERC777

- &restore-dependencies-cache
keys:
- v1-dependency-cache-{{ checksum "package.json" }}
- v1-dependency-cache-

- &save-build-cache
key: v1-build-cache-{{ .BuildNum }}
paths:
- ./build

- &restore-build-cache
keys:
- v1-build-cache-{{ .BuildNum }}
- v1-build-cache-
- &filter-all-tags
tags:
only: /.*/
commands:
restore-dependencies:
steps:
- restore_cache:
keys:
- v1-dependency-cache-{{ checksum "package.json" }}
- v1-dependency-cache-

defaults: &defaults
docker:
- image: circleci/node:10.6.0
working_directory: ~/erc777
restore-build:
steps:
- restore_cache:
keys:
- v1-build-cache-{{ .BuildNum }}
- v1-build-cache-

version: 2
restore-solc:
steps:
- run:
name: Set write permissions
command: sudo chmod go+w /opt
- restore_cache:
keys:
- v1-solc-cache-{{ .BuildNum }}
- v1-solc-cache-
- run:
name: Update $PATH
command: echo 'export PATH="/opt:$PATH"' >> $BASH_ENV

jobs:
install-dependencies:
<<: *defaults
install solc:
executor: node
steps:
- run:
name: Download solc
command: curl -L "https://github.com/ethereum/solidity/releases/download/v0.5.3/solc-static-linux" -o /tmp/solc
- run:
name: Verify solc download
command: echo "be08eb95cb3a1da52e918cf51a0c0397fbe7f0693145eb31835bf2924209f1e0 /tmp/solc" | sha256sum -c -
- run:
name: Make solc executable
command: chmod +x /tmp/solc
- run:
name: Install solc
command: sudo mv /tmp/solc /opt/solc
- save_cache:
key: v1-solc-cache-{{ .BuildNum }}
paths:
- /opt/solc
- run:
name: Solc version
command: /opt/solc --version

install dependencies:
executor: node
steps:
- run: *update-npm
- checkout
- run:
name: Install npm dependencies with npm ci
command: npm ci
- save_cache: *save-dependencies-cache
- save_cache:
key: v1-dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules

build:
<<: *defaults
executor: node
steps:
- run: *update-npm
- checkout
- restore_cache: *restore-dependencies-cache
- restore-solc
- restore-dependencies
- run:
name: Build Solidity
command: npm run build
- save_cache: *save-build-cache
lint-solidity:
<<: *defaults
- save_cache:
key: v1-build-cache-{{ .BuildNum }}
paths:
- ./artifacts

lint solidity:
executor: node
steps:
- checkout
- restore_cache: *restore-dependencies-cache
- restore-dependencies
- run:
name: Lint Solidity
command: npm run lint:sol
lint-javascript:
<<: *defaults

lint javascript:
executor: node
steps:
- run: *update-npm
- checkout
- restore_cache: *restore-dependencies-cache
- restore-dependencies
- run:
name: Lint Javascript
name: Lint JavaScript
command: npm run lint:js

test:
<<: *defaults
executor: node
steps:
- run: *update-npm
- checkout
- restore_cache: *restore-dependencies-cache
- restore_cache: *restore-build-cache
- restore-dependencies
- restore-build
- restore-solc
- run:
name: Test
command: npm run test

coverage:
<<: *defaults
executor: node
steps:
- run: *update-npm
- checkout
- restore_cache: *restore-dependencies-cache
- restore_cache: *restore-build-cache
- restore-dependencies
- restore-build
- restore-solc
- run:
name: Tests with coverage
command: npm run coverage
Expand All @@ -99,13 +132,17 @@ jobs:
- run:
name: Enforce minimum coverage threshold
command: npx istanbul check-coverage --statements 95 --functions 95 --branches 95 --lines 95

publish:
<<: *defaults
executor: node
steps:
- run: *update-npm
- checkout
- restore_cache: *restore-dependencies-cache
- restore_cache: *restore-build-cache
- run:
name: Verify branch & version tag
command: .circleci/deploy-check.sh
- restore-dependencies
- restore-build
- restore-solc
- run:
name: Set npm auth token
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
Expand All @@ -117,37 +154,31 @@ workflows:
version: 2
ci_cd:
jobs:
- install-dependencies:
filters: *filter-all-tags
- install solc
- install dependencies
- build:
requires:
- install-dependencies
filters: *filter-all-tags
- lint-solidity:
- install solc
- install dependencies
- lint solidity:
requires:
- install-dependencies
filters: *filter-all-tags
- lint-javascript:
- install dependencies
- lint javascript:
requires:
- install-dependencies
filters: *filter-all-tags
- install dependencies
- test:
requires:
- lint solidity
- lint javascript
- build
filters: *filter-all-tags
- coverage:
requires:
- lint solidity
- lint javascript
- build
filters: *filter-all-tags
- publish:
requires:
- build
- test
- coverage
- lint-solidity
- lint-javascript
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
only: master
35 changes: 35 additions & 0 deletions .circleci/deploy-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Simple script to make sure the current build is on the production branch and
# has the correct version tag.
# This script is used as a check to prevent from deploying a wrong version to
# the docs.

DIR=$(dirname "$(realpath $0)")

say() {
printf "[%s] %s\n" "$0" "$*" >&2
}

die() {
say "$*"
exit 100
}

check_branch() {
if [[ "$CIRCLE_BRANCH" != "master" ]]; then
die "Error: Invalid branch name '$CIRCLE_BRANCH', expected master"
fi
}

check_tag() {
NPM_VERSION=$(node -p "require('${DIR}/../package.json').version")
DISTANCE=$(git rev-list --count "v$NPM_VERSION..HEAD")
if [[ "$DISTANCE" != "0" ]]; then
die "Error: Production branch must point to the current version tag ($DISTANCE commits ahead)"
fi
}

check_branch
check_tag

2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
"no-debugger": 0,
"no-undef": "error",
"object-curly-spacing": ["error", "always"],
"max-len": ["error", 80, 2],
"max-len": ["error", 120, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
node_modules
coverage
coverage.json
artifacts
File renamed without changes.
48 changes: 27 additions & 21 deletions contracts/examples/ReferenceToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ contract ReferenceToken is ERC777ERC20BaseToken, Ownable {
event ERC20Enabled();
event ERC20Disabled();

address private mBurnOperator;
mapping(address => bool) private mBurnOperators;

constructor(
string memory _name,
string memory _symbol,
uint256 _granularity,
address[] memory _defaultOperators,
address _burnOperator,
uint256 _initialSupply
)
public ERC777ERC20BaseToken(_name, _symbol, _granularity, _defaultOperators)
{
mBurnOperator = _burnOperator;
doMint(msg.sender, _initialSupply, "", "");
}

Expand All @@ -53,22 +51,12 @@ contract ReferenceToken is ERC777ERC20BaseToken, Ownable {
emit ERC20Enabled();
}

/* -- Mint And Burn Functions (not part of the ERC777 standard, only the Events/tokensReceived call are) -- */
//
/// @notice Generates `_amount` tokens to be assigned to `_tokenHolder`
/// Sample mint function to showcase the use of the `Minted` event and the logic to notify the recipient.
/// @param _tokenHolder The address that will be assigned the new tokens
/// @param _amount The quantity of tokens generated
/// @param _operatorData Data that will be passed to the recipient as a first transfer
function mint(
address _tokenHolder,
uint256 _amount,
bytes calldata _data,
bytes calldata _operatorData
)
external onlyOwner
{
doMint(_tokenHolder, _amount, _data, _operatorData);
function allowBurn(address burnOperator) external onlyOwner {
mBurnOperators[burnOperator] = true;
}

function revokeBurn(address burnOperator) external onlyOwner {
mBurnOperators[burnOperator] = true;
}

/// @notice Burns `_amount` tokens from `msg.sender`
Expand All @@ -92,13 +80,31 @@ contract ReferenceToken is ERC777ERC20BaseToken, Ownable {
bytes calldata _data,
bytes calldata _operatorData
)
external
external
{
require(msg.sender == mBurnOperator, "Not a burn operator");
require(mBurnOperators[msg.sender], "Not a burn operator");
require(isOperatorFor(msg.sender, _tokenHolder), "Not an operator");
doBurn(msg.sender, _tokenHolder, _amount, _data, _operatorData);
}

/* -- Mint Function (not part of the ERC777 standard, only the Events/tokensReceived call are) -- */
//
/// @notice Generates `_amount` tokens to be assigned to `_tokenHolder`
/// Sample mint function to showcase the use of the `Minted` event and the logic to notify the recipient.
/// @param _tokenHolder The address that will be assigned the new tokens
/// @param _amount The quantity of tokens generated
/// @param _operatorData Data that will be passed to the recipient as a first transfer
function mint(
address _tokenHolder,
uint256 _amount,
bytes calldata _data,
bytes calldata _operatorData
)
external onlyOwner
{
doMint(_tokenHolder, _amount, _data, _operatorData);
}

function doMint(address _tokenHolder, uint256 _amount, bytes memory _data, bytes memory _operatorData) private {
requireMultiple(_amount);
mTotalSupply = mTotalSupply.add(_amount);
Expand Down
Loading