-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-evm-over-pov.ts
107 lines (93 loc) · 3.9 KB
/
test-evm-over-pov.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
import "@moonbeam-network/api-augment";
import { beforeAll, deployCreateCompiledContract, describeSuite, expect } from "@moonwall/cli";
import { ALITH_ADDRESS, createEthersTransaction } from "@moonwall/util";
import { Abi, encodeFunctionData } from "viem";
import { expectEVMResult, HeavyContract, deployHeavyContracts } from "../../../../helpers";
describeSuite({
id: "D012801",
title: "PoV controlled by gasLimit",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
let proxyAddress: `0x${string}`;
let proxyAbi: Abi;
let contracts: HeavyContract[];
let callData: `0x${string}`;
const MAX_CONTRACTS = 20;
const EXPECTED_POV_ROUGH = 500_000; // bytes
beforeAll(async () => {
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, 6000 + MAX_CONTRACTS);
callData = encodeFunctionData({
abi: proxyAbi,
functionName: "callRange",
args: [contracts[0].account, contracts[MAX_CONTRACTS].account],
});
});
it({
id: "T01",
title: "should allow to include transaction with estimate gas to cover PoV",
test: async function () {
const gasEstimate = await context.viem().estimateGas({
account: ALITH_ADDRESS,
to: proxyAddress,
value: 0n,
data: callData,
});
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
txnType: "eip1559",
gasLimit: gasEstimate,
});
const { result, block } = await context.createBlock(rawSigned);
log(`block.proofSize: ${block.proofSize} (successful: ${result?.successful})`);
expect(block.proofSize).toBeGreaterThanOrEqual(EXPECTED_POV_ROUGH / 1.1);
expect(block.proofSize).toBeLessThanOrEqual(EXPECTED_POV_ROUGH * 1.1);
expect(result?.successful).to.equal(true);
},
});
it({
id: "T02",
title: "should allow to include transaction with enough gas limit to cover PoV",
test: async function () {
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
txnType: "eip1559",
gasLimit: 3_000_000,
});
const { result, block } = await context.createBlock(rawSigned);
log(`block.proof_size: ${block.proofSize} (successful: ${result?.successful})`);
expect(block.proofSize).to.be.at.least(EXPECTED_POV_ROUGH / 1.1);
expect(block.proofSize).to.be.at.most(EXPECTED_POV_ROUGH * 1.1);
expect(result?.successful).to.equal(true);
},
});
it({
id: "T03",
title: "should fail to include transaction without enough gas limit to cover PoV",
test: async function () {
// This execution uses only < 100k Gas in cpu execute but require 2M Gas for PoV.
// We are providing only 1M Gas, so it should fail.
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
txnType: "eip1559",
gasLimit: 1_000_000,
});
const { result, block } = await context.createBlock(rawSigned);
log(`block.proof_size: ${block.proofSize} (successful: ${result?.successful})`);
// The block still contain the failed (out of gas) transaction so the PoV is still included
// in the block.
// 1M Gas allows ~250k of PoV, so we verify we are within range.
expect(block.proofSize).to.be.at.least(230_000);
expect(block.proofSize).to.be.at.most(300_000);
expect(result?.successful).to.equal(true);
expectEVMResult(result!.events, "Error", "OutOfGas");
},
});
},
});