Skip to content

Commit

Permalink
Build contracts to /artifacts and use only that
Browse files Browse the repository at this point in the history
  • Loading branch information
deuszx committed Apr 23, 2024
1 parent f4fd9a3 commit 10125d5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 50 deletions.
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ build-amm: ## Builds AMM contracts.
@cd amm && make build-amm && cd ..

.PHONY: build-all
build-all: build-farm build-amm build-test-contracts ## Builds all contracts.

.PHONY: build-test-contracts
build-test-contracts: ## Builds contracts used in e2e-tests
@cd amm && make build-test-contracts && cd ..
build-all: build-farm build-amm ## Builds all contracts.

.PHONY: check-farm
check-farm: ## Runs cargo checks on farm contracts.
Expand All @@ -73,7 +69,7 @@ CONTRACT_DATA = ./target/ink
wrap-all: ## Generates code for contract interaction.
@for c in $(notdir $(shell find $(CONTRACT_DATA) -mindepth 1 -maxdepth 1 -type d)); do \
echo "Wrapping $$c" ; \
ink-wrapper -m ./target/ink/$$c/$$c.json --wasm-path ../../../target/ink/$$c/$$c.wasm \
ink-wrapper -m ./artifacts/$$c.json --wasm-path ../../../artifacts/$$c.wasm \
| rustfmt --edition 2021 > ./amm/e2e-tests/src/$$c.rs ; \
done

Expand All @@ -82,7 +78,7 @@ e2e-tests: ## Runs all the e2e tests in sequence.
@cd amm/e2e-tests && cargo test -- --test-threads 1 && cd ..

.PHONY: build-and-wrap-all
build-and-wrap-all: build-all build-test-contracts wrap-all ## Builds all contracts and generates code for contract interaction.
build-and-wrap-all: build-all wrap-all ## Builds all contracts and generates code for contract interaction.

INK_DEV_IMAGE = public.ecr.aws/p6e8q1z1/ink-dev:2.1.0

Expand Down
14 changes: 2 additions & 12 deletions amm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ help: # Show help for each of the Makefile recipes.
AMM_CONTRACTS = ./contracts
AMM_CONTRACTS_PATHS := $(shell find $(AMM_CONTRACTS) -mindepth 1 -maxdepth 1 -type d)

TEST_CONTRACTS = ../test-contracts
TEST_PATHS := $(shell find $(TEST_CONTRACTS) -mindepth 1 -maxdepth 1 -type d)

CONTRACTS := factory_contract pair_contract router_contract wrapped_azero

INK_DEV_IMAGE := "public.ecr.aws/p6e8q1z1/ink-dev:2.1.0"
Expand All @@ -31,15 +28,8 @@ check-amm: check-drink-tests ## Runs cargo (contract) check on AMM contracts.
cargo contract check --quiet --manifest-path $$d/Cargo.toml ; \
done

.PHONY: build-test-contracts
build-test-contracts: ## Builds contracts used in e2e-tests
@for d in $(TEST_PATHS); do \
echo "Building $$d contract" ; \
cd $$d && cargo contract build --quiet --release --features "contract" && cd $(SCRIPT_DIR) ; \
done

.PHONY: build-all
build-all: build-amm build-test-contracts ## Builds all contracts.
build-all: build-amm ## Builds all contracts.

.PHONY: wrap-all
wrap-all: ## Generates Rust wrappers for interacting with AMM contracts.
Expand All @@ -55,7 +45,7 @@ wrap-all-dockerized: ## Generates Rust wrappers for interacting with AMM contrac
make wrap-all

.PHONY: setup-tests
setup-tests: build-test-contracts build-amm wrap-all ## Builds contracts and generates wrappers.
setup-tests: build-amm wrap-all ## Builds contracts and generates wrappers.

.PHONY: drink-tests
drink-tests: ## Runs tests for drink contract.
Expand Down
42 changes: 17 additions & 25 deletions amm/scripts/prepare_rust_wrappers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,42 @@

readonly SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

mkdir -p $SCRIPT_DIR/../drink-tests/resources

