Skip to content

Commit

Permalink
Fix the unit tests, uncomment pythonVm execution in integration tests…
Browse files Browse the repository at this point in the history
…, code cleanups
  • Loading branch information
MaksymMalicki committed Dec 28, 2024
1 parent af47a3d commit 73f6dd5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 55 deletions.
80 changes: 35 additions & 45 deletions integration_tests/cairo_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str
}
layout := getLayoutFromFileName(path)

_, traceFile, memoryFile, _, err := runVm(compiledOutput, layout, zero)
elapsedGo, traceFile, memoryFile, _, err := runVm(compiledOutput, layout, zero)
if errorExpected {
assert.Error(t, err, path)
writeToFile(path)
Expand All @@ -92,7 +92,7 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str
if zero {
rustVmFilePath = compiledOutput
}
_, rsTraceFile, rsMemoryFile, err := runRustVm(rustVmFilePath, layout, zero)
elapsedRs, rsTraceFile, rsMemoryFile, err := runRustVm(rustVmFilePath, layout, zero)
if errorExpected {
// we let the code go on so that we can check if the go vm also raises an error
assert.Error(t, err, path)
Expand Down Expand Up @@ -129,49 +129,39 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str
writeToFile(path)
}

// if zero {
// elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(compiledOutput, layout)
// if errorExpected {
// // we let the code go on so that we can check if the go vm also raises an error
// assert.Error(t, err, path)
// } else {
// if err != nil {
// t.Error(err)
// return
// }
// }

// if benchmark {
// benchmarkMap[name] = [3]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds()), int(elapsedRs.Milliseconds())}
// }

// pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile)
// if err != nil {
// t.Error(err)
// return
// }

// if !assert.Equal(t, pyTrace, rsTrace) {
// t.Logf("pytrace:\n%s\n", traceRepr(pyTrace))
// t.Logf("rstrace:\n%s\n", traceRepr(rsTrace))
// writeToFile(path)
// }
// if !assert.Equal(t, pyMemory, rsMemory) {
// t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory))
// t.Logf("rsmemory;\n%s\n", memoryRepr(rsMemory))
// writeToFile(path)
// }
// if !assert.Equal(t, pyTrace, trace) {
// t.Logf("pytrace:\n%s\n", traceRepr(pyTrace))
// t.Logf("trace:\n%s\n", traceRepr(trace))
// writeToFile(path)
// }
// if !assert.Equal(t, pyMemory, memory) {
// t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory))
// t.Logf("memory;\n%s\n", memoryRepr(memory))
// writeToFile(path)
// }
// }
if zero {
elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(compiledOutput, layout)
if errorExpected {
// we let the code go on so that we can check if the go vm also raises an error
assert.Error(t, err, path)
} else {
if err != nil {
t.Error(err)
return
}
}

if benchmark {
benchmarkMap[name] = [3]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds()), int(elapsedRs.Milliseconds())}
}

pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile)
if err != nil {
t.Error(err)
return
}

if !assert.Equal(t, pyTrace, trace) {
t.Logf("pytrace:\n%s\n", traceRepr(pyTrace))
t.Logf("trace:\n%s\n", traceRepr(trace))
writeToFile(path)
}
if !assert.Equal(t, pyMemory, memory) {
t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory))
t.Logf("memory;\n%s\n", memoryRepr(memory))
writeToFile(path)
}
}
}

var zerobench = flag.Bool("zerobench", false, "run integration tests and generate benchmarks file")
Expand Down
9 changes: 1 addition & 8 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (runner *Runner) initializeMainEntrypoint() (mem.MemoryAddress, error) {
return runner.initializeEntrypoint(mainPCOffset, nil, &mvReturnFp, memory, stack, 0)
}
case ProofModeZero:
fmt.Println("program: ", runner.program.Labels)
initialPCOffset, ok := runner.program.Labels["__start__"]
if !ok {
return mem.UnknownAddress,
Expand Down Expand Up @@ -295,7 +296,6 @@ func (runner *Runner) initializeVm(
return err
}
}
fmt.Println("offset", offset, "stackSize", stackSize, "cairo1FpOffset", cairo1FpOffset)
initialFp := offset + uint64(len(stack)) + cairo1FpOffset
var err error
// initialize vm
Expand All @@ -313,11 +313,6 @@ func (runner *Runner) initializeVm(
// run until the program counter equals the `pc` parameter
func (runner *Runner) RunUntilPc(pc *mem.MemoryAddress) error {
for !runner.vm.Context.Pc.Equal(pc) {
fmt.Println("pc", runner.pc(), "ap", runner.vm.Context.Ap, "fp", runner.vm.Context.Fp)
// if runner.steps() == 4 {
// runner.vm.PrintMemory()
// }
// runner.vm.PrintMemory()
if runner.steps() >= runner.maxsteps {
return fmt.Errorf(
"pc %s step %d: max step limit exceeded (%d)",
Expand Down Expand Up @@ -554,7 +549,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo
usedArgs := 0
var hints map[uint64][]hinter.Hinter
for _, builtin := range function.Builtins {
fmt.Println("builtin", builtin, builtin == builtins.GasBuiltinType)
if offset, isBuiltin := builtinsOffsetsMap[builtin]; isBuiltin {
ctx.AddInlineCASM(
fmt.Sprintf("[ap + 0] = [fp - %d], ap++;", offset),
Expand All @@ -575,7 +569,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo
)
apOffset += 1
} else if builtin == builtins.GasBuiltinType {
fmt.Println("builtin == builtins.GasBuiltinType")
hints = map[uint64][]hinter.Hinter{
uint64(ctx.currentCodeOffset): {
&core.ExternalWriteArgsToMemory{},
Expand Down
3 changes: 1 addition & 2 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ func TestModuloBuiltin(t *testing.T) {

func createRunner(code string, layoutName string, builtins ...builtins.BuiltinType) Runner {
program := createProgramWithBuiltins(code, builtins...)

hints := make(map[uint64][]hinter.Hinter)
runner, err := NewRunner(program, hints, ProofModeZero, false, math.MaxUint64, layoutName, nil)
runner, err := NewRunner(program, hints, ExecutionModeZero, false, math.MaxUint64, layoutName, nil)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 73f6dd5

Please sign in to comment.