diff --git a/docker/wasmd/Dockerfile b/docker/wasmd/Dockerfile index 190c62d..d26db20 100644 --- a/docker/wasmd/Dockerfile +++ b/docker/wasmd/Dockerfile @@ -3,7 +3,10 @@ ARG WASMD_VERSION=v0.44.0 FROM cosmwasm/wasmd:${WASMD_VERSION} # Increase the amount of ucosm given to accounts -RUN sed -i 's/1000000000/12000000000000/g' /opt/setup_wasmd.sh +RUN <<EOF +sed -i 's/keyring-backend = "os"/keyring-backend = "test"/g' /root/.wasmd/config/client.toml +sed -i 's/1000000000/12000000000000/g' /opt/setup_wasmd.sh +EOF # Set up wasmd. The account numbers correspond to those in the ./accounts/ # folder. @@ -13,6 +16,17 @@ RUN /opt/setup_wasmd.sh \ wasm1adcnk7lt6qst7p5d0g5607e28k77um7nxwxuqy \ wasm1jn34x50hy3my0a2mxwcx8fttgfxu2n5gpvu0ty +# Import the accounts' private keys into the image such that they can be used to +# initiate transactions from within the container. +COPY accounts /tmp/accounts +RUN <<EOF +tail -n 1 /tmp/accounts/admin.txt | wasmd keys add admin --recover --keyring-backend=test +tail -n 1 /tmp/accounts/alice.txt | wasmd keys add alice --recover --keyring-backend=test +tail -n 1 /tmp/accounts/bob.txt | wasmd keys add bob --recover --keyring-backend=test +tail -n 1 /tmp/accounts/charlie.txt | wasmd keys add charlie --recover --keyring-backend=test +rm -rf /tmp/accounts +EOF + # Configure the validator for single-node operation within a Docker container RUN <<EOF sed -i 's/keyring-backend = "os"/keyring-backend = "test"/g' /root/.wasmd/config/client.toml @@ -27,4 +41,4 @@ sed -i 's/max_body_bytes = 1000000$/max_body_bytes = 1000000000/g' /root/.wasmd/ sed -i 's/max_tx_bytes = 1048576$/max_tx_bytes = 104857600/g' /root/.wasmd/config/config.toml EOF -CMD ["/opt/run_wasmd.sh"] \ No newline at end of file +CMD ["/opt/run_wasmd.sh"] diff --git a/docker/wasmd/Makefile b/docker/wasmd/Makefile index d614c47..f27fe6e 100644 --- a/docker/wasmd/Makefile +++ b/docker/wasmd/Makefile @@ -35,4 +35,14 @@ delete-accounts: wasmd keys delete -y alice wasmd keys delete -y bob wasmd keys delete -y charlie -.PHONY: delete-accounts \ No newline at end of file +.PHONY: delete-accounts + +# Imports the accounts for admin, alice, bob and charlie from the text files in +# the ./accounts/ folder. We assume that the mnemonic for each account is the +# last line of each of the text files. +import-accounts: + tail -n 1 accounts/admin.txt | wasmd keys add admin --recover --keyring-backend=test + tail -n 1 accounts/alice.txt | wasmd keys add alice --recover --keyring-backend=test + tail -n 1 accounts/bob.txt | wasmd keys add bob --recover --keyring-backend=test + tail -n 1 accounts/charlie.txt | wasmd keys add charlie --recover --keyring-backend=test +.PHONY: import-accounts diff --git a/docker/wasmd/README.md b/docker/wasmd/README.md index 9569e0e..f3785bb 100644 --- a/docker/wasmd/README.md +++ b/docker/wasmd/README.md @@ -51,6 +51,43 @@ make This will, by default, build a Docker image tagged `informaldev/wasmd:v0.44.0`. +## Transacting on behalf of the accounts + +The accounts listed in the [`accounts`](./accounts/) folder are all already +imported into the `test` keyring within the Docker image. Once the container is +running, you can run the following to list them: + +```bash +# Assumes the container is called "wasmd" +docker exec -it wasmd \ + wasmd keys list --keyring-backend=test +``` + +## Importing the account keys + +As previously mentioned, the [`accounts`](./accounts/) folder contains all of +the necessary material to construct the public/private keypairs of the accounts. + +A convenient helper target is provided in [`Makefile`](./Makefile) to facilitate +importing of these accounts into a local `wasmd` configuration (i.e. on your +host machine, outside of the Docker container). This will allow you to transact +on behalf of any of those accounts from outside of the Docker container. + +**NB**: For this to work, you will need the same version of `wasmd` installed on +your local machine as what is built into the `wasmd` Docker image. + +```bash +make import-accounts +``` + +To check that the accounts have been imported correctly, on your host machine +run: + +```bash +# List all keys available in your local wasmd configuration +wasmd keys list --keyring-backend=test +``` + ## Querying accounts in the container To query, for example, the `admin` account's balance, where the `admin`