Skip to content

Commit

Permalink
馃И dev-test migration to Moonwall #2 (#2375)
Browse files Browse the repository at this point in the history
* progress on PoV tests

* started precompile migration

* finished author precompile tests

* bn and callpermit precompiles done

* collective precompile done

* beginning conviction voting tests

* Updated to moonwall4

* fix

* added erc20 precompile tests

* progress on local asset precompile

* Added Local assets tests

* modexp tests done

* Added proxy tests

* progress on proxy tests

* finished proxy tests

* updated precompile tests

* added more precompile tests

* progress

* added more precompile tests

* refactored wormhole tests

* added XCM transactor tests

* started xcm utils tests

* Precompile tests done

* done proxy tests

* randomness tests

* randomness tests

* randomness tests

* finished randomness tests

* added receipt tests

* staking tests

* more staking tests

* more staking

* progress

* completed staking tests

* added subscription tests

* added sudo tests

* added treasury tests

* update moonwall config

* added missing conviction tests

* txpool progress

* tx pool tests done

* CI fix

* updated prettier CI

* editorconfig

* pnpm cache

* changed CI

* fix CI

* changes

* fix CI

* fixed some tests

* more test fixes

* fixed tests

* lint

* editor config

* pkg fix

* updated lockfile

* pkg updates

* fix import

* fix import

* archived old-style dev-tests

* lint

* PR comments

