Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Jul 4, 2024
1 parent 58dd608 commit d1dd8f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/engine_api/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ test "deserialize sample engine_newPayloadV2" {
const AccountState = lib.state.AccountState;
const BlockHeader = lib.blockchain.BlockHeader;
const Hash32 = lib.types.Hash32;
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();

const fileContent = @embedFile("./test_req.json");

const payload = try json.parseFromSlice(EngineAPIRequest, std.testing.allocator, fileContent, .{ .ignore_unknown_fields = true });
const payload = try json.parseFromSlice(EngineAPIRequest, arena.allocator(), fileContent, .{ .ignore_unknown_fields = true });
defer payload.deinit();

var statedb = try StateDB.init(std.testing.allocator, &[0]AccountState{});
var statedb = try StateDB.init(arena.allocator(), &[0]AccountState{});
defer statedb.deinit();
const parent_header = BlockHeader{
.parent_hash = [_]u8{0} ** 32,
Expand All @@ -118,11 +120,11 @@ test "deserialize sample engine_newPayloadV2" {
.base_fee_per_gas = 7,
.withdrawals_root = [_]u8{0} ** 32,
};
var blockchain = try Blockchain.init(std.testing.allocator, .Testing, &statedb, parent_header, [_]Hash32{[_]u8{0} ** 32} ** 256);
var blockchain = try Blockchain.init(arena.allocator(), .Testing, &statedb, parent_header, [_]Hash32{[_]u8{0} ** 32} ** 256);

try expect(std.mem.eql(u8, payload.value.method, "engine_newPayloadV2"));
const execution_payload_json = payload.value.params[0];
var ep = try execution_payload_json.to_execution_payload(std.testing.allocator);
defer ep.deinit(std.testing.allocator);
var ep = try execution_payload_json.to_execution_payload(arena.allocator());
defer ep.deinit(arena.allocator());
try execution_payload.newPayloadV2Handler(&blockchain, &ep);
}
4 changes: 2 additions & 2 deletions src/engine_api/execution_payload.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub const ExecutionPayload = struct {
.timestamp = @intCast(self.timestamp),
.extra_data = self.extraData,
.base_fee_per_gas = self.baseFeePerGas,
.transactions_root = [_]u8{0} ** 32,
.transactions_root = lib.mpt.empty_mpt_root,
.nonce = [_]u8{0} ** 8,
.withdrawals_root = [_]u8{0} ** 32,
.withdrawals_root = lib.mpt.empty_mpt_root,
},
.transactions = self.transactions,
.withdrawals = self.withdrawals,
Expand Down
2 changes: 1 addition & 1 deletion src/engine_api/test_req.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"method": "engine_newPayloadV2",
"params": [
{
"parentHash": "0x522930864dc2f6569f4d4b92f40001fe6752727ff53db5cb5c5ffd51d3cc53e4",
"parentHash": "0xf725aca23ac424e82c9e75b78915bc533a4d4be2ced7c57f0f5885c5ac8e03d5",
"feeRecipient": "0xf97e180c050e5ab072211ad2c213eb5aee4df134",
"stateRoot": "0x27bb13dc19c41288dd29236b27baac49338c466b8c0eb44fb4c0c0083dfb214a",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
Expand Down
2 changes: 1 addition & 1 deletion src/mpt/mpt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = @import("../common/common.zig");
const Allocator = std.mem.Allocator;
const Hash32 = types.Hash32;

const empty_mpt_root = common.comptimeHexToBytes("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
pub const empty_mpt_root = common.comptimeHexToBytes("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");

// KeyVal represents an element in the Merkle Patricia Trie.
pub const KeyVal = struct {
Expand Down

0 comments on commit d1dd8f1

Please sign in to comment.