Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
151 lines (127 loc) · 5.66 KB
/
Copy pathMakefile
File metadata and controls
151 lines (127 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
define run_2nd_test
ETH_RPC_URL="$${ETH_RPC_URL2:-$$ETH_RPC_URL}" \
ETHERSCAN_TOKEN="$${ETHERSCAN_TOKEN2:-$$ETHERSCAN_TOKEN}" \
poetry run $(1)
endef
# Get the latest block number from the target RPC node to use as FORKING_BLOCK_NUMBER for core tests
__get_rpc_latest_block_number:
@curl -s -X POST $(CORE_TESTS_TARGET_RPC_URL) \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
| sed -E 's/.*"result":"([^"]+)".*/\1/' \
| xargs printf "%d"
test:
ifdef vote
OMNIBUS_VOTE_IDS=$(vote) poetry run brownie test --network mfh-1
else
ifdef dg
DG_PROPOSAL_IDS=$(dg) poetry run brownie test --network mfh-1
else
poetry run brownie test --network mfh-1
endif
endif
# Prepared external fork used by Core integration tests.
CORE_TESTS_TARGET_RPC_URL ?= http://127.0.0.1:8547
CORE_TESTS_NETWORK ?= mainnet
CORE_DIR ?= lido-core
CORE_BRANCH ?= master
NODE_PORT ?= 8545
SECONDARY_NETWORK ?= mfh-2
NETWORK_STATE_FILE ?= deployed-mainnet.json
STONKS_DIR ?= ../stonks
test-1/2:
poetry run brownie test tests/[tc]*.py tests/regression/test_staking_router_stake_distribution.py tests/regression/test_permissions.py --durations=20 --network mfh-1
test-2/2:
$(call run_2nd_test,brownie test -k 'not test_staking_router_stake_distribution.py and not test_permissions.py' --durations=20 --network $(SECONDARY_NETWORK))
init: init-scripts init-core
init-scripts:
# NB: OpenZeppelin/openzeppelin-contracts@4.0.0 is a dirty copy paste from brownie-config.yml
# because current brownie version does not support pm install from the config file
poetry install && \
yarn && \
PYTHONPATH=$$PWD poetry run brownie pm install OpenZeppelin/openzeppelin-contracts@4.0.0 && \
PYTHONPATH=$$PWD poetry run brownie compile && \
poetry run brownie networks import network-config.yaml True
debug:
echo $(shell shell awk '/^\s*-/ { print substr($0, index($0,$2)) }' brownie-config.yml)
init-core:
if [ -d "$(CORE_DIR)" ]; then \
cd $(CORE_DIR) && \
git config pull.rebase false && \
git fetch origin $(CORE_BRANCH) && \
git checkout $(CORE_BRANCH); \
else \
git clone -b $(CORE_BRANCH) https://github.com/lidofinance/core.git $(CORE_DIR); \
cd $(CORE_DIR); \
fi && \
CI=true corepack yarn --immutable && \
corepack yarn compile && \
if [ ! -f .env ]; then \
cp .env.example .env; \
fi
docker-init:
docker exec -w /root/scripts scripts bash -c 'make init'
docker:
docker exec -it scripts /bin/bash
node:
npx hardhat node --fork $(ETH_RPC_URL) --port $(NODE_PORT)
node1:
npx hardhat node --fork $(ETH_RPC_URL) --port $(NODE_PORT)
node2:
npx hardhat node --fork $(ETH_RPC_URL2) --port $(NODE_PORT)
node3:
npx hardhat node --fork $(ETH_RPC_URL3) --port $(NODE_PORT)
test-core:
LATEST_BLOCK_NUMBER=$$($(MAKE) --no-print-directory __get_rpc_latest_block_number) && \
echo "LATEST_BLOCK_NUMBER: $$LATEST_BLOCK_NUMBER" && \
cd $(CORE_DIR) && \
NETWORK=$(CORE_TESTS_NETWORK) \
RUN_NETWORK=local \
MODE=forking \
UPGRADE=false \
RPC_URL=$(CORE_TESTS_TARGET_RPC_URL) \
NETWORK_STATE_FILE=$(NETWORK_STATE_FILE) \
FORKING_BLOCK_NUMBER=$$LATEST_BLOCK_NUMBER \
yarn test:integration
# Two passes, because enacting the vote warps the fork clock ~9 days ahead of the Chainlink updatedAt:
# suites pricing through the real FeedRegistry hit OracleStale after that, so they run on a clean fork.
# The suites below need the opposite — the post-vote NEST TokenRateNotifier — and price through a stub
# registry stamped with the current block timestamp, so the warp does not affect them.
STONKS_POSTVOTE_SUITES ?= staking-revenue-source buyback-happy-path
test-stonks-integration-prevote:
cd $(STONKS_DIR) && \
{ [ -d node_modules ] || npm ci; } && \
POSTVOTE_PATTERN="^test/integration/($$(echo $(STONKS_POSTVOTE_SUITES) | tr ' ' '|'))\.ts$$" && \
PREVOTE_SUITES=$$(ls test/integration/*.ts | grep -vE "$$POSTVOTE_PATTERN" || true) && \
{ [ -n "$$PREVOTE_SUITES" ] || { echo "No pre-vote suites left after excluding: $(STONKS_POSTVOTE_SUITES)" >&2; exit 1; }; } && \
RPC_URL=$(ETH_RPC_URL) npx hardhat test $$PREVOTE_SUITES --network localhost
test-stonks-integration-postvote: ci-prepare-environment
cd $(STONKS_DIR) && \
{ [ -d node_modules ] || npm ci; } && \
RPC_URL=$(ETH_RPC_URL) npx hardhat test $(patsubst %,test/integration/%.ts,$(STONKS_POSTVOTE_SUITES)) --network localhost
slots:
@echo "Input https://github.com/lidofinance/protocol-onchain-mon-bots/blob/main/bots/ethereum-steth-v2/src/utils/constants.mainnet.ts file content (end with Enter and Ctrl+D):"
@cat | grep -v "import { ERC20 } from './constants'" | sed 's/ERC20/any/g' > slots2.ts
@cat \
| grep -v "import { ERC20 } from './constants'" \
| sed 's/ERC20/any/g' \
> slots.ts
@echo "Input https://github.com/lidofinance/protocol-onchain-mon-bots/blob/main/bots/ethereum-steth-v2/src/services/protocol/storage-watcher/constants.ts file content (end with Enter and Ctrl+D):"
@cat \
| grep -v "import { StorageSlot } from '../../../entity/storage_slot'" \
| sed "s|import { Address } from '../../../utils/constants.mainnet'|import { Address } from './slots2.ts'|g" \
| sed 's/StorageSlot/any/g' \
> slots.ts
@cat check_storage_slots.ts >> slots.ts
@echo "Checking storage slots against 127.0.0.1:8545..."
@npx tsx slots.ts
@rm -f slots.ts
@rm -f slots2.ts
ci-prepare-environment:
poetry run brownie run scripts/ci/prepare_environment --network mfh-1
# Core tests operate on vaults, and VaultHub rejects a vaults report older than 2 days, while
# enacting the vote leaves the fork clock ~9 days past the last one.
ci-refresh-vaults-report:
poetry run brownie run scripts/ci/refresh_vaults_report --network mfh-1
enact-fork:
poetry run brownie run $(vote) start_and_execute_vote_on_fork_manual --network=mfh-1