mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2024-11-22 01:36:46 +01:00
Merge branch 'master' into lash/statictoken
This commit is contained in:
commit
4f7a068164
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ build/
|
|||||||
gmon.out
|
gmon.out
|
||||||
*.egg-info
|
*.egg-info
|
||||||
.venv/
|
.venv/
|
||||||
|
.idea
|
@ -1,26 +1,67 @@
|
|||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
|
- run-coverage
|
||||||
- slither-analyzer
|
- slither-analyzer
|
||||||
|
|
||||||
test:
|
|
||||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-py-alpine:latest
|
variables:
|
||||||
cache:
|
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
||||||
- key:
|
|
||||||
files:
|
cache:
|
||||||
- requirements.txt
|
|
||||||
- test_requirements.txt
|
|
||||||
paths:
|
paths:
|
||||||
- /root/.cache/pip
|
- .cache/pip
|
||||||
|
- venv/
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- python -V # Print out python version for debugging
|
||||||
|
- pip install virtualenv
|
||||||
|
- virtualenv venv
|
||||||
|
- source venv/bin/activate
|
||||||
|
|
||||||
|
test:
|
||||||
|
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||||
script:
|
script:
|
||||||
- cd python
|
# build abi
|
||||||
- pip install --extra-index-url https://pip.grassrootseconomics.net:8433 -r test_requirements.txt
|
- 'echo "Running Solc Version: $(solc --version)"'
|
||||||
- pip install --extra-index-url https://pip.grassrootseconomics.net:8433 -r test_requirements.txt
|
- cd solidity
|
||||||
|
- solc --evm-version=byzantium GiftableToken.sol --abi | awk 'NR>3' > GiftableToken.abi.json
|
||||||
|
# build bin
|
||||||
|
- solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin &&
|
||||||
|
truncate -s "$((`stat -t -c "%s" GiftableToken.bin`-1))" GiftableToken.bin
|
||||||
|
# install test dependencies
|
||||||
|
- cd ../python
|
||||||
|
- export PYTHONPATH=.
|
||||||
|
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
||||||
|
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
||||||
|
-r requirements.txt -r test_requirements.txt
|
||||||
|
# run tests
|
||||||
- bash run_tests.sh
|
- bash run_tests.sh
|
||||||
|
|
||||||
|
run-coverage:
|
||||||
slither-analize:
|
stage: test
|
||||||
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-py-alpine:latest
|
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||||
script:
|
script:
|
||||||
- pip install slither-analyzer
|
- cd python
|
||||||
- slither solidity/
|
- export PYTHONPATH=.
|
||||||
|
- pip install --extra-index-url https://pip.grassrootseconomics.net
|
||||||
|
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
|
||||||
|
-r requirements.txt -r test_requirements.txt
|
||||||
|
- pip install pytest pytest-cov
|
||||||
|
- coverage run -m pytest
|
||||||
|
- coverage html
|
||||||
|
- coverage report --fail-under=90
|
||||||
|
|
||||||
|
coverage: '/^TOTAL.+?(\d+\%)$/'
|
||||||
|
artifacts:
|
||||||
|
reports:
|
||||||
|
cobertura: python/htmlcov/index.html
|
||||||
|
|
||||||
|
slither-analyzer:
|
||||||
|
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- cd solidity
|
||||||
|
- slither GiftableToken.sol
|
||||||
|
- slither GiftableToken.sol --print human-summary
|
||||||
|
|
||||||
|
|
||||||
|
33
Dockerfile
33
Dockerfile
@ -1,33 +0,0 @@
|
|||||||
FROM ethereum/solc:0.6.12
|
|
||||||
|
|
||||||
FROM python:3.8.6-alpine
|
|
||||||
|
|
||||||
COPY --from=0 /usr/bin/solc /usr/bin/solc
|
|
||||||
|
|
||||||
RUN apk update &&\
|
|
||||||
apk add gcc bash musl-dev libffi-dev openssl-dev autoconf automake build-base \
|
|
||||||
libtool pkgconfig python3-dev cargo
|
|
||||||
|
|
||||||
WORKDIR /usr/src
|
|
||||||
|
|
||||||
# Try to keep everything above here re-usable!
|
|
||||||
|
|
||||||
COPY ./solidity/ /usr/src/giftable_erc20_token/solidity/
|
|
||||||
COPY ./python/ /usr/src/giftable_erc20_token/python/
|
|
||||||
|
|
||||||
RUN chmod +x ./python/run_tests.sh
|
|
||||||
|
|
||||||
RUN cd giftable_erc20_token/solidity && \
|
|
||||||
solc GiftableToken.sol --abi | awk 'NR>3' > GiftableToken.abi.json
|
|
||||||
|
|
||||||
RUN cd giftable_erc20_token/solidity && \
|
|
||||||
solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin && \
|
|
||||||
truncate -s "$((`stat -t -c "%s" GiftableToken.bin`-1))" GiftableToken.bin
|
|
||||||
|
|
||||||
RUN cd giftable_erc20_token/python && \
|
|
||||||
pip install --extra-index-url https://pip.grassrootseconomics.net:8433 .
|
|
||||||
|
|
||||||
RUN pip install slither-analyzer
|
|
||||||
|
|
||||||
# To deploy:
|
|
||||||
# giftable-token-deploy --contracts-dir giftable_erc20_token/solidity/ <amount>
|
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# ETH-ERC20 Solidity Contract
|
||||||
|
|
||||||
|
|
||||||
|
### solidity
|
||||||
|
|
||||||
|
To generate bytecode and tests install solc 8.x.x and run the solc bits below or execute the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -v `pwd`:/src registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest solc --evm-version=byzantium solidity/GiftableToken.sol --abi
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -v `pwd`:/src registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest solc GiftableToken.sol --bin | awk 'NR>3' > GiftableToken.bin
|
||||||
|
```
|
||||||
|
|
||||||
|
### python unit tests
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install --extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple \
|
||||||
|
--extra-index-url https://pip.grassrootseconomics.net \
|
||||||
|
-r requirements.txt -r test_requirements.txt
|
||||||
|
|
||||||
|
bash python/run_tests.sh
|
||||||
|
|
||||||
|
```
|
BIN
python/.coverage
Normal file
BIN
python/.coverage
Normal file
Binary file not shown.
7
python/.coveragerc
Normal file
7
python/.coveragerc
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[run]
|
||||||
|
branch = True
|
||||||
|
[report]
|
||||||
|
omit = .venv/*
|
||||||
|
**/runnable/*.py
|
||||||
|
[html]
|
||||||
|
|
0
python/run_tests.sh
Normal file → Executable file
0
python/run_tests.sh
Normal file → Executable file
@ -12,6 +12,7 @@ from chainlib.eth.tx import (
|
|||||||
receipt,
|
receipt,
|
||||||
)
|
)
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from giftable_erc20_token import GiftableToken
|
from giftable_erc20_token import GiftableToken
|
||||||
@ -102,7 +103,7 @@ class TestToken(EthTesterCase):
|
|||||||
o = transaction(tx_hash)
|
o = transaction(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
data = c.parse_transfer_request(r['data'])
|
data = c.parse_transfer_request(r['data'])
|
||||||
self.assertEqual(data[0], self.accounts[1])
|
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||||
self.assertEqual(data[1], 1000)
|
self.assertEqual(data[1], 1000)
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ class TestToken(EthTesterCase):
|
|||||||
o = transaction(tx_hash)
|
o = transaction(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
data = c.parse_approve_request(r['data'])
|
data = c.parse_approve_request(r['data'])
|
||||||
self.assertEqual(data[0], self.accounts[1])
|
self.assertEqual(data[0], strip_0x(self.accounts[1]))
|
||||||
self.assertEqual(data[1], 1000)
|
self.assertEqual(data[1], 1000)
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
nonce_oracle = RPCNonceOracle(self.accounts[1], conn=self.conn)
|
||||||
@ -138,8 +139,8 @@ class TestToken(EthTesterCase):
|
|||||||
o = transaction(tx_hash)
|
o = transaction(tx_hash)
|
||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
data = c.parse_transfer_from_request(r['data'])
|
data = c.parse_transfer_from_request(r['data'])
|
||||||
self.assertEqual(data[0], self.accounts[0])
|
self.assertEqual(data[0], strip_0x(self.accounts[0]))
|
||||||
self.assertEqual(data[1], self.accounts[2])
|
self.assertEqual(data[1], strip_0x(self.accounts[2]))
|
||||||
self.assertEqual(data[2], 1001)
|
self.assertEqual(data[2], 1001)
|
||||||
|
|
||||||
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000)
|
(tx_hash, o) = c.transfer_from(self.address, self.accounts[1], self.accounts[0], self.accounts[2], 1000)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pragma solidity >0.6.11;
|
pragma solidity >=0.6.11;
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
// File-Version: 2
|
// File-Version: 2
|
||||||
|
Loading…
Reference in New Issue
Block a user