Skip to content

Commit

Permalink
rebase, rebuild tests on WormholeOverride, add missing NoQuorum test
Browse files Browse the repository at this point in the history
  • Loading branch information
nonergodic committed Oct 30, 2024
1 parent 0750963 commit d8adcea
Show file tree
Hide file tree
Showing 21 changed files with 895 additions and 796 deletions.
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
45 changes: 33 additions & 12 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 $@.ts > $($@_TARGET)
FORCE:

node_modules: package-lock.json
npm ci

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
132 changes: 69 additions & 63 deletions gen/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d8adcea

Please sign in to comment.