declare -a CONTRACTS=(
declare -a AMM_CONTRACTS=(
"factory_contract"
"pair_contract"
"router_contract"
)

declare -a TEST_CONTRACTS=(
declare -a CONTRACTS=(
"factory_contract"
"pair_contract"
"router_contract"
"wrapped_azero"
"psp22"
)

function copy_wasms() {
for c in ${AMM_CONTRACTS[@]}; do
echo "Copying $c"
cp $SCRIPT_DIR/../../target/ink/$c/$c.wasm $SCRIPT_DIR/../../artifacts/$c.wasm;
cp $SCRIPT_DIR/../../target/ink/$c/$c.json $SCRIPT_DIR/../../artifacts/$c.json;
cp $SCRIPT_DIR/../../target/ink/$c/$c.contract $SCRIPT_DIR/../../artifacts/$c.contract;
done
}

function wrap_contracts() {
for c in ${CONTRACTS[@]}; do
echo "Wrapping $c"
ink-wrapper --metadata $SCRIPT_DIR/../../target/ink/$c/$c.json \
--wasm-path ../resources/$c.wasm \
ink-wrapper --metadata $SCRIPT_DIR/../../artifacts/$c.json \
--wasm-path $SCRIPT_DIR/../../artifacts/$c.wasm \
| rustfmt --edition 2021 > $SCRIPT_DIR/../drink-tests/src/$c.rs ;
done
echo "Wrapping wrapped_azero" &&
ink-wrapper --metadata $SCRIPT_DIR/../../test-contracts/wrapped-azero/target/ink/wrapped_azero.json \
--wasm-path ../resources/wrapped_azero.wasm \
| rustfmt --edition 2021 > $SCRIPT_DIR/../drink-tests/src/wrapped_azero.rs ;
echo "Wrapping psp22" &&
ink-wrapper --metadata $SCRIPT_DIR/../../test-contracts/psp22/target/ink/psp22.json \
--wasm-path ../resources/psp22.wasm \
| rustfmt --edition 2021 > $SCRIPT_DIR/../drink-tests/src/psp22.rs ;
}

function copy_wasms() {
for c in ${CONTRACTS[@]}; do
echo "Copying $c.wasm"
cp $SCRIPT_DIR/../../target/ink/$c/$c.wasm $SCRIPT_DIR/../drink-tests/resources/$c.wasm;
done
echo "Copying wrapped_zero.wasm" &&
cp $SCRIPT_DIR/../../test-contracts/wrapped-azero/target/ink/wrapped_azero.wasm $SCRIPT_DIR/../drink-tests/resources/wrapped_azero.wasm ;
echo "Copying psp22.wasm" &&
cp $SCRIPT_DIR/../../test-contracts/psp22/target/ink/psp22.wasm $SCRIPT_DIR/../drink-tests/resources/psp22.wasm ;
}

function run() {
wrap_contracts
copy_wasms
wrap_contracts
}

run
13 changes: 7 additions & 6 deletions farm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ help: # Show help for each of the Makefile recipes.
build-farm: ## Builds farm contracts.
@echo "Building farm contract" ; \
cargo contract build --quiet --manifest-path contract/Cargo.toml --release ; \
cp ../target/ink/farm_contract/farm_contract.wasm ../artifacts/farm_contract.wasm ; \
cp ../target/ink/farm_contract/farm_contract.json ../artifacts/farm_contract.json ; \
cp ../target/ink/farm_contract/farm_contract.contract ../artifacts/farm_contract.contract ;

.PHONY: check-farm
check-farm: ## Runs cargo checks on farm contracts.
Expand All @@ -19,17 +22,15 @@ check-farm: ## Runs cargo checks on farm contracts.
.PHONY: generate-farm-wrapper
generate-farm-wrapper: build-farm ## Generates Rust wrappers for interacting with farm contract.
@echo "Wrapping farm contract" ; \
ink-wrapper --metadata ../target/ink/farm_contract/farm_contract.json \
--wasm-path ../../../../target/ink/farm_contract/farm_contract.wasm \
ink-wrapper --metadata ../artifacts/farm_contract.json \
--wasm-path ../../../../artifacts/farm_contract.wasm \
| rustfmt --edition 2021 > ./tests/src/farm/farm_contract.rs ; \

.PHONY: generate-psp22-wrapper
generate-psp22-wrapper: ## Generates Rust wrappers for interacting with PSP22 contracts.
@echo "Building PSP22 contract" ; \
cargo contract build --quiet --manifest-path ../test-contracts/psp22/Cargo.toml --release --features "contract" ;
@echo "Wrapping PSP22 contract" ; \
ink-wrapper --metadata ../test-contracts/psp22/target/ink/psp22.json \
--wasm-path ../../../../test-contracts/psp22/target/ink/psp22.wasm \
ink-wrapper --metadata ../artifacts/psp22.json \
--wasm-path ../../../../artifacts/psp22.wasm \
| rustfmt --edition 2021 > ./tests/src/psp22/psp22_contract.rs ; \

.PHONY: generate-wrappers
Expand Down

0 comments on commit 10125d5

Please sign in to comment.