Skip to content

Commit

Permalink
feat: use the GenericError for all the errors originating from the …
Browse files Browse the repository at this point in the history
…agglayer (#227)

* chore: update the versions.json

* Remove PPError interface and use the error instead

* Remove non-applicable test cases

* Rename

* test: increase UT coverage

* test: certificate status unmarshal json

* test: TestMerkleProofString

* test: TestGlobalIndexString

* test: move helper functions to a separate file

* test: TestL1InfoTreeLeafString

* test: TestClaimType

* test: parallel execution, renames
  • Loading branch information
Stefan-Ethernal committed Dec 9, 2024
1 parent 306acbd commit 27139e6
Show file tree
Hide file tree
Showing 22 changed files with 869 additions and 1,563 deletions.
2 changes: 1 addition & 1 deletion agglayer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestGetLatestKnownCertificateHeaderWithPrevLERResponse(t *testing.T) {
response := rpc.Response{
Result: []byte(`{"network_id":1,"height":0,"epoch_number":223,"certificate_index":0,"certificate_id":"0xf9179d2fbe535814b5a14496e2eed474f49c6131227a9dfc5d2d8caf9e212054","prev_local_exit_root":"0x27ae5ba08d7291c96c8cbddcc148bf48a6d68c7974b94356f53754ef6171d757","new_local_exit_root":"0x7ae06f4a5d0b6da7dd4973fb6ef40d82c9f2680899b3baaf9e564413b59cc160","metadata":"0x00000000000000000000000000000000000000000000000000000000000001a7","status":"Settled"}`),
}
jSONRPCCall = func(url, method string, params ...interface{}) (rpc.Response, error) {
jSONRPCCall = func(_, _ string, _ ...interface{}) (rpc.Response, error) {
return response, nil
}
cert, err := sut.GetLatestKnownCertificateHeader(1)
Expand Down
45 changes: 0 additions & 45 deletions agglayer/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
package agglayer

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestErrorVectors(t *testing.T) {
t.Parallel()

type testCase struct {
TestName string `json:"test_name"`
ExpectedError string `json:"expected_error"`
CertificateHeaderJSON string `json:"certificate_header"`
}

files, err := filepath.Glob("testdata/*/*.json")
require.NoError(t, err)

for _, file := range files {
file := file

t.Run(file, func(t *testing.T) {
t.Parallel()

data, err := os.ReadFile(file)
require.NoError(t, err)

var testCases []*testCase

require.NoError(t, json.Unmarshal(data, &testCases))

for _, tc := range testCases {
certificateHeader := &CertificateHeader{}
err = json.Unmarshal([]byte(tc.CertificateHeaderJSON), certificateHeader)

if tc.ExpectedError == "" {
require.NoError(t, err, "Test: %s not expected any unmarshal error, but got: %v", tc.TestName, err)
require.NotNil(t, certificateHeader.Error, "Test: %s unpacked error is nil", tc.TestName)
fmt.Println(certificateHeader.Error.String())
} else {
require.ErrorContains(t, err, tc.ExpectedError, "Test: %s expected error: %s. Got: %v", tc.TestName, tc.ExpectedError, err)
}
}
})
}
}

func TestConvertMapValue_String(t *testing.T) {
t.Parallel()

Expand Down
Loading

0 comments on commit 27139e6

Please sign in to comment.