From 6a85d83bc1b471cbfe7432c4d78400d4a5b25c75 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 3 Nov 2022 17:58:51 +0100 Subject: [PATCH 1/2] chore: adding test utility for generating embedded test data, creating README --- share/eds/eds_test.go | 37 ++++++++++++++++++++++++++++++++++++ share/eds/testdata/README.md | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 share/eds/testdata/README.md diff --git a/share/eds/eds_test.go b/share/eds/eds_test.go index 659888c85f..303dd4b509 100644 --- a/share/eds/eds_test.go +++ b/share/eds/eds_test.go @@ -230,3 +230,40 @@ func openWrittenEDS(t *testing.T) *os.File { require.NoError(t, err, "error opening file") return f } + +/* +use this function as needed to create new test data. + +example: + + func Test_CreateData(t *testing.T) { + createTestData(t, "celestia-node/share/eds/testdata") + } +*/ +func createTestData(t *testing.T, testDir string) { //nolint:unused + t.Helper() + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + err := os.Chdir(testDir) + require.NoError(t, err, "changing to the directory") + os.RemoveAll("example.car") + require.NoError(t, err, "removing old file") + f, err := os.OpenFile("example.car", os.O_WRONLY|os.O_CREATE, 0600) + require.NoError(t, err, "opening file") + + eds := share.RandEDS(t, 4) + err = WriteEDS(ctx, eds, f) + require.NoError(t, err, "writing EDS to file") + f.Close() + dah := da.NewDataAvailabilityHeader(eds) + + header, err := json.MarshalIndent(dah, "", "") + require.NoError(t, err, "marshaling example root") + os.RemoveAll("example-root.json") + require.NoError(t, err, "removing old file") + f, err = os.OpenFile("example-root.json", os.O_WRONLY|os.O_CREATE, 0600) + require.NoError(t, err, "opening file") + _, err = f.Write(header) + require.NoError(t, err, "writing example root to file") + f.Close() +} diff --git a/share/eds/testdata/README.md b/share/eds/testdata/README.md new file mode 100644 index 0000000000..8ca5329783 --- /dev/null +++ b/share/eds/testdata/README.md @@ -0,0 +1,3 @@ +This directory contains an example CARv1 file of an EDS and its matching data availability header. + +They might need to be regenerated when modifying constants such as the default share size. This can be done by running the test utility in `eds_test.go` called `createTestData`. \ No newline at end of file From 5c9161fba2df5fb83275f61d01912489d9bb96dd Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 3 Nov 2022 18:07:46 +0100 Subject: [PATCH 2/2] chore: adding readme --- share/eds/testdata/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/share/eds/testdata/README.md b/share/eds/testdata/README.md index 8ca5329783..960549e2a0 100644 --- a/share/eds/testdata/README.md +++ b/share/eds/testdata/README.md @@ -1,3 +1,5 @@ +# CARxEDS Testdata + This directory contains an example CARv1 file of an EDS and its matching data availability header. -They might need to be regenerated when modifying constants such as the default share size. This can be done by running the test utility in `eds_test.go` called `createTestData`. \ No newline at end of file +They might need to be regenerated when modifying constants such as the default share size. This can be done by running the test utility in `eds_test.go` called `createTestData`.