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

Fixing para-test CI #1479

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
93 changes: 82 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@ jobs:
./scripts/build-alphanet-relay-image.sh
docker push $DOCKER_TAG
fi
- name: Check & prepare para-test docker image
run: |
POLKADOT_REPO=${{ needs.set-tags.outputs.polkadot_repo }}
POLKADOT_COMMIT=${{ needs.set-tags.outputs.polkadot_commit }}
DOCKER_TAG="purestake/polkadot-para-tests:sha-$POLKADOT_COMMIT"
POLKADOT_EXISTS=$(docker manifest inspect $DOCKER_TAG > /dev/null && \
echo "true" || echo "false")
if [[ "$POLKADOT_EXISTS" == "false" ]]; then
mkdir -p build
MOONBEAM_DOCKER_TAG="purestake/moonbase-relay-testnet:sha-$POLKADOT_COMMIT"
docker create --pull always -ti --name dummy $MOONBEAM_DOCKER_TAG bash
docker cp dummy:/usr/local/bin/polkadot build/polkadot
docker rm -f dummy
docker build . --pull --no-cache -f docker/polkadot-para-tests.Dockerfile \
--network=host \
--build-arg HOST_UID="$UID" \
-t $DOCKER_TAG
docker push $DOCKER_TAG
fi

####### Building and Testing binaries #######

