Skip to content

Commit 65f905f

Browse files
authored
Fix ccq (#57)
* cleanup, fix, refactor * remove missed trailing spaces * fix guardian set rotation issue, stick to custom errors only * rebase, rebuild tests on WormholeOverride, add missing NoQuorum test * remove package-lock to always pull latest version of TS SDK * use Makefile for CI
1 parent 88c4a6d commit 65f905f

26 files changed

+2536
-3083
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
- name: Run Forge build
3030
run: |
3131
forge --version
32-
forge build --sizes
32+
make
3333
id: build
3434

3535
- name: Run Forge tests
3636
run: |
37-
forge test -vvv
37+
make test
3838
id: test

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#the chain that will be forked for testing
2+
TEST_FORK = Mainnet Ethereum
3+
4+
.DEFAULT_GOAL = build
5+
.PHONY: build test clean
6+
7+
build:
8+
@$(MAKE) -C gen build
9+
forge build
10+
11+
#include (and build if necessary) env/testing.env if we're running tests
12+
ifneq (,$(filter test, $(MAKECMDGOALS)))
13+
#hacky:
14+
_ := $(shell $(MAKE) -C gen testing.env "TEST_FORK=$(strip $(TEST_FORK))")
15+
include gen/testing.env
16+
export
17+
unexport TEST_FORK
18+
endif
19+
test: build
20+
forge test
21+
22+
clean:
23+
@$(MAKE) -C gen clean
24+
forge clean

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ remappings = [
1818
"IERC20/=src/interfaces/token/",
1919
]
2020

21-
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
21+
verbosity = 3

gen/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.package-lock.json

gen/Makefile

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
1-
GENEREATORS = chains cctpDomains
2-
chains_TARGET = ../src/constants/Chains.sol
3-
cctpDomains_TARGET = ../src/constants/CCTPDomains.sol
1+
GENERATORS = chains cctpDomains
2+
chains_TARGET = constants/Chains.sol
3+
cctpDomains_TARGET = constants/CCTPDomains.sol
44

5-
TEST_WRAPPERS = BytesParsing
6-
BytesParsing_BASE_PATH = libraries
5+
fnGeneratorTarget = ../src/$($(1)_TARGET)
6+
GENERATOR_TARGETS = $(foreach generator,$(GENERATORS),$(call fnGeneratorTarget,$(generator)))
7+
8+
TEST_WRAPPERS = BytesParsing QueryResponse
79

810
fnTestWrapperTarget = ../test/generated/$(1)TestWrapper.sol
911
TEST_WRAPPER_TARGETS =\
10-
$(foreach wrapper, $(TEST_WRAPPERS), $(call fnTestWrapperTarget,$(wrapper)))
12+
$(foreach wrapper,$(TEST_WRAPPERS),$(call fnTestWrapperTarget,$(wrapper)))
13+
14+
.DEFAULT_GOAL = build
15+
.PHONY: build clean FORCE
1116

12-
.PHONY: generate $(GENEREATORS)
17+
build: $(GENERATOR_TARGETS) $(TEST_WRAPPER_TARGETS)
1318

14-
build: $(GENEREATORS) $(TEST_WRAPPER_TARGETS)
19+
clean:
20+
rm -rf node_modules fork_changed testing.env
1521

16-
$(GENEREATORS): node_modules
17-
npx ts-node $@.ts > $($@_TARGET)
22+
FORCE:
1823

19-
node_modules: package-lock.json
20-
npm ci
24+
node_modules:
25+
npm i
26+
27+
define ruleGenerator
28+
$(call fnGeneratorTarget,$(1)): node_modules $(1).ts
29+
npx ts-node $(1).ts > $$@
30+
endef
31+
$(foreach generator,$(GENERATORS),$(eval $(call ruleGenerator,$(generator))))
2132

2233
define ruleTestWrapper
23-
$(call fnTestWrapperTarget,$(1)): ../src/$($(1)_BASE_PATH)/$(1).sol
24-
npx ts-node libraryTestWrapper.ts $($(1)_BASE_PATH)/$(1) > $(call fnTestWrapperTarget,$(1))
34+
$(call fnTestWrapperTarget,$(1)): ../src/libraries/$(1).sol libraryTestWrapper.ts
35+
npx ts-node libraryTestWrapper.ts libraries/$(1) > $$@
2536
endef
2637
$(foreach wrapper,$(TEST_WRAPPERS),$(eval $(call ruleTestWrapper,$(wrapper))))
2738

39+
ifneq ($(TEST_FORK), $(shell cat fork_changed 2>/dev/null))
40+
#if a different chain/network for testing was supplied last time then force an update
41+
fork_changed: FORCE
42+
endif
43+
44+
testing.env: node_modules fork_changed testingEnv.ts
45+
@echo "Generating testing.env for $(TEST_FORK)"
46+
npx ts-node testingEnv.ts $(TEST_FORK) > $@
2847

48+
fork_changed:
49+
@echo $(TEST_FORK) > fork_changed

gen/fork_changed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Mainnet Ethereum

gen/libraryTestWrapper.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ for (const libs of libMatches) {
107107
const retParasRaw = modsRaw.match(retParasRegex);
108108

109109
const collapseSpaceRegex = /\s\s+/g;
110-
const paramsToArray = (paramList: string) =>
111-
paramList.replace(collapseSpaceRegex, ' ').trim().split(',').map(param => {
110+
const paramsToArray = (paramList: string) => {
111+
const cleaned = paramList.replace(collapseSpaceRegex, ' ').trim();
112+
return !cleaned ? [] : cleaned.split(',').map(param => {
112113
param = param.trim();
113114
const paraType = param.match(/^(\w+)/)[1];
114115
return structs.has(paraType) ? param.replace(paraType, `${name}.${paraType}`) : param;
115116
});
117+
}
116118

117119
libraries[name].push({
118120
name: funcName,
@@ -142,8 +144,10 @@ for (const [libName, funcs] of Object.entries(libraries)) {
142144
const funcCode = [];
143145
for (const func of funcs)
144146
funcCode.push([
145-
` function ${func.name}(${pConcat(func.paras)}) external ${func.stateMut}` +
146-
` ${func.rets ? `returns (${pConcat(func.rets)}) ` : ''} {`,
147+
` function ${func.name}(${pConcat(func.paras)}) external` +
148+
(func.stateMut ? ` ${func.stateMut}` : "") +
149+
(func.rets ? ` returns (${pConcat(func.rets)})` : "") +
150+
" {",
147151
` ${func.rets ? 'return ' : ''}${libName}.${func.name}(${pNames(func.paras).join(', ')});`,
148152
` }`
149153
].join('\n'));

0 commit comments

Comments
 (0)