diff --git a/bindings/go/main_test.go b/bindings/go/main_test.go index 2360528..f16d734 100644 --- a/bindings/go/main_test.go +++ b/bindings/go/main_test.go @@ -121,7 +121,7 @@ var ( func TestBlobToKZGCommitment(t *testing.T) { type Test struct { Input struct { - Blob Blob `yaml:"blob"` + Blob string `yaml:"blob"` } Output *Bytes48 `yaml:"output"` } @@ -137,7 +137,14 @@ func TestBlobToKZGCommitment(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - commitment, ret := BlobToKZGCommitment(test.Input.Blob) + var blob Blob + err = blob.UnmarshalText([]byte(test.Input.Blob)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + commitment, ret := BlobToKZGCommitment(blob) if ret == C_KZG_OK { require.NotNil(t, test.Output) require.Equal(t, test.Output[:], commitment[:]) @@ -150,8 +157,8 @@ func TestBlobToKZGCommitment(t *testing.T) { func TestComputeKZGProof(t *testing.T) { type Test struct { Input struct { - Blob Blob `yaml:"blob"` - Z Bytes32 `yaml:"z"` + Blob string `yaml:"blob"` + Z string `yaml:"z"` } Output *[]string `yaml:"output"` } @@ -167,7 +174,21 @@ func TestComputeKZGProof(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - proof, y, ret := ComputeKZGProof(test.Input.Blob, test.Input.Z) + var blob Blob + err = blob.UnmarshalText([]byte(test.Input.Blob)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var z Bytes32 + err = z.UnmarshalText([]byte(test.Input.Z)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + proof, y, ret := ComputeKZGProof(blob, z) if ret == C_KZG_OK { require.NotNil(t, test.Output) var expectedProof Bytes48 @@ -187,8 +208,8 @@ func TestComputeKZGProof(t *testing.T) { func TestComputeBlobKZGProof(t *testing.T) { type Test struct { Input struct { - Blob Blob `yaml:"blob"` - Commitment Bytes48 `yaml:"commitment"` + Blob string `yaml:"blob"` + Commitment string `yaml:"commitment"` } Output *Bytes48 `yaml:"output"` } @@ -204,7 +225,21 @@ func TestComputeBlobKZGProof(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - proof, ret := ComputeBlobKZGProof(test.Input.Blob, test.Input.Commitment) + var blob Blob + err = blob.UnmarshalText([]byte(test.Input.Blob)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var commitment Bytes48 + err = commitment.UnmarshalText([]byte(test.Input.Commitment)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + proof, ret := ComputeBlobKZGProof(blob, commitment) if ret == C_KZG_OK { require.NotNil(t, test.Output) require.Equal(t, test.Output[:], proof[:]) @@ -217,10 +252,10 @@ func TestComputeBlobKZGProof(t *testing.T) { func TestVerifyKZGProof(t *testing.T) { type Test struct { Input struct { - Commitment Bytes48 `yaml:"commitment"` - Z Bytes32 `yaml:"z"` - Y Bytes32 `yaml:"y"` - Proof Bytes48 `yaml:"proof"` + Commitment string `yaml:"commitment"` + Z string `yaml:"z"` + Y string `yaml:"y"` + Proof string `yaml:"proof"` } Output *bool `yaml:"output"` } @@ -236,11 +271,35 @@ func TestVerifyKZGProof(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - valid, ret := VerifyKZGProof( - test.Input.Commitment, - test.Input.Z, - test.Input.Y, - test.Input.Proof) + var commitment Bytes48 + err = commitment.UnmarshalText([]byte(test.Input.Commitment)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var z Bytes32 + err = z.UnmarshalText([]byte(test.Input.Z)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var y Bytes32 + err = y.UnmarshalText([]byte(test.Input.Y)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var proof Bytes48 + err = proof.UnmarshalText([]byte(test.Input.Proof)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + valid, ret := VerifyKZGProof(commitment, z, y, proof) if ret == C_KZG_OK { require.NotNil(t, test.Output) require.Equal(t, *test.Output, valid) @@ -253,9 +312,9 @@ func TestVerifyKZGProof(t *testing.T) { func TestVerifyBlobKZGProof(t *testing.T) { type Test struct { Input struct { - Blob Blob `yaml:"blob"` - Commitment Bytes48 `yaml:"commitment"` - Proof Bytes48 `yaml:"proof"` + Blob string `yaml:"blob"` + Commitment string `yaml:"commitment"` + Proof string `yaml:"proof"` } Output *bool `yaml:"output"` } @@ -271,10 +330,28 @@ func TestVerifyBlobKZGProof(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - valid, ret := VerifyBlobKZGProof( - test.Input.Blob, - test.Input.Commitment, - test.Input.Proof) + var blob Blob + err = blob.UnmarshalText([]byte(test.Input.Blob)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var commitment Bytes48 + err = commitment.UnmarshalText([]byte(test.Input.Commitment)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + var proof Bytes48 + err = proof.UnmarshalText([]byte(test.Input.Proof)) + if err != nil { + require.Nil(t, test.Output) + continue + } + + valid, ret := VerifyBlobKZGProof(blob, commitment, proof) if ret == C_KZG_OK { require.NotNil(t, test.Output) require.Equal(t, *test.Output, valid) @@ -287,9 +364,9 @@ func TestVerifyBlobKZGProof(t *testing.T) { func TestVerifyBlobKZGProofBatch(t *testing.T) { type Test struct { Input struct { - Blobs []Blob `yaml:"blobs"` - Commitments []Bytes48 `yaml:"commitments"` - Proofs []Bytes48 `yaml:"proofs"` + Blobs []string `yaml:"blobs"` + Commitments []string `yaml:"commitments"` + Proofs []string `yaml:"proofs"` } Output *bool `yaml:"output"` } @@ -305,10 +382,40 @@ func TestVerifyBlobKZGProofBatch(t *testing.T) { require.NoError(t, testFile.Close()) require.NoError(t, err) - valid, ret := VerifyBlobKZGProofBatch( - test.Input.Blobs, - test.Input.Commitments, - test.Input.Proofs) + var blobs []Blob + for _, b := range test.Input.Blobs { + var blob Blob + err = blob.UnmarshalText([]byte(b)) + if err != nil { + require.Nil(t, test.Output) + continue + } + blobs = append(blobs, blob) + } + + var commitments []Bytes48 + for _, c := range test.Input.Commitments { + var commitment Bytes48 + err = commitment.UnmarshalText([]byte(c)) + if err != nil { + require.Nil(t, test.Output) + continue + } + commitments = append(commitments, commitment) + } + + var proofs []Bytes48 + for _, p := range test.Input.Proofs { + var proof Bytes48 + err = proof.UnmarshalText([]byte(p)) + if err != nil { + require.Nil(t, test.Output) + continue + } + proofs = append(proofs, proof) + } + + valid, ret := VerifyBlobKZGProofBatch(blobs, commitments, proofs) if ret == C_KZG_OK { require.NotNil(t, test.Output) require.Equal(t, *test.Output, valid)