forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated update of test vectors (0xPolygonHermez#456)
* Automate test-vector update * run update action on PR to test * remove gh action testing * Fix apply tx in e2e tests * refactor getTargetPath and log entries * fix typo * run tests on pushes to update-external-dependencies branch
- Loading branch information
Showing
34 changed files
with
1,677 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
- main | ||
- master | ||
- develop | ||
- update-external-dependencies | ||
pull_request: | ||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
- main | ||
- master | ||
- develop | ||
- update-external-dependencies | ||
pull_request: | ||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
/dist/ | ||
/test/e2e/keystore | ||
/test/e2e/keystore | ||
|
||
/test/vectors/src/**/*md | ||
/test/vectors/src/**/*js | ||
/test/vectors/src/**/*sol | ||
/test/vectors/src/**/*sh | ||
/test/vectors/src/package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dependencies | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/hermeznetwork/hermez-core/log" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
func updateFiles(fs afero.Fs, sourceDir, targetDir string) error { | ||
const bufferSize = 20 | ||
err := afero.Walk(fs, targetDir, func(wpath string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info == nil || info.IsDir() { | ||
return nil | ||
} | ||
relativePath := strings.Replace(wpath, targetDir, "", -1) | ||
sourcePath := path.Join(sourceDir, relativePath) | ||
|
||
sourceFile, err := fs.Open(sourcePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err := sourceFile.Close(); err != nil { | ||
log.Errorf("Could not close %s: %v", sourceFile.Name(), err) | ||
} | ||
}() | ||
destinationFile, err := fs.OpenFile(wpath, os.O_RDWR, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err := destinationFile.Close(); err != nil { | ||
log.Errorf("Could not close %s: %v", destinationFile.Name(), err) | ||
} | ||
}() | ||
buf := make([]byte, bufferSize) | ||
for { | ||
n, err := sourceFile.Read(buf) | ||
if err != nil && err != io.EOF { | ||
return err | ||
} | ||
if n == 0 { | ||
break | ||
} | ||
if _, err := destinationFile.Write(buf[:n]); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}) | ||
return err | ||
} | ||
|
||
func getTargetPath(targetPath string) string { | ||
if strings.HasPrefix(targetPath, "/") { | ||
return targetPath | ||
} | ||
_, filename, _, _ := runtime.Caller(1) | ||
|
||
return path.Join(path.Dir(filename), targetPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package dependencies | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hermeznetwork/hermez-core/log" | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_updateFiles(t *testing.T) { | ||
const ( | ||
defaultTargetDir = "/a/b/src" | ||
defaultSourceDir = "/tmp/src" | ||
) | ||
|
||
var appFs = afero.NewMemMapFs() | ||
|
||
tcs := []struct { | ||
description string | ||
initialSourceFiles map[string]string | ||
initialTargetFiles map[string]string | ||
expectedTargetFiles map[string]string | ||
}{ | ||
{ | ||
description: "single file matching file", | ||
initialSourceFiles: map[string]string{ | ||
"/tmp/src/a": "new-a-content", | ||
}, | ||
initialTargetFiles: map[string]string{ | ||
"/a/b/src/a": "old-a-content", | ||
}, | ||
expectedTargetFiles: map[string]string{ | ||
"/a/b/src/a": "new-a-content", | ||
}, | ||
}, | ||
{ | ||
description: "single file matching file with non-matching files", | ||
initialSourceFiles: map[string]string{ | ||
"/tmp/src/a": "new-a-content", | ||
"/tmp/src/b": "new-b-content", | ||
}, | ||
initialTargetFiles: map[string]string{ | ||
"/a/b/src/a": "old-a-content", | ||
}, | ||
expectedTargetFiles: map[string]string{ | ||
"/a/b/src/a": "new-a-content", | ||
}, | ||
}, | ||
{ | ||
description: "multiple matching files", | ||
initialSourceFiles: map[string]string{ | ||
"/tmp/src/a.json": "new-a-content", | ||
"/tmp/src/subdir1/subdir2/b.json": "new-b-content", | ||
}, | ||
initialTargetFiles: map[string]string{ | ||
"/a/b/src/a.json": "old-a-content", | ||
"/a/b/src/subdir1/subdir2/b.json": "old-b-content", | ||
}, | ||
expectedTargetFiles: map[string]string{ | ||
"/a/b/src/a.json": "new-a-content", | ||
"/a/b/src/subdir1/subdir2/b.json": "new-b-content", | ||
}, | ||
}, | ||
{ | ||
description: "multiple matching files with non matching files", | ||
initialSourceFiles: map[string]string{ | ||
"/tmp/src/subdira1/a.json": "new-a-content", | ||
"/tmp/src/subdirb1/subdirb2/b.json": "new-b-content", | ||
"/tmp/src/c.json": "new-c-content", | ||
}, | ||
initialTargetFiles: map[string]string{ | ||
"/a/b/src/subdira1/a.json": "old-a-content", | ||
"/a/b/src/subdir1/subdir2/b.json": "old-b-content", | ||
}, | ||
expectedTargetFiles: map[string]string{ | ||
"/a/b/src/subdira1/a.json": "new-a-content", | ||
"/a/b/src/subdir1/subdir2/b.json": "new-b-content", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
tc := tc | ||
t.Run(tc.description, func(t *testing.T) { | ||
require.NoError(t, createTestFiles(appFs, tc.initialSourceFiles)) | ||
require.NoError(t, createTestFiles(appFs, tc.initialTargetFiles)) | ||
|
||
require.NoError(t, updateFiles(appFs, defaultSourceDir, defaultTargetDir)) | ||
a := afero.Afero{Fs: appFs} | ||
for path, expectedContent := range tc.expectedTargetFiles { | ||
actualContent, err := a.ReadFile(path) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedContent, string(actualContent)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func createTestFiles(appFs afero.Fs, files map[string]string) error { | ||
for path, content := range files { | ||
f, err := appFs.Create(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
if err := f.Close(); err != nil { | ||
log.Errorf("Could not close %s: %v", f.Name(), err) | ||
} | ||
}() | ||
_, err = f.WriteString(content) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.