Skip to content

Commit

Permalink
refactor: use setUpMemory function to set up memory (keep-starknet-…
Browse files Browse the repository at this point in the history
…strange#171)

* use setUpMemory in unit tests

* update cli hash

---------

Co-authored-by: lanaivina <31368580+lana-shanghai@users.noreply.github.com>
  • Loading branch information
tcoratger and lana-shanghai authored Nov 21, 2023
1 parent 7ab841a commit d043ccf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
46 changes: 23 additions & 23 deletions src/vm/memory/memory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -655,16 +655,15 @@ test "memory set and get" {
const value_2 = relocatable.fromFelt(starknet_felt.Felt252.one());

// Set a value into the memory.
_ = try memory.set(
std.testing.allocator,
address_1,
value_1,
);
_ = try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
address_2,
value_2,
.{
.{ .{ 0, 0 }, .{1} },
.{ .{ -1, 0 }, .{1} },
},
);

defer memory.deinitData(std.testing.allocator);

// Get the value from the memory.
Expand Down Expand Up @@ -734,11 +733,12 @@ test "validate existing memory for range check within bound" {
const value_1 = relocatable.fromFelt(starknet_felt.Felt252.one());

// Set a value into the memory.
_ = try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
address_1,
value_1,
.{.{ .{ 0, 0 }, .{1} }},
);

defer memory.deinitData(std.testing.allocator);

// Get the value from the memory.
Expand Down Expand Up @@ -768,10 +768,10 @@ test "Memory: getFelt should return Felt252 if available at the given address" {
var memory = try Memory.init(std.testing.allocator);
defer memory.deinit();

try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
Relocatable.new(10, 30),
.{ .felt = Felt252.fromInteger(23) },
.{.{ .{ 10, 30 }, .{23} }},
);
defer memory.deinitData(std.testing.allocator);

Expand All @@ -787,10 +787,10 @@ test "Memory: getFelt should return ExpectedInteger error if Relocatable instead
var memory = try Memory.init(std.testing.allocator);
defer memory.deinit();

try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
Relocatable.new(10, 30),
.{ .relocatable = Relocatable.new(3, 7) },
.{.{ .{ 10, 30 }, .{ 3, 7 } }},
);
defer memory.deinitData(std.testing.allocator);

Expand Down Expand Up @@ -818,10 +818,10 @@ test "Memory: getRelocatable should return Relocatable if available at the given
var memory = try Memory.init(std.testing.allocator);
defer memory.deinit();

try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
Relocatable.new(10, 30),
.{ .relocatable = Relocatable.new(4, 34) },
.{.{ .{ 10, 30 }, .{ 4, 34 } }},
);
defer memory.deinitData(std.testing.allocator);

Expand All @@ -837,10 +837,10 @@ test "Memory: getRelocatable should return ExpectedRelocatable error if Felt ins
var memory = try Memory.init(std.testing.allocator);
defer memory.deinit();

try memory.set(
try setUpMemory(
memory,
std.testing.allocator,
Relocatable.new(10, 30),
.{ .felt = Felt252.fromInteger(3) },
.{.{ .{ 10, 30 }, .{3} }},
);
defer memory.deinitData(std.testing.allocator);

Expand Down
10 changes: 8 additions & 2 deletions src/vm/memory/segments.zig
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,14 @@ test "set get integer value in segment memory" {

const value_2 = relocatable.fromFelt(Felt252.fromInteger(84));

_ = try memory_segment_manager.memory.set(std.testing.allocator, address_1, value_1);
_ = try memory_segment_manager.memory.set(std.testing.allocator, address_2, value_2);
try memoryFile.setUpMemory(
memory_segment_manager.memory,
std.testing.allocator,
.{
.{ .{ 0, 0 }, .{42} },
.{ .{ -1, 0 }, .{84} },
},
);
defer memory_segment_manager.memory.deinitData(std.testing.allocator);

// ************************************************************
Expand Down

0 comments on commit d043ccf

Please sign in to comment.