From 8e2b024c936c84cc781904a6282d967fef92d9cc Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 1 Jun 2022 13:40:48 -0700 Subject: [PATCH] fix: localosmosis to work for testing cosmwasm contracts (#1640) (#1641) * first working version * better makefile commands and docs * fix osmosisd start script to expose rpc port * changelog (cherry picked from commit d5cd03329b7edc028f2793f95d4c4e85e62060fb) Co-authored-by: Roman --- .gitignore | 1 + CHANGELOG.md | 2 ++ Makefile | 6 +++++- tests/localosmosis/Dockerfile | 30 +++++++++------------------ tests/localosmosis/README.md | 5 +++++ tests/localosmosis/docker-compose.yml | 7 ++++--- tests/localosmosis/setup.sh | 7 ++++++- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 3cc5164ae35..1e05d8c9fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -201,3 +201,4 @@ $RECYCLE.BIN/ /scripts/local/ /x/incentives/keeper/osmosis_testing/ tools-stamp +/tests/localosmosis/.osmosisd/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c8ec77ce5..6bb091573a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,8 @@ Upgrade from wasmd v0.23.x to [v0.27.0](https://github.com/CosmWasm/wasmd/releas The TokenFactory module is added to the chain, making it possible for users and contracts to make new native tokens. Cosmwasm bindings have been added, to make swapping and creating these new tokens easier within the contract ecosystem. +* [#1640](https://github.com/osmosis-labs/osmosis/pull/1640) fix: localosmosis to work for testing cosmwasm contracts + ### Other Features * [#1629](https://github.com/osmosis-labs/osmosis/pull/1629) Fix bug in the airdrop claim script diff --git a/Makefile b/Makefile index edbd3cc43c5..dbee202c2c9 100644 --- a/Makefile +++ b/Makefile @@ -276,9 +276,13 @@ localnet-build: localnet-start: @docker-compose -f tests/localosmosis/docker-compose.yml up -localnet-remove: +localnet-stop: @docker-compose -f tests/localosmosis/docker-compose.yml down +localnet-remove: localnet-stop + PWD=$(shell pwd) + @docker run --user root -v ${PWD}/tests/localosmosis/.osmosisd:/root/osmosis ubuntu /bin/sh -c "rm -rf /root/osmosis/*" + .PHONY: all build-linux install format lint \ go-mod-cache draw-deps clean build build-contract-tests-hooks \ test test-all test-build test-cover test-unit test-race benchmark diff --git a/tests/localosmosis/Dockerfile b/tests/localosmosis/Dockerfile index 3a4645f5d27..d4246ea11d0 100644 --- a/tests/localosmosis/Dockerfile +++ b/tests/localosmosis/Dockerfile @@ -1,9 +1,6 @@ # syntax=docker/dockerfile:1 -# -------------------------------------------------------- -# Build -# -------------------------------------------------------- - +# Build stage FROM golang:1.18.2-alpine3.15 as build RUN set -eux; apk add --no-cache ca-certificates build-base; @@ -14,7 +11,6 @@ RUN apk add linux-headers WORKDIR /osmosis COPY . /osmosis - # CosmWasm: see https://github.com/CosmWasm/wasmvm/releases ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a @@ -26,26 +22,20 @@ RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build -# -------------------------------------------------------- -# Runner -# -------------------------------------------------------- - +# Run stage FROM ubuntu -COPY --from=build /osmosis/build/osmosisd /bin/osmosisd -COPY /tests/localosmosis/setup.sh /setup.sh - ENV HOME /osmosis WORKDIR $HOME -RUN apk update -RUN apk add jq -RUN apk add moreutils -RUN rm -rf /var/cache/apk/* -RUN chmod +x /setup.sh -RUN /setup.sh + +COPY --from=build ${HOME}/build/osmosisd /bin/osmosisd +COPY tests/localosmosis/setup.sh ${HOME}/setup.sh + +RUN apt-get update -y && apt-get install -y jq moreutils +RUN chmod +x ${HOME}/setup.sh + EXPOSE 26656 EXPOSE 26657 EXPOSE 1317 -ENTRYPOINT ["osmosisd"] -CMD ["start"] +ENTRYPOINT ${HOME}/setup.sh diff --git a/tests/localosmosis/README.md b/tests/localosmosis/README.md index 4c99ab03184..1c25f2cb317 100644 --- a/tests/localosmosis/README.md +++ b/tests/localosmosis/README.md @@ -9,6 +9,9 @@ You can now quickly test your changes to Osmosis with just a few commands: 3. Once complete, run `make localnet-start` - You will now be running a local network with your changes! + - The files in `tests/e2e/localosmosis/.osmosisd` that are produced + by this command can only be removed by running `make localnet-remove` + - That will reset the chain to genesis 4. To add your validator wallet and 9 other preloaded wallets automatically, run `make localnet-keys` - These keys are added to your --keyring-backend test @@ -18,6 +21,8 @@ You can now quickly test your changes to Osmosis with just a few commands: 5. To remove all block history and start from scratch, run `make localnet-remove` +6. To stop the chain but keep the state, run `make localnet-stop` + ## Accounts LocalOsmosis is pre-configured with one validator and 9 accounts with ION and OSMO balances. diff --git a/tests/localosmosis/docker-compose.yml b/tests/localosmosis/docker-compose.yml index a52d6c5a56b..46f2b278b66 100644 --- a/tests/localosmosis/docker-compose.yml +++ b/tests/localosmosis/docker-compose.yml @@ -4,9 +4,10 @@ services: osmosisd: image: local:osmosis user: "root:root" - command: - - start - - --rpc.laddr=tcp://0.0.0.0:26657 + volumes: + - ./.osmosisd/config:/osmosis/.osmosisd/config + - ./.osmosisd/data:/osmosis/.osmosisd/data + - ./.osmosisd/wasm:/osmosis/.osmosisd/wasm ports: - "26657:26657" - "1317:1317" diff --git a/tests/localosmosis/setup.sh b/tests/localosmosis/setup.sh index cc2cf878026..7fdd11780b0 100755 --- a/tests/localosmosis/setup.sh +++ b/tests/localosmosis/setup.sh @@ -42,5 +42,10 @@ cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["mint cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json # update gamm genesis cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gamm"]["params"]["pool_creation_fee"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# remove seeds +# update txfee basedenom +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["txfees"]["basedenom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +remove seeds + sed -i.bak -E 's#^(seeds[[:space:]]+=[[:space:]]+).*$#\1""#' ~/.osmosisd/config/config.toml + +osmosisd start --rpc.laddr=tcp://0.0.0.0:26657