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

Fix ccq #57

Merged
merged 6 commits into from
Nov 14, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
- name: Run Forge build
run: |
forge --version
forge build --sizes
make
id: build

- name: Run Forge tests
run: |
forge test -vvv
make test
id: test
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#the chain that will be forked for testing
TEST_FORK = Mainnet Ethereum

.DEFAULT_GOAL = build
.PHONY: build test clean

build:
@$(MAKE) -C gen build
forge build

#include (and build if necessary) env/testing.env if we're running tests
ifneq (,$(filter test, $(MAKECMDGOALS)))
#hacky:
_ := $(shell $(MAKE) -C gen testing.env "TEST_FORK=$(strip $(TEST_FORK))")
include gen/testing.env
export
unexport TEST_FORK
endif
test: build
forge test

clean:
@$(MAKE) -C gen clean
forge clean
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ remappings = [
"IERC20/=src/interfaces/token/",
]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
verbosity = 3
3 changes: 2 additions & 1 deletion gen/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.package-lock.json
49 changes: 35 additions & 14 deletions gen/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
GENEREATORS = chains cctpDomains
chains_TARGET = ../src/constants/Chains.sol
cctpDomains_TARGET = ../src/constants/CCTPDomains.sol
GENERATORS = chains cctpDomains
chains_TARGET = constants/Chains.sol
cctpDomains_TARGET = constants/CCTPDomains.sol

TEST_WRAPPERS = BytesParsing
BytesParsing_BASE_PATH = libraries
fnGeneratorTarget = ../src/$($(1)_TARGET)
GENERATOR_TARGETS = $(foreach generator,$(GENERATORS),$(call fnGeneratorTarget,$(generator)))

TEST_WRAPPERS = BytesParsing QueryResponse

fnTestWrapperTarget = ../test/generated/$(1)TestWrapper.sol
TEST_WRAPPER_TARGETS =\
$(foreach wrapper, $(TEST_WRAPPERS), $(call fnTestWrapperTarget,$(wrapper)))
$(foreach wrapper,$(TEST_WRAPPERS),$(call fnTestWrapperTarget,$(wrapper)))

.DEFAULT_GOAL = build
.PHONY: build clean FORCE

.PHONY: generate $(GENEREATORS)
build: $(GENERATOR_TARGETS) $(TEST_WRAPPER_TARGETS)

build: $(GENEREATORS) $(TEST_WRAPPER_TARGETS)
clean:
rm -rf node_modules fork_changed testing.env

$(GENEREATORS): node_modules
npx ts-node [email protected] > $($@_TARGET)
FORCE:

node_modules: package-lock.json
npm ci
node_modules:
npm i

define ruleGenerator
$(call fnGeneratorTarget,$(1)): node_modules $(1).ts
npx ts-node $(1).ts > $$@
endef
$(foreach generator,$(GENERATORS),$(eval $(call ruleGenerator,$(generator))))

define ruleTestWrapper
$(call fnTestWrapperTarget,$(1)): ../src/$($(1)_BASE_PATH)/$(1).sol
npx ts-node libraryTestWrapper.ts $($(1)_BASE_PATH)/$(1) > $(call fnTestWrapperTarget,$(1))
$(call fnTestWrapperTarget,$(1)): ../src/libraries/$(1).sol libraryTestWrapper.ts
npx ts-node libraryTestWrapper.ts libraries/$(1) > $$@
endef
$(foreach wrapper,$(TEST_WRAPPERS),$(eval $(call ruleTestWrapper,$(wrapper))))

ifneq ($(TEST_FORK), $(shell cat fork_changed 2>/dev/null))
#if a different chain/network for testing was supplied last time then force an update
fork_changed: FORCE
endif

testing.env: node_modules fork_changed testingEnv.ts
@echo "Generating testing.env for $(TEST_FORK)"
npx ts-node testingEnv.ts $(TEST_FORK) > $@

fork_changed:
@echo $(TEST_FORK) > fork_changed
1 change: 1 addition & 0 deletions gen/fork_changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mainnet Ethereum
12 changes: 8 additions & 4 deletions gen/libraryTestWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ for (const libs of libMatches) {
const retParasRaw = modsRaw.match(retParasRegex);

const collapseSpaceRegex = /\s\s+/g;
const paramsToArray = (paramList: string) =>
paramList.replace(collapseSpaceRegex, ' ').trim().split(',').map(param => {
const paramsToArray = (paramList: string) => {
const cleaned = paramList.replace(collapseSpaceRegex, ' ').trim();
return !cleaned ? [] : cleaned.split(',').map(param => {
param = param.trim();
const paraType = param.match(/^(\w+)/)[1];
return structs.has(paraType) ? param.replace(paraType, `${name}.${paraType}`) : param;
});
}

libraries[name].push({
name: funcName,
Expand Down Expand Up @@ -142,8 +144,10 @@ for (const [libName, funcs] of Object.entries(libraries)) {
const funcCode = [];
for (const func of funcs)
funcCode.push([
` function ${func.name}(${pConcat(func.paras)}) external ${func.stateMut}` +
` ${func.rets ? `returns (${pConcat(func.rets)}) ` : ''} {`,
` function ${func.name}(${pConcat(func.paras)}) external` +
(func.stateMut ? ` ${func.stateMut}` : "") +
(func.rets ? ` returns (${pConcat(func.rets)})` : "") +
" {",
` ${func.rets ? 'return ' : ''}${libName}.${func.name}(${pNames(func.paras).join(', ')});`,
` }`
].join('\n'));
Expand Down
Loading
Loading