-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-evm-over-pov2.ts
99 lines (84 loc) · 3.42 KB
/
test-evm-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
import "@moonbeam-network/api-augment";
import { beforeAll, deployCreateCompiledContract, describeSuite, expect } from "@moonwall/cli";
import { MAX_ETH_POV_PER_TX, createEthersTransaction } from "@moonwall/util";
import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";
describeSuite({
id: "D012802",
title: "PoV Limit (3.5Mb in Dev)",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
let proxyAddress: `0x${string}`;
let proxyAbi: Abi;
let contracts: HeavyContract[];
let callData: `0x${string}`;
let emptyBlockProofSize: bigint;
const MAX_CONTRACTS = 20;
beforeAll(async () => {
// 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, abi } = await deployCreateCompiledContract(context, "CallForwarder");
proxyAddress = contractAddress;
proxyAbi = abi;
// Deploy heavy contracts (test won't use more than what is needed for reaching max pov)
contracts = await deployHeavyContracts(
context,
6000,
Number(6000n + MAX_ETH_POV_PER_TX / 24_000n + 1n)
);
callData = encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[MAX_CONTRACTS].account],
});
});
it({
id: "T01",
title: "should allow to produce block just under the PoV Limit",
test: async function () {
const calculatedMax = MAX_ETH_POV_PER_TX / 24_000n - 1n;
const callData = encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[Number(calculatedMax)].account],
});
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
gasLimit: 13_000_000,
txnType: "eip1559",
});
const { result, block } = await context.createBlock(rawSigned);
log(`block.proofSize: ${block.proofSize} (successful: ${result?.successful})`);
expect(block.proofSize).toBeGreaterThanOrEqual(MAX_ETH_POV_PER_TX - 20_000n);
expect(block.proofSize).toBeLessThanOrEqual(MAX_ETH_POV_PER_TX + emptyBlockProofSize);
expect(result?.successful).to.equal(true);
},
});
it({
id: "T02",
title: "should prevent a transaction reaching just over the PoV",
test: async function () {
const calculatedMax = MAX_ETH_POV_PER_TX / 24_000n;
const callData = encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[Number(calculatedMax) + 1].account],
});
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
gasLimit: 15_000_000,
txnType: "eip1559",
});
const { result, block } = await context.createBlock(rawSigned);
log(`block.proofSize: ${block.proofSize} (successful: ${result?.successful})`);
// 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);
},
});
},
});