Skip to content

Commit

Permalink
added getCellDst test with negative offset
Browse files Browse the repository at this point in the history
  • Loading branch information
mmk-1 committed Sep 20, 2023
1 parent 696d38d commit c000240
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion pkg/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package vm
import (
"testing"

"github.com/stretchr/testify/require"
f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

mem "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory"
)
Expand Down Expand Up @@ -80,6 +80,51 @@ func TestGetCellFpDst(t *testing.T) {
assert.Equal(t, mem.MemoryValueFromInt(123), cell.Read())
}

func TestGetCellDstApNegativeOffset(t *testing.T) {
vm := defaultVirtualMachine()

const (
offDest = -2
ap = 12
)
vm.Context.Ap = ap

writeToDataSegment(vm, ap+offDest, mem.MemoryValueFromInt(100))

instruction := Instruction{
OffDest: offDest,
DstRegister: Ap,
}

cell, err := vm.getCellDst(&instruction)

require.NoError(t, err)
assert.True(t, cell.Accessed)
assert.Equal(t, mem.MemoryValueFromInt(100), cell.Read())
}

func TestGetCellDstFpNegativeOffset(t *testing.T) {
vm := defaultVirtualMachine()

const (
offDest = -19
fp = 33
)
vm.Context.Fp = fp

writeToDataSegment(vm, fp+offDest, mem.MemoryValueFromInt(100))

instruction := Instruction{
OffDest: offDest,
DstRegister: Fp,
}

cell, err := vm.getCellDst(&instruction)
require.NoError(t, err)
assert.True(t, cell.Accessed)
assert.Equal(t, mem.MemoryValueFromInt(100), cell.Read())
}

func TestGetApCellOp0(t *testing.T) {
vm := defaultVirtualMachine()

Expand Down

0 comments on commit c000240

Please sign in to comment.