Skip to content

Commit b742feb

Browse files
authored
Restore precompile macro tests (polkadot-evm#1808)
* Restore precompile macro tests * editorconfig: exclude *.expanded.rs files * pin specific nightly version * normalize path
1 parent f90139d commit b742feb

38 files changed

+2197
-1814
lines changed

.github/workflows/editorconfig.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v6
2121
- uses: editorconfig-checker/action-editorconfig-checker@main
22-
- run: editorconfig-checker -disable-charset
22+
- run: editorconfig-checker -disable-charset -exclude '\.expanded\.rs$'

.github/workflows/test.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ env:
2222
SCCACHE_GHA_ENABLED: "true"
2323

2424
jobs:
25+
changes:
26+
name: Detect Changes
27+
runs-on: ubuntu-latest
28+
permissions:
29+
pull-requests: read
30+
outputs:
31+
precompile-macro: ${{ steps.filter.outputs.precompile-macro }}
32+
steps:
33+
- name: Checkout sources
34+
uses: actions/checkout@v6
35+
36+
- name: Detect changed paths
37+
uses: dorny/paths-filter@v3
38+
id: filter
39+
with:
40+
filters: |
41+
precompile-macro:
42+
- 'precompiles/macro/**'
43+
2544
unit-test:
2645
name: Run Unit Tests
2746
runs-on: ubuntu-latest
@@ -97,3 +116,40 @@ jobs:
97116

98117
- name: Run integration tests
99118
run: make integration-test
119+
120+
precompile-macro-test:
121+
name: Run Precompile Macro Tests
122+
needs: changes
123+
if: ${{ needs.changes.outputs.precompile-macro == 'true' }}
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: Checkout sources
127+
uses: actions/checkout@v6
128+
129+
- name: Cache cargo registry & git sources
130+
uses: actions/cache@v5
131+
with:
132+
path: |
133+
~/.cargo/bin/
134+
~/.cargo/registry/
135+
~/.cargo/git/db/
136+
key: ${{ runner.os }}-cargo-precompile-macro-${{ hashFiles('**/Cargo.lock') }}
137+
restore-keys: |
138+
${{ runner.os }}-cargo-precompile-macro-${{ hashFiles('**/Cargo.lock') }}
139+
${{ runner.os }}-cargo-precompile-macro-
140+
${{ runner.os }}-cargo-
141+
142+
- name: Run sccache
143+
uses: mozilla-actions/sccache-action@v0.0.9
144+
145+
- name: Install stable Rust toolchain
146+
run: make setup
147+
148+
- name: Install nightly Rust toolchain
149+
run: rustup install nightly-2026-01-31
150+
151+
- name: Install cargo-expand
152+
run: cargo +nightly-2026-01-31 install cargo-expand --force --locked || true
153+
154+
- name: Run precompile-utils-macro tests
155+
run: cargo +nightly-2026-01-31 test -p precompile-utils-macro

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

precompiles/macro/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ precompile-utils = { path = "../", features = ["testing"] }
2929

3030
fp-evm = { workspace = true }
3131
frame-support = { workspace = true }
32+
sp-core = { workspace = true }

precompiles/macro/src/precompile/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl Precompile {
420420
let discriminant = match discriminant {
421421
DiscriminantResult::Some(d, _) => d,
422422
DiscriminantResult::None(cost) => return None,
423-
DiscriminantResult::OutOfGas => return Some(Err(ExitError::OutOfGas.into()))
423+
DiscriminantResult::OutOfGas => return Some(Err(::fp_evm::ExitError::OutOfGas.into()))
424424
};
425425

426426
#opt_pre_check
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: Codec can only be derived for structs with named fields
2-
--> tests/compile-fail/derive_codec/empty_struct.rs:20:8
2+
--> tests/compile-fail/derive_codec/empty_struct.rs:22:8
33
|
4-
20 | struct Empty1;
4+
22 | struct Empty1;
55
| ^^^^^^
66

77
error: Codec can only be derived for structs with at least one field
8-
--> tests/compile-fail/derive_codec/empty_struct.rs:23:8
8+
--> tests/compile-fail/derive_codec/empty_struct.rs:25:8
99
|
10-
23 | struct Empty2 {}
10+
25 | struct Empty2 {}
1111
| ^^^^^^
1212

1313
error: Codec can only be derived for structs with named fields
14-
--> tests/compile-fail/derive_codec/empty_struct.rs:26:8
14+
--> tests/compile-fail/derive_codec/empty_struct.rs:28:8
1515
|
16-
26 | struct Empty3 ();
16+
28 | struct Empty3();
1717
| ^^^^^^
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Codec can only be derived for structs with named fields
2-
--> tests/compile-fail/derive_codec/enum.rs:20:6
2+
--> tests/compile-fail/derive_codec/enum.rs:22:6
33
|
4-
20 | enum Test {
4+
22 | enum Test {
55
| ^^^^

precompiles/macro/tests/compile-fail/precompile/codec/arg-dont-impl-codec.stderr

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
error[E0277]: the trait bound `String: Codec` is not satisfied
2-
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:26:43
2+
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:28:43
33
|
4-
26 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
4+
28 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
55
| ^^^ the trait `Codec` is not implemented for `String`
66
|
7+
= note: `String` implements similarly named trait `parity_scale_codec::codec::Codec`, but not `Codec`
78
= help: the following other types implement trait `Codec`:
89
()
910
(TupleElement0, TupleElement1)
@@ -15,17 +16,18 @@ error[E0277]: the trait bound `String: Codec` is not satisfied
1516
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
1617
and $N others
1718
note: required by a bound in `Reader::<'inner>::read`
18-
--> $WORKSPACE/precompiles/utils/src/solidity/codec/mod.rs
19+
--> $WORKSPACE/precompiles/src/solidity/codec/mod.rs
1920
|
2021
| pub fn read<T: Codec>(&mut self) -> MayRevert<T> {
2122
| ^^^^^ required by this bound in `Reader::<'inner>::read`
2223

2324
error[E0277]: the trait bound `String: Codec` is not satisfied
24-
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:26:43
25+
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:28:43
2526
|
26-
26 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
27+
28 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
2728
| ^^^ the trait `Codec` is not implemented for `String`
2829
|
30+
= note: `String` implements similarly named trait `parity_scale_codec::codec::Codec`, but not `Codec`
2931
= help: the following other types implement trait `Codec`:
3032
()
3133
(TupleElement0, TupleElement1)
@@ -36,18 +38,19 @@ error[E0277]: the trait bound `String: Codec` is not satisfied
3638
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6)
3739
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
3840
and $N others
39-
note: required by a bound in `precompile_utils::solidity::codec::Writer::write`
40-
--> $WORKSPACE/precompiles/utils/src/solidity/codec/mod.rs
41+
note: required by a bound in `Writer::write`
42+
--> $WORKSPACE/precompiles/src/solidity/codec/mod.rs
4143
|
4244
| pub fn write<T: Codec>(mut self, value: T) -> Self {
4345
| ^^^^^ required by this bound in `Writer::write`
4446

4547
error[E0277]: the trait bound `String: Codec` is not satisfied
46-
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:26:5
48+
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:28:5
4749
|
48-
26 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
50+
28 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
4951
| ^^^ the trait `Codec` is not implemented for `String`
5052
|
53+
= note: `String` implements similarly named trait `parity_scale_codec::codec::Codec`, but not `Codec`
5154
= help: the following other types implement trait `Codec`:
5255
()
5356
(TupleElement0, TupleElement1)
@@ -59,3 +62,17 @@ error[E0277]: the trait bound `String: Codec` is not satisfied
5962
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
6063
and $N others
6164
= note: required for `(String,)` to implement `Codec`
65+
66+
warning: unused variable: `test`
67+
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:28:9
68+
|
69+
28 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
70+
| ^^^^ help: if this is intentional, prefix it with an underscore: `_test`
71+
|
72+
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
73+
74+
warning: unused variable: `arg`
75+
--> tests/compile-fail/precompile/codec/arg-dont-impl-codec.rs:28:43
76+
|
77+
28 | fn foo(test: &mut impl PrecompileHandle, arg: String) -> EvmResult {
78+
| ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: A precompile method must have a return type of `EvmResult<_>` (exposed by `precompile_utils`)
2-
--> tests/compile-fail/precompile/codec/no-output.rs:24:2
2+
--> tests/compile-fail/precompile/codec/no-output.rs:26:2
33
|
4-
24 | fn foo(test: &mut impl PrecompileHandle) {
5-
| ^^
4+
26 | fn foo(test: &mut impl PrecompileHandle) {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
error[E0277]: the trait bound `String: Codec` is not satisfied
2-
--> tests/compile-fail/precompile/codec/output-dont-impl-codec.rs:26:46
2+
--> tests/compile-fail/precompile/codec/output-dont-impl-codec.rs:28:46
33
|
4-
26 | fn foo(test: &mut impl PrecompileHandle) -> EvmResult<String> {
5-
| ^^^^^^^^^ the trait `Codec` is not implemented for `String`
4+
28 | fn foo(test: &mut impl PrecompileHandle) -> EvmResult<String> {
5+
| ^^^^^^^^^^^^^^^^^ the trait `Codec` is not implemented for `String`
66
|
7+
= note: `String` implements similarly named trait `parity_scale_codec::codec::Codec`, but not `Codec`
78
= help: the following other types implement trait `Codec`:
89
()
910
(TupleElement0, TupleElement1)
@@ -15,7 +16,15 @@ error[E0277]: the trait bound `String: Codec` is not satisfied
1516
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)
1617
and $N others
1718
note: required by a bound in `encode_arguments`
18-
--> $WORKSPACE/precompiles/utils/src/solidity/codec/mod.rs
19+
--> $WORKSPACE/precompiles/src/solidity/codec/mod.rs
1920
|
2021
| pub fn encode_arguments<T: Codec>(value: T) -> Vec<u8> {
2122
| ^^^^^ required by this bound in `encode_arguments`
23+
24+
warning: unused variable: `test`
25+
--> tests/compile-fail/precompile/codec/output-dont-impl-codec.rs:28:9
26+
|
27+
28 | fn foo(test: &mut impl PrecompileHandle) -> EvmResult<String> {
28+
| ^^^^ help: if this is intentional, prefix it with an underscore: `_test`
29+
|
30+
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

0 commit comments

Comments
 (0)