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

NTRN-195 feat: relayer keyring tests #31

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fb3db42
wip
oldremez Oct 29, 2022
834c68c
wip
oldremez Oct 29, 2022
1564af3
os, test, memory look working
oldremez Oct 30, 2022
67c471c
pass and file tests
oldremez Oct 31, 2022
95eaf0d
tests moved to jest
oldremez Nov 2, 2022
ac4db7f
oops forgot the test file
oldremez Nov 2, 2022
a61b802
refactoring
oldremez Nov 2, 2022
3e5b0d8
moved dockerfiles to setup dir
oldremez Nov 2, 2022
19834d3
optimization of dockerfile building
oldremez Nov 3, 2022
7391f06
Merge remote-tracking branch 'origin/main' into feat/relayer-keychain
oldremez Nov 3, 2022
8da74e6
Merge remote-tracking branch 'origin/main' into feat/relayer-keychain
oldremez Nov 7, 2022
0b6dfdd
Merge remote-tracking branch 'origin/main' into feat/relayer-keychain
oldremez Nov 8, 2022
ad2c909
removed some unnecessary code
oldremez Nov 15, 2022
1b0c9e8
Merge branch 'main' into feat/relayer-keychain
oldremez Nov 15, 2022
ba527a6
reorganized the test
oldremez Nov 16, 2022
9d8255c
Merge branch 'main' into feat/relayer-keychain
oldremez Nov 18, 2022
27d7aa7
Skip keyring tests if NO_DOCKER
oldremez Nov 18, 2022
53d8cb3
Merge branch 'main' into feat/relayer-keychain
oldremez Dec 1, 2022
fe8bc05
better error handling for queries
oldremez Dec 1, 2022
c21d0bd
small readme fix
oldremez Dec 1, 2022
183b774
relayer image building fix
oldremez Dec 1, 2022
0d15906
Merge branch 'main' into feat/relayer-keychain
oldremez Dec 6, 2022
96c1f2d
readme fix
oldremez Dec 7, 2022
e7b8ce6
refactoring wip
oldremez Dec 7, 2022
326ba8b
fixing tests wip
oldremez Dec 8, 2022
c36b252
tests work still need refactoring though
oldremez Dec 8, 2022
03def28
removed unnecessary rebuilding
oldremez Dec 8, 2022
c0c8051
error in queryContract fix
oldremez Dec 9, 2022
7ea6b8b
ICQ relayer image name fix
oldremez Dec 9, 2022
3d93260
post-review separate keyring config
oldremez Dec 9, 2022
cf205b6
Merge branch 'main' into feat/relayer-keychain
oldremez Dec 9, 2022
21ea2c0
removing 'base' image version dependency
oldremez Dec 9, 2022
bee0ef5
revert of unnecessary changes
oldremez Dec 9, 2022
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ We use the Gaia network as a host network, so you need to clone it next to the n

```shell
git clone [email protected]:cosmos/gaia.git
cd gaia
git checkout v7.0.3
```

