Skip to content

Commit

Permalink
CI Reliability Improvements (#2519)
Browse files Browse the repository at this point in the history
* turn on multithreading

* fix

* removing test file

* re-enabled multi threads

* Using atomics

* moonscope timeout

* added chopsticks retries

* removed script

* fix retries

* fix CI

* fix chopsticks CI

* chopsticks fix

* Given retries to tracing tests

* changed thread config

* testing single-threads

* restored multithreads

* pkg update

* pkg update

* update pkgs

* lint

* restore wormhole test

* fixing type errors

* lint

* Changed prettier format task

* skip actions requiring secrets if comning from forks

PRs filed from forks do not have access to secrets

* added linting to helper files

* fix ci

* enable lint for test files

* Tidied import statements on test specs

---------

Co-authored-by: Andrea Giacobino <[email protected]>
  • Loading branch information
timbrinded and noandrea authored Oct 19, 2023
1 parent aefcc5b commit 1b193f5
Show file tree
Hide file tree
Showing 346 changed files with 2,187 additions and 2,189 deletions.
73 changes: 55 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ jobs:
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
check-eslint:
name: "Check with EsLint"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 8.6.12
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "pnpm"
cache-dependency-path: test/pnpm-lock.yaml
- name: Run Eslint check
run: |
cd test
pnpm i
pnpm lint
check-cargo-toml-format:
name: "Check Cargo.toml files format"
runs-on:
Expand Down Expand Up @@ -377,7 +402,7 @@ jobs:
uses: pnpm/action-setup@v2
with:
version: 8.6.12
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
Expand All @@ -395,10 +420,7 @@ jobs:
./scripts/build-last-tracing-runtime.sh ${{ needs.set-tags.outputs.git_branch }}
mkdir -p test/moonbase-overrides/
mv build/wasm/moonbase-runtime-local-substitute-tracing.wasm test/moonbase-overrides/
- name: Typescript tracing tests (against dev service)
env:
DEBUG_COLOURS: "1"
NODE_OPTIONS: "--max-old-space-size=12288"
- name: Preparing the repository
run: |
chmod uog+x build/moonbeam
chmod uog+x target/release/moonbeam
Expand All @@ -411,12 +433,19 @@ jobs:
#### Preparing the typescript api
cd ../typescript-api
npm ci
#### Install and run dev tracing
cd ../test
pnpm install
pnpm compile-solidity
pnpm moonwall test dev_moonbase_tracing
- name: Running Tracing Tests (with retry)
env:
DEBUG_COLOURS: "1"
NODE_OPTIONS: "--max-old-space-size=12288"
uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 5
command: |
cd test
pnpm install
pnpm compile-solidity
pnpm moonwall test dev_moonbase_tracing
docker-moonbeam:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -488,6 +517,7 @@ jobs:
labels: bare-metal
needs: ["set-tags", "build"]
strategy:
fail-fast: false
matrix:
chain: ["moonbase", "moonriver", "moonbeam"]
env:
Expand Down Expand Up @@ -519,13 +549,22 @@ jobs:
run: |
cd test
pnpm install
pnpm moonwall test upgrade_${{matrix.chain}}
- name: Run Upgrade Test (with retry)
uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 2
retry_on: error
command: |
cd test
pnpm moonwall test upgrade_${{matrix.chain}}
zombie_upgrade_test:
runs-on:
labels: bare-metal
needs: ["set-tags", "build"]
strategy:
fail-fast: false
matrix:
## TODO: add moonriver here when it is ready
chain: ["moonbase", "moonbeam"]
Expand Down Expand Up @@ -616,17 +655,14 @@ jobs:
with:
name: moonbeam
path: target/release
- name: Enforce multi thread limit
run: |
sed -i 's/"multiThreads": true/"multiThreads": 3/g' test/moonwall.config.json
- name: "Run Moonwall Dev Tests"
uses: ./.github/workflow-templates/dev-tests
with:
moonwall_environment: dev_${{ matrix.chain }}
- name: Upload HTML report to s3
if: |
github.event.pull_request.head.repo.full_name == github.repository
|| github.event_name == 'push'
&& github.event_name == 'push'
uses: mario-sangar/upload-s3-action@master
id: S3
with:
Expand All @@ -637,7 +673,7 @@ jobs:
source_dir: "test/html"
acl: "none"
- name: Upload to Moonscope
if: always()
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
curl --location 'https://api.moonscope.kaki.dev/insert' \
-X POST \
Expand All @@ -646,4 +682,5 @@ jobs:
--header 'table: dev_reports' \
--header 'branch: ${{ needs.set-tags.outputs.git_branch }}' \
--header 'Content-Type: application/json' \
-d@test/tmp/testResults.json
--max-time 30 \
-d@test/tmp/testResults.json || echo "Curl command failed but continuing"
30 changes: 30 additions & 0 deletions test/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
env: {
es2021: true,
node: true,
},
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
overrides: [
{
env: {
node: true,
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script",
},
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["@typescript-eslint", "unused-imports"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"no-async-promise-executor": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "error",
},
};
58 changes: 23 additions & 35 deletions test/helpers/block.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import "@moonbeam-network/api-augment/moonbase";
import type { RuntimeDispatchInfoV1 } from "@polkadot/types/interfaces/payment";
import { ApiPromise } from "@polkadot/api";
import { BlockHash, DispatchInfo, RuntimeDispatchInfo } from "@polkadot/types/interfaces";
import { u32, u128, Option } from "@polkadot/types";
import { DevModeContext, expect } from "@moonwall/cli";
import {
WEIGHT_PER_GAS,
mapExtrinsics,
BlockRangeOption,
calculateFeePortions,
EXTRINSIC_BASE_WEIGHT,
WEIGHT_PER_GAS,
calculateFeePortions,
mapExtrinsics,
} from "@moonwall/util";
import { DevModeContext } from "@moonwall/cli";
import { expect } from "@moonwall/cli";
import type { Block, AccountId20 } from "@polkadot/types/interfaces/runtime/types";
import { ApiPromise } from "@polkadot/api";
import type { TxWithEvent } from "@polkadot/api-derive/types";
import { Option, u128, u32 } from "@polkadot/types";
import type { ITuple } from "@polkadot/types-codec/types";
import { Debugger } from "debug";
import { BlockHash, DispatchInfo, RuntimeDispatchInfo } from "@polkadot/types/interfaces";
import type { RuntimeDispatchInfoV1 } from "@polkadot/types/interfaces/payment";
import type { AccountId20, Block } from "@polkadot/types/interfaces/runtime/types";
import chalk from "chalk";

const debug = require("debug")("test:blocks");
import { Debugger } from "debug";
import Debug from "debug";
const debug = Debug("test:blocks");

// Given a deposit amount, returns the amount burned (80%) and deposited to treasury (20%).
// This is meant to precisely mimic the logic in the Moonbeam runtimes where the burn amount
Expand Down Expand Up @@ -91,7 +90,7 @@ export const verifyBlockFees = async (
) => {
const api = context.polkadotJs();
debug(`========= Checking block ${fromBlockNumber}...${toBlockNumber}`);
let sumBlockFees = 0n;
// let sumBlockFees = 0n;
let sumBlockBurnt = 0n;

// Get from block hash and totalSupply
Expand All @@ -109,12 +108,12 @@ export const verifyBlockFees = async (
api,
{ from: fromBlockNumber, to: toBlockNumber, concurrency: 5 },
async (blockDetails) => {
let blockFees = 0n;
// let blockFees = 0n;
let blockBurnt = 0n;

// iterate over every extrinsic
for (const txWithEvents of blockDetails.txWithEvents) {
let { events, extrinsic, fee } = txWithEvents;
const { events, extrinsic, fee } = txWithEvents;

// This hash will only exist if the transaction was executed through ethereum.
let ethereumAddress = "";
Expand All @@ -129,7 +128,7 @@ export const verifyBlockFees = async (
}

// Payment event is submitted for substrate transactions
let paymentEvent = events.find(
const paymentEvent = events.find(
(event) => event.section == "transactionPayment" && event.method == "TransactionFeePaid"
);

Expand All @@ -156,9 +155,9 @@ export const verifyBlockFees = async (
if (extrinsic.method.section == "ethereum") {
// For Ethereum tx we caluculate fee by first converting weight to gas
const gasUsed = (dispatchInfo as any).weight.refTime.toBigInt() / WEIGHT_PER_GAS;
let ethTxWrapper = extrinsic.method.args[0] as any;
const ethTxWrapper = extrinsic.method.args[0] as any;

let number = blockDetails.block.header.number.toNumber();
const number = blockDetails.block.header.number.toNumber();
// The on-chain base fee used by the transaction. Aka the parent block's base fee.
//
// Note on 1559 fees: no matter what the user was willing to pay (maxFeePerGas),
Expand Down Expand Up @@ -237,7 +236,7 @@ export const verifyBlockFees = async (
})) as any
).toBigInt();

const tip = extrinsic.tip.toBigInt();
// const tip = extrinsic.tip.toBigInt();
const expectedPartialFee = lengthFee + weightFee + baseFee;

// Verify the computed fees are equal to the actual fees
Expand All @@ -247,7 +246,7 @@ export const verifyBlockFees = async (
expect(expectedPartialFee).to.eq(fee.partialFee.toBigInt());
}

blockFees += txFees;
// blockFees += txFees;
blockBurnt += txBurnt;

const origin = extrinsic.signer.isEmpty
Expand Down Expand Up @@ -299,7 +298,7 @@ export const verifyBlockFees = async (
` all deposits : ${allDeposits.toString().padStart(30, " ")}`
).to.eq(allDeposits);
}
sumBlockFees += blockFees;
// sumBlockFees += blockFees;
sumBlockBurnt += blockBurnt;
previousBlockHash = blockDetails.block.hash.toString();
}
Expand Down Expand Up @@ -328,7 +327,7 @@ export const verifyLatestBlockFees = async (

export async function jumpToRound(context: DevModeContext, round: number): Promise<string | null> {
let lastBlockHash = "";
while (true) {
for (;;) {
const currentRound = (
await context.polkadotJs().query.parachainStaking.round()
).current.toNumber();
Expand All @@ -349,25 +348,14 @@ export async function jumpBlocks(context: DevModeContext, blockCount: number) {
}
}

export async function jumpRounds(context: DevModeContext, count: Number): Promise<string | null> {
export async function jumpRounds(context: DevModeContext, count: number): Promise<string | null> {
const round = (await context.polkadotJs().query.parachainStaking.round()).current
.addn(count.valueOf())
.toNumber();

return jumpToRound(context, round);
}

// Determine if the block range intersects with an upgrade event
export const checkTimeSliceForUpgrades = async (
api: ApiPromise,
blockNumbers: number[],
currentVersion: u32
) => {
const apiAt = await api.at(await api.rpc.chain.getBlockHash(blockNumbers[0]));
const onChainRt = (await apiAt.query.system.lastRuntimeUpgrade()).unwrap().specVersion;
return { result: !onChainRt.eq(currentVersion), specVersion: onChainRt };
};

export function extractPreimageDeposit(
request:
| Option<ITuple<[AccountId20, u128]>>
Expand Down
1 change: 0 additions & 1 deletion test/helpers/eth-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
EvmCoreErrorExitRevert,
EvmCoreErrorExitSucceed,
} from "@polkadot/types/lookup";
import { Signer } from "ethers";
export type Errors = {
Succeed: EvmCoreErrorExitSucceed["type"];
Error: EvmCoreErrorExitError["type"];
Expand Down
Loading

0 comments on commit 1b193f5

Please sign in to comment.