a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package languages
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestNoirExtractor_Basics(t *testing.T) {
|
|
src := []byte(`use dep::std::hash::pedersen;
|
|
use dep::aztec::context;
|
|
|
|
struct Proof {
|
|
nullifier: Field,
|
|
}
|
|
|
|
trait Verifier {
|
|
fn verify(self: Self, p: Proof) -> bool;
|
|
}
|
|
|
|
impl Proof {
|
|
fn new() -> Self {
|
|
Self { nullifier: 0 }
|
|
}
|
|
}
|
|
|
|
fn main(secret: Field) -> pub Field {
|
|
pedersen([secret])
|
|
}
|
|
`)
|
|
e := NewNoirExtractor()
|
|
require.Equal(t, "noir", e.Language())
|
|
|
|
res, err := e.Extract("main.nr", src)
|
|
require.NoError(t, err)
|
|
|
|
var gotProof, gotVerifier, gotImpl, gotMain bool
|
|
for _, n := range res.Nodes {
|
|
switch n.Name {
|
|
case "Proof":
|
|
gotProof = true
|
|
case "Verifier":
|
|
gotVerifier = true
|
|
case "main":
|
|
gotMain = true
|
|
}
|
|
if n.Name == "Proof" && n.Kind == graph.KindType {
|
|
gotImpl = true
|
|
}
|
|
}
|
|
var gotImport bool
|
|
for _, ed := range res.Edges {
|
|
if ed.Kind == graph.EdgeImports && ed.To == "unresolved::import::dep::std::hash::pedersen" {
|
|
gotImport = true
|
|
}
|
|
}
|
|
assert.True(t, gotProof)
|
|
assert.True(t, gotVerifier)
|
|
assert.True(t, gotImpl)
|
|
assert.True(t, gotMain)
|
|
assert.True(t, gotImport)
|
|
}
|
|
|
|
func TestNoirExtractor_EmptyInput(t *testing.T) {
|
|
res, err := NewNoirExtractor().Extract("e.nr", []byte(""))
|
|
require.NoError(t, err)
|
|
require.Len(t, res.Nodes, 1)
|
|
assert.Equal(t, graph.KindFile, res.Nodes[0].Kind)
|
|
}
|