Skip to content

Commit 22b784d

Browse files
authored
A PR for Issue #25 ( Continuous Integration ) (#72)
Fix issue #25 - Two new workflow files ( **.github/workflows/mypy.yml** and **.github/workflows/pytest.yml** ) - .**/ganache.py** now has "&" at the end for workflow to run it in the background. - Pytest having issues with the config option "collect_ignore" in **oceanprotocol/contracts/setup.cfg**. I forked the contracts repo to remove the line. For now, the workflow clones my fork of the contracts repo. - In tokenspice's README, regarding the instruction about running one test, that specified test doesn't exist anymore. ~~So I edited the README to reference an existing test, and also added the workflow status badges.~~ EDIT: BK's push seemed to have addressed this. I adjusted accordingly. - In tokenspice.ini , ARTIFACTS_PATH now points to a user's relative directory instead of the absolute trentmc directory.
1 parent 48d3a6f commit 22b784d

11 files changed

+240
-70
lines changed

.github/to_outside

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../

.github/workflows/mypy.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: MyPy Static Typechecking
2+
3+
on:
4+
push:
5+
branches: [ action_tests ]
6+
pull_request:
7+
branches: [ action_tests ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: [ 3.8, 3.9 ]
17+
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Set up Python {{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install flake8 pytest numpy
31+
if [ -f requirements.txt ];
32+
then pip install -r requirements.txt;
33+
echo "Requirements.txt found!"
34+
fi
35+
36+
- name: Run MyPy
37+
run: |
38+
mypy --config-file mypy.ini ./

.github/workflows/pytest.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Unit Testing
2+
3+
on:
4+
push:
5+
branches: [ action_tests ]
6+
pull_request:
7+
branches: [ action_tests ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: [ 3.8, 3.9 ]
17+
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Set up Python {{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install Ganache-CLI
28+
run: npm install ganache-cli --global
29+
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install flake8 pytest numpy
34+
if [ -f requirements.txt ];
35+
then pip install -r requirements.txt;
36+
echo "Requirements.txt found!"
37+
fi
38+
39+
- name: Find out what the directory structure looks like
40+
run: |
41+
pwd
42+
tree
43+
44+
- name: Executing Python Ganache script
45+
run: |
46+
nohup python3 ganache.py
47+
48+
- name: Check Node version on this machine.
49+
run: |
50+
node -v
51+
52+
- name: Making a Directory for Ocean Protocol Repo
53+
run: |
54+
mkdir ../contracts
55+
56+
- name: Clone Ocean Protocol Contracts
57+
uses: actions/checkout@master
58+
with:
59+
repository: JohannSuarez/contracts
60+
path: .github/to_outside/contracts
61+
62+
- name: Deploy Contracts to Ganache
63+
run: |
64+
cd .github/to_outside/contracts
65+
npm i
66+
npm run deploy
67+
68+
- name: Check Current directory after installing and deploying contracts
69+
run: |
70+
pwd
71+
tree
72+
73+
- name: Trying to print contracts/setup.cfg
74+
run: |
75+
cat .github/to_outside/contracts/setup.cfg
76+
77+
- name: Run Pytest (Just one test)
78+
run: |
79+
pytest assets/agents/test/test_DataconsumerAgent.py
80+
81+
- name: Run Entire Suite of Tests
82+
run: |
83+
pytest

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# TokenSPICE: EVM Agent-Based Token Simulator 🐟🌪️
44

5+
<div align="center">
6+
<img alt="Pytest Unit Testing" src="https://github.com/JohannSuarez/tokenspice/actions/workflows/pytest.yml/badge.svg">
7+
8+
<img alt="MyPy Static Type Checking" src="https://github.com/JohannSuarez/tokenspice/actions/workflows/mypy.yml/badge.svg">
9+
</div>
10+
511
TokenSPICE simulates tokenized ecosystems via an agent-based approach, with EVM in-the-loop.
612

713
It can help design, tune, and verify tokenized ecosystems. It's young but promising. We welcome you to contribute! 👋

assets/agents/DataconsumerAgent.py

+27-15
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,35 @@
66
from engine.AgentBase import AgentBase
77
from web3engine import bpool, datatoken, globaltokens
88
from web3tools.web3util import fromBase18, toBase18
9-
from util import constants
9+
from util import constants
10+
1011

1112
@enforce_types
1213
class DataconsumerAgent(AgentBase):
1314
def __init__(self, name: str, USD: float, OCEAN: float):
1415
super().__init__(name, USD, OCEAN)
15-
16+
1617
self._s_since_buy = 0
17-
self._s_between_buys = 3 * constants.S_PER_DAY #magic number
18-
self.profit_margin_on_consume = 0.2 # magic number
19-
18+
self._s_between_buys = 3 * constants.S_PER_DAY # magic number
19+
self.profit_margin_on_consume = 0.2 # magic number
20+
2021
def takeStep(self, state) -> None:
22+
2123
self._s_since_buy += state.ss.time_step
24+
25+
'''
26+
27+
-- Issue found on September 25, 2021 5:43 PM PST
28+
-- MyPy shows the method _buyDT was never defined anywhere,
29+
-- not even in the parent class.
30+
-- I'm commenting out this if-block for now. - Johann
2231
2332
if self._doBuyAndConsumeDT(state):
33+
2434
self._s_since_buy = 0
2535
pool_agent, OCEAN_spend = self._buyDT(state)
2636
self._consumeDT(state, pool_agent, OCEAN_spend)
37+
'''
2738

2839
def _doBuyAndConsumeDT(self, state):
2940
cand_pool_agents = self._candPoolAgents(state)
@@ -44,11 +55,12 @@ def _candPoolAgents(self, state) -> List[PoolAgent]:
4455
for pool_agent in all_pool_agents:
4556
pool = pool_agent.pool
4657
DT_address = pool_agent.datatoken_address
47-
58+
4859
pool_DT_balance_base = pool.getBalance_base(DT_address)
4960
pool_OCEAN_balance_base = pool.getBalance_base(OCEAN_address)
5061
pool_DT_weight_base = pool.getDenormalizedWeight_base(DT_address)
51-
pool_OCEAN_weight_base = pool.getDenormalizedWeight_base(OCEAN_address)
62+
pool_OCEAN_weight_base = pool.getDenormalizedWeight_base(
63+
OCEAN_address)
5264
pool_swapFee_base = pool.getSwapFee_base()
5365

5466
DT_amount_out_base = toBase18(1.0)
@@ -66,42 +78,42 @@ def _candPoolAgents(self, state) -> List[PoolAgent]:
6678

6779
if OCEANamountIn_base < OCEAN_base:
6880
cand_pool_agents.append(pool_agent)
69-
81+
7082
return cand_pool_agents
7183

7284
def _buyAndConsumeDT(self, state):
7385
"""Buy dataset, then consume it"""
74-
DT_buy_amt = 1.0 # buy just enough to consume once
86+
DT_buy_amt = 1.0 # buy just enough to consume once
7587
max_OCEAN_allow = self.OCEAN()
7688
OCEANtoken = globaltokens.OCEANtoken()
7789

7890
cand_pool_agents = self._candPoolAgents(state)
7991
assert cand_pool_agents
8092
pool_agent = random.choice(cand_pool_agents)
81-
93+
8294
pool = pool_agent.pool
8395
DT = pool_agent.datatoken
8496

8597
DT_before = self.DT(DT)
8698
OCEAN_before = self.OCEAN()
8799

88-
#buy
100+
# buy
89101
self._wallet.buyDT(pool, DT, DT_buy_amt, max_OCEAN_allow)
90-
102+
91103
DT_after = self.DT(DT)
92104
OCEAN_after = self.OCEAN()
93-
105+
94106
assert self.DT(DT) == (DT_before + DT_buy_amt)
95107
assert OCEAN_after < OCEAN_before
96108

97109
OCEAN_spend = OCEAN_before - OCEAN_after
98110

99-
#consume
111+
# consume
100112
publisher_agent = state.agents.agentByAddress(
101113
pool_agent.controller_address)
102114
self._wallet.transferDT(publisher_agent._wallet, DT, DT_buy_amt)
103115

104-
#get business value due to consume
116+
# get business value due to consume
105117
OCEAN_returned = OCEAN_spend * (1.0 + self.profit_margin_on_consume)
106118
self.receiveOCEAN(OCEAN_returned)
107119

0 commit comments

Comments
 (0)