Expand Down Expand Up @@ -45,6 +46,7 @@ yarn test:simple # basic tests
yarn test:interchaintx # interchain txs test
yarn test:interchain_tx_query # interchain tx query test
yarn test:interchain_kv_query # interchain kv query test
yarn test:relayer_keyring # relayer keyring test
```

NOTE: To speed up tests you can run the cosmopark by youself with `make start-cosmopark` in the setup dir. To run test with the already running cosmopark use `NO_DOCKER` env variable.
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = () => {
process.on('exit', () => {
if (oneStop) return;
oneStop = true;
console.log('Stopping cosmopark');
console.error('Stopping cosmopark');
ch.execSync(`cd setup && make stop-cosmopark`);
});
return config;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test:simple": "jest --runInBand -b src/testcases/simple",
"test:interchain_kv_query": "jest --runInBand -b src/testcases/interchain_kv_query",
"test:interchain_tx_query": "jest --runInBand -b src/testcases/interchain_tx_query",
"test:relayer_keyring": "jest --runInBand -b src/testcases/relayer_keyring",
"lint": "eslint ./src",
"fmt": "eslint ./src --fix"
},
Expand Down
1 change: 1 addition & 0 deletions setup/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RELAYER_IMAGE_NAME=neutron-org/neutron-query-relayer
13 changes: 10 additions & 3 deletions setup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ build-hermes:
@docker build -f dockerbuilds/Dockerfile.hermes -t hermes:1.0.0 .

build-relayer:
cd ../../neutron-query-relayer/ && make build-docker
cd ../../neutron-query-relayer/ && make build-docker RELAYER_IMAGE_NAME=neutron-org/neutron-query-relayer

build-all: build-gaia build-neutron build-hermes build-relayer
build-relayer-keyring-tests: build-neutron build-relayer
docker build ./relayer_keyrings/os_test -t neutron-org/neutron-query-relayer:os-test
docker build ./relayer_keyrings/test_test -t neutron-org/neutron-query-relayer:test-test
docker build ./relayer_keyrings/memory_test -t neutron-org/neutron-query-relayer:memory-test
docker build ./relayer_keyrings/pass_test -t neutron-org/neutron-query-relayer:pass-test
docker build ./relayer_keyrings/file_test -t neutron-org/neutron-query-relayer:file-test

start-cosmopark: build-neutron build-relayer
build-all: build-gaia build-neutron build-hermes build-relayer build-relayer-keyring-tests

start-cosmopark: build-neutron build-relayer-keyring-tests
@docker-compose up -d

start-cosmopark-no-rebuild:
Expand Down
6 changes: 3 additions & 3 deletions setup/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ services:
- "gaia-node"

relayer:
image: neutron-org/neutron-query-relayer
image: "${RELAYER_IMAGE_NAME}"
entrypoint: ./run.sh
volumes:
- data:/data
Expand All @@ -48,13 +48,13 @@ services:
- RELAYER_NEUTRON_CHAIN_RPC_ADDR=tcp://neutron-node:26657
- RELAYER_NEUTRON_CHAIN_REST_ADDR=http://neutron-node:1317
- RELAYER_NEUTRON_CHAIN_HOME_DIR=/data/test-1
- RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=demowallet3
- RELAYER_KEYRING_KEY_NAME=demowallet3
- RELAYER_NEUTRON_CHAIN_GAS_PRICES=0.5stake
- RELAYER_NEUTRON_CHAIN_GAS_ADJUSTMENT=1.4
- RELAYER_NEUTRON_CHAIN_CONNECTION_ID=connection-0
- RELAYER_NEUTRON_CHAIN_DEBUG=true
- RELAYER_NEUTRON_CHAIN_ACCOUNT_PREFIX=neutron
- RELAYER_NEUTRON_CHAIN_KEYRING_BACKEND=test
- RELAYER_KEYRING_BACKEND=test
- RELAYER_TARGET_CHAIN_RPC_ADDR=tcp://gaia-node:26657
- RELAYER_TARGET_CHAIN_ACCOUNT_PREFIX=cosmos
- RELAYER_TARGET_CHAIN_VALIDATOR_ACCOUNT_PREFIX=cosmosvaloper
Expand Down
10 changes: 10 additions & 0 deletions setup/relayer_keyrings/file_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM neutron-org/neutron-query-relayer

COPY --from=neutron-node /go/bin/neutrond /bin/

RUN mv run.sh run-old.sh

# preserve original run.sh
ADD --chmod=0755 run.sh .

ENTRYPOINT ["/bin/bash", "run.sh"]
19 changes: 19 additions & 0 deletions setup/relayer_keyrings/file_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

NEUTRON_BIN=/bin/neutrond
KEYRING_PASS=rootroot
SEED="record gift you once hip style during joke field prize dust unique length more pencil transfer quit train device arrive energy sort steak upset"
ACCOUNT_NAME=os_demowallet

echo "Inititalizing file keyring"

echo -e "$SEED\n$KEYRING_PASS\n$KEYRING_PASS\n" | $NEUTRON_BIN keys add $ACCOUNT_NAME --recover --keyring-backend=file

echo "file keyring initialized"

export RELAYER_KEYRING_KEY_NAME=$ACCOUNT_NAME
export RELAYER_KEYRING_BACKEND=file
export RELAYER_KEYRING_PASSWORD=$KEYRING_PASS
export RELAYER_NEUTRON_CHAIN_HOME_DIR=/root/.neutrond/

./run-old.sh
8 changes: 8 additions & 0 deletions setup/relayer_keyrings/memory_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM neutron-org/neutron-query-relayer

RUN mv run.sh run-old.sh

# preserve original run.sh
ADD --chmod=0755 run.sh .

ENTRYPOINT ["/bin/bash", "run.sh"]
6 changes: 6 additions & 0 deletions setup/relayer_keyrings/memory_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

export RELAYER_KEYRING_BACKEND=memory
export RELAYER_KEYRING_KEY_SEED="record gift you once hip style during joke field prize dust unique length more pencil transfer quit train device arrive energy sort steak upset"

./run-old.sh
10 changes: 10 additions & 0 deletions setup/relayer_keyrings/os_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM neutron-org/neutron-query-relayer

COPY --from=neutron-node /go/bin/neutrond /bin/

RUN mv run.sh run-old.sh

# preserve original run.sh
ADD --chmod=0755 run.sh .

ENTRYPOINT ["/bin/bash", "run.sh"]
19 changes: 19 additions & 0 deletions setup/relayer_keyrings/os_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

NEUTRON_BIN=/bin/neutrond
KEYRING_PASS=rootroot
SEED="record gift you once hip style during joke field prize dust unique length more pencil transfer quit train device arrive energy sort steak upset"
ACCOUNT_NAME=os_demowallet

echo "Inititalizing os keyring"

echo -e "$SEED\n$KEYRING_PASS\n$KEYRING_PASS\n" | $NEUTRON_BIN keys add $ACCOUNT_NAME --recover

echo "os keyring initialized"

export RELAYER_KEYRING_KEY_NAME=$ACCOUNT_NAME
export RELAYER_KEYRING_BACKEND=os
export RELAYER_KEYRING_PASSWORD=$KEYRING_PASS
export RELAYER_NEUTRON_CHAIN_HOME_DIR=/root/.neutrond/

./run-old.sh
13 changes: 13 additions & 0 deletions setup/relayer_keyrings/pass_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM neutron-org/neutron-query-relayer

RUN apt install pass -y

COPY --from=neutron-node /go/bin/neutrond /bin/

RUN mv run.sh run-old.sh

# preserve original run.sh
ADD --chmod=0755 run.sh .
ADD --chmod=0755 fake-pinentry.sh .

ENTRYPOINT ["/bin/bash", "run.sh"]
33 changes: 33 additions & 0 deletions setup/relayer_keyrings/pass_test/fake-pinentry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
# Use this for your test suites when a POSIX shell is available.
#
# The encrypted keys in your test suite that you expect to work must
# be locked with a passphrase of "passphrase"
#
# Author: Daniel Kahn Gillmor <[email protected]>
#
# License: Creative Commons Zero ("Public Domain Dedication") --
# Anyone may reuse it, modify it, redistribute it for any purpose.

echo "OK This is only for test suites, and should never be used in production"
while read cmd rest; do
cmd=$(printf "%s" "$cmd" | tr 'A-Z' 'a-z')
if [ -z "$cmd" ]; then
continue;
fi
case "$cmd" in
\#*)
;;
getpin)
echo "D rootroot"
echo "OK"
;;
bye)
echo "OK"
exit 0
;;
*)
echo "OK"
;;
esac
done
33 changes: 33 additions & 0 deletions setup/relayer_keyrings/pass_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

NEUTRON_BIN=/bin/neutrond
SEED="record gift you once hip style during joke field prize dust unique length more pencil transfer quit train device arrive energy sort steak upset"
ACCOUNT_NAME=test_demowallet

echo "Inititalizing pass keyring"

gpg --batch --gen-key <<EOF
Key-Type: 1
Key-Length: 2048
Subkey-Type: 1
Subkey-Length: 2048
Name-Real: test-user
Name-Email: [email protected]
Expire-Date: 0
Passphrase: rootroot
EOF

pass init test-user

echo "pinentry-program /fake-pinentry.sh" > ~/.gnupg/gpg-agent.conf
gpg-connect-agent reloadagent /bye

echo -e "$SEED\n" | $NEUTRON_BIN keys add $ACCOUNT_NAME --recover --keyring-backend=pass --keyring-dir=/root/.neutrond/

echo "pass keyring initialized"

export RELAYER_KEYRING_KEY_NAME=$ACCOUNT_NAME
export RELAYER_KEYRING_BACKEND=pass
export RELAYER_NEUTRON_CHAIN_HOME_DIR=/root/.neutrond/

./run-old.sh
10 changes: 10 additions & 0 deletions setup/relayer_keyrings/test_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM neutron-org/neutron-query-relayer

COPY --from=neutron-node /go/bin/neutrond /bin/

RUN mv run.sh run-old.sh

# preserve original run.sh
ADD --chmod=0755 run.sh .

ENTRYPOINT ["/bin/bash", "run.sh"]
19 changes: 19 additions & 0 deletions setup/relayer_keyrings/test_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

NEUTRON_BIN=/bin/neutrond
SEED="record gift you once hip style during joke field prize dust unique length more pencil transfer quit train device arrive energy sort steak upset"
ACCOUNT_NAME=test_demowallet

echo "Inititalizing test keyring"

echo -e "$SEED\n" | $NEUTRON_BIN keys add $ACCOUNT_NAME --recover --keyring-backend=test --keyring-dir=/root/.neutrond/

echo "test keyring initialized"

export RELAYER_KEYRING_KEY_NAME=$ACCOUNT_NAME
export RELAYER_KEYRING_BACKEND=test
export RELAYER_NEUTRON_CHAIN_HOME_DIR=/root/.neutrond/

./run-old.sh || true

sleep infinity
35 changes: 25 additions & 10 deletions src/helpers/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export class CosmosWrapper {
return data.data;
}
}

const rpcError = error?.response?.data?.message;
if (rpcError !== undefined) {
throw rpcError;
}
error = error ?? new Error('failed to submit tx');
throw error;
}
Expand Down Expand Up @@ -264,16 +269,26 @@ export class CosmosWrapper {
contract: string,
query: Record<string, unknown>,
): Promise<T> {
const url = `${this.sdk.url}/wasm/contract/${contract}/smart/${Buffer.from(
JSON.stringify(query),
).toString('base64')}?encoding=base64`;
const req = await axios.get<{
result: { smart: string };
height: number;
}>(url);
return JSON.parse(
Buffer.from(req.data.result.smart, 'base64').toString(),
) as T;
try {
const url = `${
this.sdk.url
}/wasm/contract/${contract}/smart/${Buffer.from(
JSON.stringify(query),
).toString('base64')}?encoding=base64`;
const req = await axios.get<{
result: { smart: string };
height: number;
}>(url);
return JSON.parse(
Buffer.from(req.data.result.smart, 'base64').toString(),
) as T;
} catch (e) {
const rpcError = e?.response?.data?.error;
if (rpcError !== undefined) {
throw new Error(rpcError);
}
throw e;
}
}

/**
Expand Down
14 changes: 5 additions & 9 deletions src/helpers/env.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import axios from 'axios';
import { execSync } from 'child_process';
import { execSync, ExecSyncOptions } from 'child_process';
import { wait } from './wait';
import { getContractsHashes } from './cosmos';

const BLOCKS_COUNT_BEFORE_START = process.env.BLOCKS_COUNT_BEFORE_START
? parseInt(process.env.BLOCKS_COUNT_BEFORE_START, 10)
: 10;

let alreadySetUp = false;

export const setup = async (host: string) => {
if (alreadySetUp) {
console.log('already set up');
return;
}
if (process.env.NO_DOCKER) {
console.log('NO_DOCKER ENV provided');
return;
Expand All @@ -23,13 +17,15 @@ export const setup = async (host: string) => {
// eslint-disable-next-line no-empty
} catch (e) {}
console.log('Starting container... it may take long');
execSync(`cd setup && make start-cosmopark`);
const execOptions: ExecSyncOptions = {
env: process.env,
};
execSync(`cd setup && make start-cosmopark-no-rebuild`, execOptions);
showVersions();
await showContractsHashes();

await waitForHTTP(host);
await waitForChannel(host);
alreadySetUp = true;
};

export const waitForHTTP = async (
Expand Down
Loading