-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-precompile-over-pov2.ts
123 lines (110 loc) · 3.64 KB
/
test-precompile-over-pov2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import "@moonbeam-network/api-augment";
import {
beforeAll,
deployCreateCompiledContract,
describeSuite,
expect,
fetchCompiledContract,
} from "@moonwall/cli";
import {
MAX_ETH_POV_PER_TX,
PRECOMPILE_BATCH_ADDRESS,
createEthersTransaction,
} from "@moonwall/util";
import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";
describeSuite({
id: "D012805",
title: "PoV precompile test - PoV Limit (3.5Mb in Dev)",
foundationMethods: "dev",
testCases: ({ context, log, it }) => {
let contracts: HeavyContract[];
let batchAbi: Abi;
let proxyAbi: Abi;
let proxyAddress: `0x${string}`;
let emptyBlockProofSize: bigint;
beforeAll(async function () {
// Create an empty block to estimate empty block proof size
const { block } = await context.createBlock();
// Empty blocks usually do not exceed 50kb
emptyBlockProofSize = BigInt(block.proofSize || 50_000);
const { contractAddress: contractAdd1, abi } = await deployCreateCompiledContract(
context,
"CallForwarder"
);
proxyAddress = contractAdd1;
proxyAbi = abi;
contracts = await deployHeavyContracts(
context,
6000,
Number(6000n + MAX_ETH_POV_PER_TX / 24_000n + 1n)
);
// Get the interface for Batch precompile
batchAbi = fetchCompiledContract("Batch").abi;
});
it({
id: "T01",
title: "should allow to produce block under the PoV Limit with precompile tx",
test: async function () {
const maxContracts = MAX_ETH_POV_PER_TX / 24_000n - 1n;
const callData = encodeFunctionData({
abi: batchAbi,
functionName: "batchAll",
args: [
[proxyAddress],
[],
[
encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[Number(maxContracts)].account],
}),
],
[],
],
});
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 13_000_000,
});
const { result, block } = await context.createBlock(rawSigned);
expect(block.proofSize).to.be.at.least(Number(MAX_ETH_POV_PER_TX - 20_000n));
expect(block.proofSize).to.be.at.most(Number(MAX_ETH_POV_PER_TX + emptyBlockProofSize));
expect(result?.successful).to.equal(true);
},
});
it({
id: "T0",
title: "should prevent a tx reaching just over the PoV with a precompile tx",
test: async function () {
const maxContracts = MAX_ETH_POV_PER_TX / 24_000n;
const callData = encodeFunctionData({
abi: batchAbi,
functionName: "batchAll",
args: [
[proxyAddress],
[],
[
encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[Number(maxContracts)].account],
}),
],
[],
],
});
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 15_000_000,
});
const { result, block } = await context.createBlock(rawSigned);
// Empty blocks usually do not exceed 10kb, picking 50kb as a safe limit
expect(block.proofSize).to.be.at.most(50_000);
expect(result?.successful).to.equal(false);
},
});
},
});