Skip to content

Commit c784d12

Browse files
timbrindedfgamundicrystalin
authored
🧪 dev-test migration to Moonwall #2 (#2375)
* 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 <[email protected]> Co-authored-by: Alan Sapede <[email protected]>
1 parent ad27c07 commit c784d12

File tree

553 files changed

+30797
-15210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

553 files changed

+30797
-15210
lines changed

.github/workflow-templates/dev-tests/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ runs:
1515
version: 8
1616
- uses: actions/setup-node@v3
1717
with:
18-
node-version: 18.x
18+
node-version: 20.x
1919
cache: "pnpm"
2020
cache-dependency-path: test/pnpm-lock.yaml
2121

@@ -42,9 +42,9 @@ runs:
4242
run: |
4343
chmod uog+x target/release/moonbeam
4444
cd test
45-
# pnpm i
45+
pnpm install
46+
pnpm compile-solidity
4647
pnpm moonwall test ${{ inputs.moonwall_environment }}
47-
4848
- name: Upload HTML report
4949
if: always()
5050
uses: actions/[email protected]

.github/workflows/build.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,19 @@ jobs:
169169
uses: actions/checkout@v3
170170
with:
171171
ref: ${{ needs.set-tags.outputs.git_ref }}
172-
- name: Use Node.js 18.x
173-
uses: actions/setup-node@v3
172+
- uses: oven-sh/setup-bun@v1
174173
with:
175-
node-version: 18.x
174+
bun-version: latest
176175
- name: Check with Prettier
177176
run: |
178-
npx prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
177+
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)' \
179178
|| (git diff --quiet \
180179
|| (echo 'Unable to show a diff because there are unstaged changes'; false) \
181-
&& (npx prettier@2 --ignore-path \
180+
&& (bun x prettier@2 --ignore-path \
182181
.prettierignore '**/*.(yml|js|ts|json)' -w --loglevel silent \
183182
&& git --no-pager diff; git restore .) && false)
184183
185-
npx prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
184+
bun x prettier@2 --check --ignore-path .prettierignore '**/*.(yml|js|ts|json)'
186185
187186
check-cargo-toml-format:
188187
name: "Check Cargo.toml files format"
@@ -374,7 +373,7 @@ jobs:
374373
- name: Use Node.js 18.x
375374
uses: actions/setup-node@v3
376375
with:
377-
node-version: 18.x
376+
node-version: 20.x
378377
- name: Get tracing runtimes
379378
run: |
380379
./scripts/build-last-tracing-runtime.sh ${{ needs.set-tags.outputs.git_branch }}
@@ -493,10 +492,10 @@ jobs:
493492
ref: ${{ needs.set-tags.outputs.git_ref }}
494493
- uses: pnpm/action-setup@v2
495494
with:
496-
version: 7
495+
version: 8
497496
- uses: actions/setup-node@v3
498497
with:
499-
node-version: 18.x
498+
node-version: 20.x
500499
cache: "pnpm"
501500
cache-dependency-path: test/pnpm-lock.yaml
502501
- name: Create local folders
@@ -511,7 +510,7 @@ jobs:
511510
- name: "Install and run upgrade test"
512511
run: |
513512
cd test
514-
pnpm i
513+
pnpm install
515514
pnpm moonwall test upgrade_${{matrix.chain}}
516515
517516
zombie_upgrade_test:
@@ -532,12 +531,10 @@ jobs:
532531
ref: ${{ needs.set-tags.outputs.git_ref }}
533532
- uses: pnpm/action-setup@v2
534533
with:
535-
version: 7
534+
version: 8
536535
- uses: actions/setup-node@v3
537536
with:
538-
node-version: 18.x
539-
cache: "pnpm"
540-
cache-dependency-path: test/pnpm-lock.yaml
537+
node-version: 20.x
541538
- name: Create local folders
542539
run: |
543540
mkdir -p target/release/wbuild/${{ matrix.chain }}-runtime/
@@ -573,12 +570,12 @@ jobs:
573570
- name: "Run zombie upgrade test"
574571
run: |
575572
cd test
576-
pnpm i
573+
pnpm install
577574
578575
## Generate old spec using latest published node, modify it, and generate raw spec
579576
chmod uog+x tmp/moonbeam_rt
580577
tmp/moonbeam_rt build-spec --chain ${{ matrix.chain }}-local > tmp/${{ matrix.chain }}-plain-spec.json
581-
pnpm ts-node --esm --swc scripts/modify-plain-specs.ts process tmp/${{ matrix.chain }}-plain-spec.json tmp/${{ matrix.chain }}-modified-spec.json
578+
pnpm tsx scripts/modify-plain-specs.ts process tmp/${{ matrix.chain }}-plain-spec.json tmp/${{ matrix.chain }}-modified-spec.json
582579
tmp/moonbeam_rt build-spec --chain tmp/${{ matrix.chain }}-modified-spec.json --raw > tmp/${{ matrix.chain }}-raw-spec.json
583580
584581
## Start zombie network and run tests

.prettierignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Typescript directories
99
**/node_modules
1010
**/.yarn
11+
test/tsconfig.json
1112

1213
# Spec/Wasm build directory
1314
/build/
@@ -31,5 +32,7 @@ tests/util/tracer/blockscout_tracer*
3132
# Typescript-api is autogenerated
3233
/typescript-api/
3334

34-
# Forge lib submodules
35-
/test/contracts/lib
35+
# Temporary Moonwall files
36+
**/contracts/out
37+
**/tmp/
38+
**/html/

test/.npmrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ignore-workspace-root-check = true
22
strict-peer-dependencies = false
33
registry = https://registry.npmjs.org/
4-
auto-install-peers = false
5-
node-linker = hoisted
4+
auto-install-peers = true

test/contracts/src/CallForwarder.sol

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
pragma solidity >=0.8.3;
33

44
contract CallForwarder {
5-
function call(address target, bytes memory data)
6-
public
7-
returns (bool, bytes memory)
8-
{
5+
function call(
6+
address target,
7+
bytes memory data
8+
) public returns (bool, bytes memory) {
99
return target.call(data);
1010
}
1111

12-
function delegateCall(address target, bytes memory data)
13-
public
14-
returns (bool, bytes memory)
15-
{
12+
function callRange(address first, address last) public {
13+
require(first < last, "invalid range");
14+
while (first < last) {
15+
first.call("");
16+
first = address(uint160(first) + 1);
17+
}
18+
}
19+
20+
function delegateCall(
21+
address target,
22+
bytes memory data
23+
) public returns (bool, bytes memory) {
1624
return target.delegatecall(data);
1725
}
1826
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
pragma solidity >=0.8.3;
3+
4+
import "./ERC20WithInitialSupply.sol";
5+
6+
contract ERC20ExcessGas is ERC20WithInitialSupply {
7+
uint public _gasHog;
8+
9+
constructor(
10+
string memory name_,
11+
string memory symbol_,
12+
address initialAccount,
13+
uint256 initialSupply
14+
) ERC20WithInitialSupply(name_, symbol_, initialAccount, initialSupply) {}
15+
16+
function transfer(
17+
address to,
18+
uint256 amount
19+
) public override returns (bool) {
20+
// Consume gas to over Erc20XcmBridgeTransferGasLimit
21+
for (uint i = 0; i < 500; i++) {
22+
_gasHog += i;
23+
}
24+
25+
address owner = msg.sender;
26+
_transfer(owner, to, amount);
27+
return true;
28+
}
29+
}

test/contracts/src/ERC20WithInitialSupply.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ contract ERC20WithInitialSupply is IERC20 {
5353
function transfer(
5454
address to,
5555
uint256 amount
56-
) public override returns (bool) {
56+
) public virtual override returns (bool) {
5757
address owner = msg.sender;
5858
_transfer(owner, to, amount);
5959
return true;

test/helpers/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const verifyBlockFees = async (
169169
// (await context.web3().eth.getBlock(number - 1)).baseFeePerGas!
170170
// );
171171
const baseFeePerGas = (
172-
await context.viem("public").getBlock({ blockNumber: BigInt(number - 1) })
172+
await context.viem().getBlock({ blockNumber: BigInt(number - 1) })
173173
).baseFeePerGas!;
174174
let priorityFee;
175175

test/helpers/common.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1+
import { DevModeContext, importJsonConfig } from "@moonwall/cli";
12
import { ApiPromise } from "@polkadot/api";
23
import { u32 } from "@polkadot/types";
34
import { EXTRINSIC_VERSION } from "@polkadot/types/extrinsic/v4/Extrinsic";
4-
import {
5-
createMetadata,
6-
getSpecTypes,
7-
KeyringPair,
8-
OptionsWithMeta,
9-
TypeRegistry,
10-
} from "@substrate/txwrapper-core";
5+
import { createMetadata, KeyringPair, OptionsWithMeta } from "@substrate/txwrapper-core";
116
import Bottleneck from "bottleneck";
12-
import { DevModeContext, importJsonConfig, MoonwallContext } from "@moonwall/cli";
13-
import { ethers, Signer } from "ethers";
14-
import fetch from "node-fetch";
15-
import { Chain } from "viem";
167

17-
export function rateLimiter() {
8+
export function chunk<T>(array: Array<T>, size: number): Array<Array<T>> {
9+
const chunks = [];
10+
for (let i = 0; i < array.length; i += size) {
11+
chunks.push(array.slice(i, i + size));
12+
}
13+
14+
return chunks;
15+
}
16+
17+
export function rateLimiter(options?: Bottleneck.ConstructorOptions) {
1818
const settings =
19-
process.env.SKIP_RATE_LIMITER === "true" ? {} : { maxConcurrent: 10, minTime: 150 };
19+
process.env.SKIP_RATE_LIMITER === "true"
20+
? {}
21+
: { maxConcurrent: 10, minTime: 50, ...(options || {}) };
22+
2023
return new Bottleneck(settings);
2124
}
22-
2325
export async function checkTimeSliceForUpgrades(
2426
api: ApiPromise,
2527
blockNumbers: number[],
@@ -47,18 +49,14 @@ export function sortObjectByKeys(unsortedObject: Record<string, any>): Record<st
4749
}, {});
4850
}
4951

50-
export async function getMappingInfo(
51-
context: DevModeContext,
52-
authorId: string
53-
): Promise<{ account: string; deposit: BigInt } | null> {
52+
export async function getMappingInfo(context: DevModeContext, authorId: string) {
5453
const mapping = await context.polkadotJs().query.authorMapping.mappingWithDeposit(authorId);
5554
if (mapping.isSome) {
5655
return {
5756
account: mapping.unwrap().account.toString(),
5857
deposit: mapping.unwrap().deposit.toBigInt(),
5958
};
6059
}
61-
return null;
6260
}
6361

6462
export async function getProviderPath() {

test/helpers/contracts.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { DevModeContext } from "@moonwall/cli";
2+
import { ALITH_ADDRESS, alith } from "@moonwall/util";
3+
4+
export interface HeavyContract {
5+
deployed: boolean;
6+
account: string;
7+
key: string;
8+
}
9+
/**
10+
* @description Deploy multiple contracts to test the EVM storage limit.
11+
* @param context Context of the test
12+
* @param count Number of contracts to deploy
13+
* @returns
14+
*/
15+
export const deployHeavyContracts = async (context: DevModeContext, first = 6000, last = 6999) => {
16+
// Generate the contract addresses
17+
const contracts = await Promise.all(
18+
new Array(last - first + 1).fill(0).map(async (_, i) => {
19+
const account = `0x${(i + first).toString(16).padStart(40, "0")}`;
20+
return {
21+
deployed: false,
22+
account,
23+
key: context.polkadotJs().query.evm.accountCodes.key(account),
24+
};
25+
})
26+
);
27+
28+
// Check which contracts are already deployed
29+
for (const contract of contracts) {
30+
contract.deployed =
31+
(await context.polkadotJs().rpc.state.getStorage(contract.key))!.toString().length > 10;
32+
}
33+
34+
// Create the contract code (24kb of zeros)
35+
const evmCode = `60006000fd${"0".repeat(24_000 * 2)}`;
36+
const storageData = `${context
37+
.polkadotJs()
38+
.registry.createType("Compact<u32>", `0x${BigInt((evmCode.length + 1) * 2).toString(16)}`)
39+
.toHex(true)}${evmCode}`;
40+
41+
// Create the batchs of contracts to deploy
42+
const batchs = contracts
43+
.reduce(
44+
(acc, value) => {
45+
if (acc[acc.length - 1].length >= 30) acc.push([]);
46+
if (!value.deployed) acc[acc.length - 1].push([value.key, storageData]);
47+
return acc;
48+
},
49+
[[]] as [string, string][][]
50+
)
51+
.filter((batch) => batch.length > 0);
52+
53+
// Set the storage of the contracts
54+
let nonce = await context.viem().getTransactionCount({ address: ALITH_ADDRESS });
55+
for (let i = 0; i < batchs.length; i++) {
56+
const batch = batchs[i];
57+
await context.createBlock([
58+
context
59+
.polkadotJs()
60+
.tx.sudo.sudo(context.polkadotJs().tx.system.setStorage(batch))
61+
.signAsync(alith, {
62+
nonce: nonce++,
63+
}),
64+
]);
65+
}
66+
return contracts as HeavyContract[];
67+
};

0 commit comments

Comments
 (0)