* Port ERC20-XCM tests. Add excess gas tests (#2410)

* ERC20XCM tests

* Add tsx

* Moved expect out of xcm helper

* Removed unused imports

* removed old tests

* editorconfig grr

* removed smoke tests

* Upgraded randomness smoketest

* updated randomness comments

* Fix conviction MaxVotes (#2401)

* Reduce the ConvictionVoting MaxVotes from 512 to 30

* Set MaxVote to 20

* Run toml-sort and update repo reference (#2426)

* [MOON-2434] remove deprecated leave delegator functionality (#2349)

* remove leave delegator functionality

* remove precompile methods

* return error for removed call indices

* removed scheduleLeaveDelegators calls

* de-bun 馃珦 the CI

* fix

* smoke-fix

* fixed ci

---------

Co-authored-by: Francisco Gamundi <52399794+fgamundi@users.noreply.github.com>
Co-authored-by: Alan Sapede <alan.sapede@gmail.com>
  • Loading branch information
3 people committed Aug 10, 2023
1 parent ad27c07 commit c784d12
Show file tree
Hide file tree
Showing 553 changed files with 30,797 additions and 15,210 deletions.
6 changes: 3 additions & 3 deletions .github/workflow-templates/dev-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: "pnpm"
cache-dependency-path: test/pnpm-lock.yaml

Expand All @@ -42,9 +42,9 @@ runs:
run: |
chmod uog+x target/release/moonbeam
cd test
# pnpm i
pnpm install
pnpm compile-solidity
pnpm moonwall test ${{ inputs.moonwall_environment }}
- name: Upload HTML report
if: always()
uses: actions/upload-artifact@v3.1.2
Expand Down
29 changes: 13 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,19 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Use Node.js 18.x
uses: actions/setup-node@v3
- uses: oven-sh/setup-bun@v1
with:
node-version: 18.x
bun-version: latest
- name: Check with Prettier
run: |
npx prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
|| (git diff --quiet \
|| (echo 'Unable to show a diff because there are unstaged changes'; false) \
&& (npx prettier@2 --ignore-path \
&& (bun x prettier@2 --ignore-path \
.prettierignore '**/*.(yml|js|ts|json)' -w --loglevel silent \
&& git --no-pager diff; git restore .) && false)
npx prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
check-cargo-toml-format:
name: "Check Cargo.toml files format"
Expand Down Expand Up @@ -374,7 +373,7 @@ jobs:
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
- name: Get tracing runtimes
run: |
./scripts/build-last-tracing-runtime.sh ${{ needs.set-tags.outputs.git_branch }}
Expand Down Expand Up @@ -493,10 +492,10 @@ jobs:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x
cache: "pnpm"
cache-dependency-path: test/pnpm-lock.yaml
- name: Create local folders
Expand All @@ -511,7 +510,7 @@ jobs:
- name: "Install and run upgrade test"
run: |
cd test
pnpm i
pnpm install
pnpm moonwall test upgrade_${{matrix.chain}}
zombie_upgrade_test:
Expand All @@ -532,12 +531,10 @@ jobs:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: pnpm/action-setup@v2
with:
version: 7
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "pnpm"
cache-dependency-path: test/pnpm-lock.yaml
node-version: 20.x
- name: Create local folders
run: |
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
Expand Down Expand Up @@ -573,12 +570,12 @@ jobs:
- name: "Run zombie upgrade test"
run: |
cd test
pnpm i
pnpm install
## Generate old spec using latest published node, modify it, and generate raw spec
chmod uog+x tmp/moonbeam_rt
tmp/moonbeam_rt build-spec --chain ${{ matrix.chain }}-local > tmp/${{ matrix.chain }}-plain-spec.json
pnpm ts-node --esm --swc scripts/modify-plain-specs.ts process tmp/${{ matrix.chain }}-plain-spec.json tmp/${{ matrix.chain }}-modified-spec.json
pnpm tsx scripts/modify-plain-specs.ts process tmp/${{ matrix.chain }}-plain-spec.json tmp/${{ matrix.chain }}-modified-spec.json
tmp/moonbeam_rt build-spec --chain tmp/${{ matrix.chain }}-modified-spec.json --raw > tmp/${{ matrix.chain }}-raw-spec.json
## Start zombie network and run tests
Expand Down
7 changes: 5 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Typescript directories
**/node_modules
**/.yarn
test/tsconfig.json

# Spec/Wasm build directory
/build/
Expand All @@ -31,5 +32,7 @@ tests/util/tracer/blockscout_tracer*
# Typescript-api is autogenerated
/typescript-api/

# Forge lib submodules
/test/contracts/lib
# Temporary Moonwall files
**/contracts/out
**/tmp/
**/html/
3 changes: 1 addition & 2 deletions test/.npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ignore-workspace-root-check = true
strict-peer-dependencies = false
registry = https://registry.npmjs.org/
auto-install-peers = false
node-linker = hoisted
auto-install-peers = true
24 changes: 16 additions & 8 deletions test/contracts/src/CallForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
pragma solidity >=0.8.3;

contract CallForwarder {
function call(address target, bytes memory data)
public
returns (bool, bytes memory)
{
function call(
address target,
bytes memory data
) public returns (bool, bytes memory) {
return target.call(data);
}

function delegateCall(address target, bytes memory data)
public
returns (bool, bytes memory)
{
function callRange(address first, address last) public {
require(first < last, "invalid range");
while (first < last) {
first.call("");
first = address(uint160(first) + 1);
}
}

function delegateCall(
address target,
bytes memory data
) public returns (bool, bytes memory) {
return target.delegatecall(data);
}
}
29 changes: 29 additions & 0 deletions test/contracts/src/ERC20ExcessGas.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.3;

import "./ERC20WithInitialSupply.sol";

contract ERC20ExcessGas is ERC20WithInitialSupply {
uint public _gasHog;

constructor(
string memory name_,
string memory symbol_,
address initialAccount,
uint256 initialSupply
) ERC20WithInitialSupply(name_, symbol_, initialAccount, initialSupply) {}

function transfer(
address to,
uint256 amount
) public override returns (bool) {
// Consume gas to over Erc20XcmBridgeTransferGasLimit
for (uint i = 0; i < 500; i++) {
_gasHog += i;
}

address owner = msg.sender;
_transfer(owner, to, amount);
return true;
}
}
2 changes: 1 addition & 1 deletion test/contracts/src/ERC20WithInitialSupply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract ERC20WithInitialSupply is IERC20 {
function transfer(
address to,
uint256 amount
) public override returns (bool) {
) public virtual override returns (bool) {
address owner = msg.sender;
_transfer(owner, to, amount);
return true;
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const verifyBlockFees = async (
// (await context.web3().eth.getBlock(number - 1)).baseFeePerGas!
// );
const baseFeePerGas = (
await context.viem("public").getBlock({ blockNumber: BigInt(number - 1) })
await context.viem().getBlock({ blockNumber: BigInt(number - 1) })
).baseFeePerGas!;
let priorityFee;

Expand Down
36 changes: 17 additions & 19 deletions test/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { DevModeContext, importJsonConfig } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";
import { u32 } from "@polkadot/types";
import { EXTRINSIC_VERSION } from "@polkadot/types/extrinsic/v4/Extrinsic";
import {
createMetadata,
getSpecTypes,
KeyringPair,
OptionsWithMeta,
TypeRegistry,
} from "@substrate/txwrapper-core";
import { createMetadata, KeyringPair, OptionsWithMeta } from "@substrate/txwrapper-core";
import Bottleneck from "bottleneck";
import { DevModeContext, importJsonConfig, MoonwallContext } from "@moonwall/cli";
import { ethers, Signer } from "ethers";
import fetch from "node-fetch";
import { Chain } from "viem";

export function rateLimiter() {
export function chunk<T>(array: Array<T>, size: number): Array<Array<T>> {
const chunks = [];
for (let i = 0; i < array.length; i += size) {
chunks.push(array.slice(i, i + size));
}

return chunks;
}

export function rateLimiter(options?: Bottleneck.ConstructorOptions) {
const settings =
process.env.SKIP_RATE_LIMITER === "true" ? {} : { maxConcurrent: 10, minTime: 150 };
process.env.SKIP_RATE_LIMITER === "true"
? {}
: { maxConcurrent: 10, minTime: 50, ...(options || {}) };

return new Bottleneck(settings);
}

export async function checkTimeSliceForUpgrades(
api: ApiPromise,
blockNumbers: number[],
Expand Down Expand Up @@ -47,18 +49,14 @@ export function sortObjectByKeys(unsortedObject: Record<string, any>): Record<st
}, {});
}

export async function getMappingInfo(
context: DevModeContext,
authorId: string
): Promise<{ account: string; deposit: BigInt } | null> {
export async function getMappingInfo(context: DevModeContext, authorId: string) {
const mapping = await context.polkadotJs().query.authorMapping.mappingWithDeposit(authorId);
if (mapping.isSome) {
return {
account: mapping.unwrap().account.toString(),
deposit: mapping.unwrap().deposit.toBigInt(),
};
}
return null;
}

export async function getProviderPath() {
Expand Down
67 changes: 67 additions & 0 deletions test/helpers/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { DevModeContext } from "@moonwall/cli";
import { ALITH_ADDRESS, alith } from "@moonwall/util";

export interface HeavyContract {
deployed: boolean;
account: string;
key: string;
}
/**
* @description Deploy multiple contracts to test the EVM storage limit.
* @param context Context of the test
* @param count Number of contracts to deploy
* @returns
*/
export const deployHeavyContracts = async (context: DevModeContext, first = 6000, last = 6999) => {
// Generate the contract addresses
const contracts = await Promise.all(
new Array(last - first + 1).fill(0).map(async (_, i) => {
const account = `0x${(i + first).toString(16).padStart(40, "0")}`;
return {
deployed: false,
account,
key: context.polkadotJs().query.evm.accountCodes.key(account),
};
})
);

// Check which contracts are already deployed
for (const contract of contracts) {
contract.deployed =
(await context.polkadotJs().rpc.state.getStorage(contract.key))!.toString().length > 10;
}

// Create the contract code (24kb of zeros)
const evmCode = `60006000fd${"0".repeat(24_000 * 2)}`;
const storageData = `${context
.polkadotJs()
.registry.createType("Compact<u32>", `0x${BigInt((evmCode.length + 1) * 2).toString(16)}`)
.toHex(true)}${evmCode}`;

// Create the batchs of contracts to deploy
const batchs = contracts
.reduce(
(acc, value) => {
if (acc[acc.length - 1].length >= 30) acc.push([]);
if (!value.deployed) acc[acc.length - 1].push([value.key, storageData]);
return acc;
},
[[]] as [string, string][][]
)
.filter((batch) => batch.length > 0);

// Set the storage of the contracts
let nonce = await context.viem().getTransactionCount({ address: ALITH_ADDRESS });
for (let i = 0; i < batchs.length; i++) {
const batch = batchs[i];
await context.createBlock([
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.system.setStorage(batch))
.signAsync(alith, {
nonce: nonce++,
}),
]);
}
return contracts as HeavyContract[];
};

0 comments on commit c784d12

Please sign in to comment.