Skip to content

Commit

Permalink
Refactor error messages to lowercase and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesserc committed Nov 11, 2023
1 parent 20c40d9 commit a97ec5d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions pkg/vm/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Memory struct {
Data map[Relocatable]MaybeRelocatable
numSegments uint
validationRules map[uint]ValidationRule
validatedAdresses AddressSet
validatedAddresses AddressSet
// This is a map of addresses that were accessed during execution
// The map is of the form `segmentIndex` -> `offset`. This is to
// make the counting of memory holes easier
Expand All @@ -67,7 +67,7 @@ func InsufficientAllocatedCellsErrorMinStepNotReached(minStep uint, builtinName
func NewMemory() *Memory {
return &Memory{
Data: make(map[Relocatable]MaybeRelocatable),
validatedAdresses: NewAddressSet(),
validatedAddresses: NewAddressSet(),
validationRules: make(map[uint]ValidationRule),
AccessedAddresses: make(map[Relocatable]bool),
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (m *Memory) AddValidationRule(SegmentIndex uint, rule ValidationRule) {
// Applies the validation rule for the addr's segment if any
// Skips validation if the address is temporary or if it has been previously validated
func (m *Memory) validateAddress(addr Relocatable) error {
if addr.SegmentIndex < 0 || m.validatedAdresses.Contains(addr) {
if addr.SegmentIndex < 0 || m.validatedAddresses.Contains(addr) {
return nil
}
rule, ok := m.validationRules[uint(addr.SegmentIndex)]
Expand All @@ -183,7 +183,7 @@ func (m *Memory) validateAddress(addr Relocatable) error {
return err
}
for _, validated_address := range validated_addresses {
m.validatedAdresses.Add(validated_address)
m.validatedAddresses.Add(validated_address)
}
return nil
}
Expand All @@ -192,7 +192,7 @@ func (m *Memory) MarkAsAccessed(address Relocatable) {
m.AccessedAddresses[address] = true
}

// Applies validation_rules to every memory address, if applicatble
// Applies validation_rules to every memory address, if applicable
// Skips validation if the address is temporary or if it has been previously validated
func (m *Memory) ValidateExistingMemory() error {
for addr := range m.Data {
Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestMemoryInsertOverWriteValue(t *testing.T) {
val2 := memory.NewMaybeRelocatableFelt(lambdaworks.FeltFromUint64(8))
err2 := mem.Insert(key, val2)
if err2 == nil {
t.Errorf("Overwritting memory value should fail")
t.Errorf("Overwriting memory value should fail")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/memory/relocatable.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *Relocatable) IsEqual(r1 *Relocatable) bool {

func (relocatable *Relocatable) SubUint(other uint) (Relocatable, error) {
if relocatable.Offset < other {
return NewRelocatable(0, 0), &SubReloctableError{Msg: "RelocatableSubUsizeNegOffset"}
return NewRelocatable(0, 0), &SubRelocatableError{Msg: "RelocatableSubUsizeNegOffset"}
} else {
new_offset := relocatable.Offset - other
return NewRelocatable(relocatable.SegmentIndex, new_offset), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/vm/memory/relocatable_err.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package memory

type SubReloctableError struct {
type SubRelocatableError struct {
Msg string
}

func (e *SubReloctableError) Error() string {
func (e *SubRelocatableError) Error() string {
return e.Msg
}
4 changes: 2 additions & 2 deletions pkg/vm/memory/relocatable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestRelocatableIsEqual(t *testing.T) {

is_equal := a.IsEqual(&b)
if !is_equal {
t.Errorf("TestRelocatableIsEqual failed epected true, got %v", is_equal)
t.Errorf("TestRelocatableIsEqual failed expected true, got %v", is_equal)
}

}
Expand All @@ -101,7 +101,7 @@ func TestRelocatableIsNotEqual(t *testing.T) {

is_equal := a.IsEqual(&b)
if is_equal {
t.Errorf("TestRelocatableIsNotEqual failed epected false, got %v", is_equal)
t.Errorf("TestRelocatableIsNotEqual failed expected false, got %v", is_equal)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/memory/segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,5 @@ func (m *MemorySegmentManager) GenArg(arg any) (MaybeRelocatable, error) {
_, err := m.LoadData(base, &args)
return *NewMaybeRelocatableRelocatable(base), err
}
return *NewMaybeRelocatableFelt(lambdaworks.FeltZero()), errors.New("GenArg: found argument of invalid type.")
return *NewMaybeRelocatableFelt(lambdaworks.FeltZero()), errors.New("GenArg: found argument of invalid type")
}
12 changes: 6 additions & 6 deletions pkg/vm/memory/segments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ func TestGenArgMaybeRelocatable(t *testing.T) {
segments := memory.NewMemorySegmentManager()
arg := any(*memory.NewMaybeRelocatableFelt(lambdaworks.FeltZero()))
expectedArg := *memory.NewMaybeRelocatableFelt(lambdaworks.FeltZero())
genedArg, err := segments.GenArg(arg)
if err != nil || !reflect.DeepEqual(expectedArg, genedArg) {
generatedArgs, err := segments.GenArg(arg)
if err != nil || !reflect.DeepEqual(expectedArg, generatedArgs) {
t.Error("GenArg failed or returned wrong value")
}
}
Expand All @@ -327,8 +327,8 @@ func TestGenArgSliceMaybeRelocatable(t *testing.T) {

expectedBase := memory.NewRelocatable(0, 0)
expectedArg := *memory.NewMaybeRelocatableRelocatable(expectedBase)
genedArg, err := segments.GenArg(arg)
if err != nil || !reflect.DeepEqual(expectedArg, genedArg) {
generatedArgs, err := segments.GenArg(arg)
if err != nil || !reflect.DeepEqual(expectedArg, generatedArgs) {
t.Error("GenArg failed or returned wrong value")
}
val, err := segments.Memory.GetFelt(expectedBase)
Expand All @@ -344,9 +344,9 @@ func TestGenArgSliceSliceMaybeRelocatable(t *testing.T) {
expectedBaseA := memory.NewRelocatable(1, 0)
expectedBaseB := memory.NewRelocatable(0, 0)
expectedArg := *memory.NewMaybeRelocatableRelocatable(expectedBaseA)
genedArg, err := segments.GenArg(arg)
generatedArgs, err := segments.GenArg(arg)

if err != nil || !reflect.DeepEqual(expectedArg, genedArg) {
if err != nil || !reflect.DeepEqual(expectedArg, generatedArgs) {
t.Error("GenArg failed or returned wrong value")
}
valA, err := segments.Memory.GetRelocatable(expectedBaseA)
Expand Down

0 comments on commit a97ec5d

Please sign in to comment.