forked from 10d9e/zevm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.zig
More file actions
147 lines (122 loc) · 6.25 KB
/
main.zig
File metadata and controls
147 lines (122 loc) · 6.25 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const std = @import("std");
const primitives = @import("primitives");
const state = @import("state");
const bytecode = @import("bytecode");
const database = @import("database");
pub const BlockEnv = @import("block.zig").BlockEnv;
pub const BlobExcessGasAndPrice = @import("block.zig").BlobExcessGasAndPrice;
pub const TxEnv = @import("tx.zig").TxEnv;
pub const TxKind = @import("tx.zig").TxKind;
pub const AccessList = @import("tx.zig").AccessList;
pub const AccessListItem = @import("tx.zig").AccessListItem;
pub const Authorization = @import("tx.zig").Authorization;
pub const RecoveredAuthority = @import("tx.zig").RecoveredAuthority;
pub const RecoveredAuthorization = @import("tx.zig").RecoveredAuthorization;
pub const Either = @import("tx.zig").Either;
pub const CfgEnv = @import("cfg.zig").CfgEnv;
pub const Journal = @import("journal.zig").Journal;
pub const JournalCheckpoint = @import("journal.zig").JournalCheckpoint;
pub const StateLoad = @import("journal.zig").StateLoad;
pub const AccountInfoLoad = @import("journal.zig").AccountInfoLoad;
pub const SStoreResult = @import("journal.zig").SStoreResult;
pub const SelfDestructResult = @import("journal.zig").SelfDestructResult;
pub const TransferError = @import("journal.zig").TransferError;
pub const AccountPreState = @import("journal.zig").AccountPreState;
pub const AccessLog = @import("journal.zig").AccessLog;
pub const ContextError = @import("context.zig").ContextError;
pub const LocalContext = @import("local.zig").LocalContext;
pub const Context = @import("context.zig").Context;
pub const DefaultContext = @import("context.zig").DefaultContext;
pub const Evm = @import("evm.zig").Evm;
// Re-export all context types
pub const BlockEnvBuilder = @import("block.zig").BlockEnvBuilder;
pub const TxEnvBuilder = @import("tx.zig").TxEnvBuilder;
pub const CfgEnvBuilder = @import("cfg.zig").CfgEnvBuilder;
// Testing functions
pub const testing = struct {
pub fn testBlockEnv() !void {
std.debug.print("Testing BlockEnv...\n", .{});
var block_env = BlockEnv.default();
std.debug.assert(block_env.number == @as(primitives.U256, 0));
std.debug.assert(std.mem.eql(u8, &block_env.beneficiary, &([_]u8{0} ** 20)));
std.debug.assert(block_env.timestamp == @as(primitives.U256, 1));
std.debug.assert(block_env.gas_limit == std.math.maxInt(u64));
std.debug.assert(block_env.basefee == 0);
std.debug.assert(block_env.difficulty == @as(primitives.U256, 0));
std.debug.assert(block_env.prevrandao != null);
std.debug.assert(block_env.blob_excess_gas_and_price != null);
std.debug.print("BlockEnv tests passed.\n", .{});
}
pub fn testTxEnv() !void {
std.debug.print("Testing TxEnv...\n", .{});
var tx_env = TxEnv.default();
std.debug.assert(tx_env.tx_type == 0);
std.debug.assert(std.mem.eql(u8, &tx_env.caller, &([_]u8{0} ** 20)));
std.debug.assert(tx_env.gas_limit == 30000000); // EIP-7825 cap
std.debug.assert(tx_env.gas_price == 0);
std.debug.assert(tx_env.value == @as(primitives.U256, 0));
std.debug.assert(tx_env.nonce == 0);
std.debug.assert(tx_env.chain_id == 1);
std.debug.assert(tx_env.access_list.len() == 0);
std.debug.assert(tx_env.gas_priority_fee == null);
std.debug.assert(tx_env.blob_hashes == null);
std.debug.assert(tx_env.max_fee_per_blob_gas == 0);
std.debug.assert(tx_env.authorization_list == null);
std.debug.print("TxEnv tests passed.\n", .{});
}
pub fn testCfgEnv() !void {
std.debug.print("Testing CfgEnv...\n", .{});
const cfg_env = CfgEnv.default();
std.debug.assert(cfg_env.chain_id == 1);
std.debug.assert(cfg_env.tx_chain_id_check == true);
std.debug.assert(cfg_env.spec == primitives.SpecId.prague);
std.debug.assert(cfg_env.limit_contract_code_size == null);
std.debug.assert(cfg_env.limit_contract_initcode_size == null);
std.debug.assert(cfg_env.disable_nonce_check == false);
std.debug.assert(cfg_env.max_blobs_per_tx == null);
std.debug.assert(cfg_env.blob_base_fee_update_fraction == null);
std.debug.assert(cfg_env.tx_gas_limit_cap == null);
std.debug.print("CfgEnv tests passed.\n", .{});
}
pub fn testLocalContext() !void {
std.debug.print("Testing LocalContext...\n", .{});
var local_ctx = LocalContext.default();
std.debug.assert(local_ctx.shared_memory_buffer == null);
std.debug.assert(local_ctx.precompile_error_message == null);
local_ctx.clear();
std.debug.assert(local_ctx.shared_memory_buffer == null);
std.debug.assert(local_ctx.precompile_error_message == null);
std.debug.print("LocalContext tests passed.\n", .{});
}
pub fn testContext() !void {
std.debug.print("Testing Context...\n", .{});
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var db = database.InMemoryDB.init(allocator);
defer db.deinit();
const ctx = DefaultContext.new(db, primitives.SpecId.prague);
std.debug.assert(ctx.block.number == @as(primitives.U256, 0));
std.debug.assert(ctx.tx.tx_type == 0);
std.debug.assert(ctx.cfg.spec == primitives.SpecId.prague);
std.debug.assert(ctx.local.shared_memory_buffer == null);
std.debug.assert(ctx.ctx_error == ContextError.ok);
std.debug.print("Context tests passed.\n", .{});
}
pub fn testEvm() !void {
std.debug.print("Testing Evm...\n", .{});
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var db = database.InMemoryDB.init(allocator);
defer db.deinit();
const ctx = DefaultContext.new(db, primitives.SpecId.prague);
const evm = Evm.new(ctx, {}, {});
std.debug.assert(evm.ctx.block.number == @as(primitives.U256, 0));
std.debug.assert(evm.ctx.tx.tx_type == 0);
std.debug.assert(evm.ctx.cfg.spec == primitives.SpecId.prague);
std.debug.assert(evm.ctx.local.shared_memory_buffer == null);
std.debug.assert(evm.ctx.ctx_error == ContextError.ok);
std.debug.print("Evm tests passed.\n", .{});
}
};