Expand All @@ -219,8 +238,6 @@ jobs:
RUSTFLAGS: "-C opt-level=3 -D warnings"
# MOONBEAM_LOG: info
# DEBUG: "test*"
outputs:
RUSTC: ${{ steps.get-rust-versions.outputs.rustc }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -251,9 +268,6 @@ jobs:
fi
$SCCACHE_BIN -s
echo "RUSTC_WRAPPER=$SCCACHE_BIN" >> $GITHUB_ENV
- id: get-rust-versions
run: |
echo "::set-output name=rustc::$(rustc --version)"
- name: Build Node
run: |
env
Expand Down Expand Up @@ -312,7 +326,7 @@ jobs:

typescript-tests:
runs-on: self-hosted
needs: ["set-tags", "build"]
needs: ["set-tags", "build", "prepare-polkadot"]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -327,16 +341,33 @@ jobs:
with:
node-version: 14.x
- name: Typescript integration tests (against dev service)
env:
BINARY_PATH: ../build/moonbeam
run: |
chmod uog+x build/moonbeam

#### Preparing the repository
cd moonbeam-types-bundle
npm install
npm run build
cd ../tests
npm install
node_modules/.bin/mocha --parallel -j 4 -r ts-node/register 'tests/**/test-*.ts'
cd ..

#### Retrieving docker image as base to run tests
POLKADOT_REPO=${{ needs.set-tags.outputs.polkadot_repo }}
POLKADOT_COMMIT=${{ needs.set-tags.outputs.polkadot_commit }}
DOCKER_TAG="purestake/polkadot-para-tests:sha-$POLKADOT_COMMIT"

docker run \
-e BINARY_PATH='../build/moonbeam' \
-v $(pwd):/moonbeam:z \
-u $UID \
-w /moonbeam/tests \
$DOCKER_TAG \
node node_modules/.bin/mocha \
--parallel -j 4 \
--exit \
-r ts-node/register \
'tests/**/test-*.ts'

# We determine whether there are unmodified package-lock.json files by:
# 1. Asking git for a list of all modified files
Expand Down Expand Up @@ -398,7 +429,7 @@ jobs:
npm run build
cd ../tests
npm install
node_modules/.bin/mocha --parallel -j 2 -r ts-node/register 'tracing-tests/**/test-*.ts'
node_modules/.bin/mocha --exit --parallel -j 2 -r ts-node/register 'tracing-tests/**/test-*.ts'

typescript-para-tests:
runs-on: self-hosted
Expand Down Expand Up @@ -437,11 +468,51 @@ jobs:
run: |
chmod uog+x build/polkadot
chmod uog+x build/moonbeam

#### Preparing the repository
cd moonbeam-types-bundle
npm install
cd ../tests
npm install
node_modules/.bin/mocha -r ts-node/register 'para-tests/**/test-*.ts'
cd ..

POLKADOT_REPO=${{ needs.set-tags.outputs.polkadot_repo }}
POLKADOT_COMMIT=${{ needs.set-tags.outputs.polkadot_commit }}
DOCKER_TAG="purestake/polkadot-para-tests:sha-$POLKADOT_COMMIT"

#### Retrieve binary to avoid para-node script to rely on docker
mkdir -p build
localVersion=$(grep 'spec_version: [0-9]*' runtime/moonbase/src/lib.rs | grep -o '[0-9]*')
baseRuntime=$(git tag -l -n 'runtime-[0-9]*' | \
cut -d' ' -f 1 | cut -d'-' -f 2 | \
sed "1 i ${localVersion}" | \
sort -n -r | \
uniq | \
grep -A1 "${localVersion}" | \
tail -1)
rev=$(git rev-list -1 runtime-$baseRuntime)
sha8=${rev:0:8}
dockerImage=purestake/moonbeam:sha-${sha8}
binaryPath=build/moonbeam-${sha8}
docker create --pull always --name moonbeam-tmp ${dockerImage} && \
docker cp moonbeam-tmp:/moonbeam/moonbeam ${binaryPath} && \
docker rm moonbeam-tmp

echo "Running para-tests inside docker: $DOCKER_TAG"
docker run \
-e OVERRIDE_RUNTIME_PATH='./runtimes' \
-e BINARY_PATH='../build/moonbeam' \
-e MOONBEAM_LOG='info' \
-e RELAY_BINARY_PATH='/binaries/polkadot' \
-e RUNTIME_DIRECTORY='/tmp/runtimes' \
-e BINARY_DIRECTORY='../build/' \
-e SPECS_DIRECTORY='/tmp/specs' \
-v $(pwd):/moonbeam:z \
-v $(pwd)/${binaryPath}:/binaries/moonbeam:z \
-u $UID \
-w /moonbeam/tests \
$DOCKER_TAG \
node node_modules/.bin/mocha --exit -r ts-node/register 'para-tests/**/test-*.ts'

docker-parachain:
runs-on: ubuntu-latest
Expand Down
26 changes: 26 additions & 0 deletions docker/polkadot-para-tests.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Node for Moonbase Parachains.
#
# Requires to run from repository root and to copy the binary in the build folder (part of the release workflow)

FROM node
LABEL maintainer "[email protected]"
LABEL description="Node image use to run Moonbeam para-tests"

ARG HOST_UID=1001

RUN ((getent passwd $HOST_UID > /dev/null) || \
useradd -m -u $HOST_UID -U -s /bin/sh -d /polkadot polkadot) && \
mkdir -p /polkadot/.local/share/polkadot && \
chown -R $HOST_UID /polkadot && \
ln -s /polkadot/.local/share/polkadot /data

RUN mkdir -p /binaries
COPY build/polkadot /binaries/
RUN chmod -R uog+rwX /binaries

USER $HOST_UID

WORKDIR /polkadot

ENTRYPOINT ["docker-entrypoint.sh"]
CMD [ "node" ]
2 changes: 1 addition & 1 deletion scripts/build-alphanet-relay-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi

echo "Using Polkadot from $POLKADOT_REPO revision #${POLKADOT_COMMIT}"

docker build . -f docker/polkadot-relay.Dockerfile --network=host \
docker build . --pull --no-cache -f docker/polkadot-relay.Dockerfile --network=host \
--build-arg POLKADOT_COMMIT="$POLKADOT_COMMIT" \
--build-arg POLKADOT_REPO="$POLKADOT_REPO" \
-t purestake/moonbase-relay-testnet:sha-$POLKADOT_COMMIT
18 changes: 12 additions & 6 deletions tests/util/para-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export interface NodePorts {
wsPort: number;
}

const RUNTIME_DIRECTORY = "runtimes";
const BINARY_DIRECTORY = "binaries";
const SPECS_DIRECTORY = "specs";
const RUNTIME_DIRECTORY = process.env.RUNTIME_DIRECTORY || "runtimes";
const BINARY_DIRECTORY = process.env.BINARY_DIRECTORY || "binaries";
const SPECS_DIRECTORY = process.env.SPECS_DIRECTORY || "specs";

// Downloads the runtime and return the filepath
export async function getRuntimeWasm(
Expand All @@ -105,6 +105,10 @@ export async function getRuntimeWasm(
): Promise<string> {
const runtimePath = path.join(RUNTIME_DIRECTORY, `${runtimeName}-${runtimeTag}.wasm`);

if (!fs.existsSync(RUNTIME_DIRECTORY)) {
fs.mkdirSync(RUNTIME_DIRECTORY, { recursive: true });
}

if (runtimeTag == "local") {
const builtRuntimePath = path.join(
OVERRIDE_RUNTIME_PATH || `../target/release/wbuild/${runtimeName}-runtime/`,
Expand Down Expand Up @@ -176,7 +180,7 @@ export async function getMoonbeamDockerBinary(binaryTag: string): Promise<string

console.log(` Missing ${binaryPath} locally, downloading it...`);
child_process.execSync(`mkdir -p ${path.dirname(binaryPath)} && \
docker create --name moonbeam-tmp ${dockerImage} && \
docker create --pull always --name moonbeam-tmp ${dockerImage} && \
docker cp moonbeam-tmp:/moonbeam/moonbeam ${binaryPath} && \
docker rm moonbeam-tmp`);
console.log(`${binaryPath} downloaded !`);
Expand All @@ -194,7 +198,8 @@ export async function getRawSpecsFromTag(

child_process.execSync(
`mkdir -p ${path.dirname(specPath)} && ` +
`${binaryPath} build-spec --chain moonbase-local --raw > ${specPath}`
`${binaryPath} build-spec --chain moonbase-local ` +
`--raw --disable-default-bootnode > ${specPath}`
);
}
return specPath;
Expand All @@ -208,7 +213,8 @@ export async function generateRawSpecs(
if (!fs.existsSync(specPath)) {
child_process.execSync(
`mkdir -p ${path.dirname(specPath)} && ` +
`${binaryPath} build-spec --chain moonbase-local --raw > ${specPath}`
`${binaryPath} build-spec --chain moonbase-local ` +
`--raw --disable-default-bootnode > ${specPath}`
);
}
return specPath;
Expand Down
9 changes: 6 additions & 3 deletions tests/util/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ export async function customWeb3Request(web3: Web3, method: string, params: any[
(error: Error | null, result?: JsonRpcResponse) => {
if (error) {
reject(
`Failed to send custom request (${method} (${params.join(",")})): ${
error.message || error.toString()
}`
`Failed to send custom request (${method} (${params
.map((p) => {
const str = p.toString();
return str.length > 128 ? `${str.slice(0, 96)}...${str.slice(-28)}` : str;
})
.join(",")})): ${error.message || error.toString()}`
);
}
resolve(result);
Expand Down