Skip to content

Commit

Permalink
Use standard mechanism for spec tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jul 6, 2023
1 parent 2ba62f6 commit 6b1fb2f
Show file tree
Hide file tree
Showing 31 changed files with 743 additions and 1,354 deletions.
49 changes: 0 additions & 49 deletions spec/altair/beaconblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ package altair_test
import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/goccy/go-yaml"
"github.com/golang/snappy"
"github.com/stretchr/testify/assert"
require "github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -180,48 +176,3 @@ func TestBeaconBlockYAML(t *testing.T) {
})
}
}

func TestBeaconBlockSpec(t *testing.T) {
if os.Getenv("ETH2_SPEC_TESTS_DIR") == "" {
t.Skip("ETH2_SPEC_TESTS_DIR not suppplied, not running spec tests")
}
baseDir := filepath.Join(os.Getenv("ETH2_SPEC_TESTS_DIR"), "tests", "mainnet", "altair", "ssz_static", "BeaconBlock", "ssz_random")
require.NoError(t, filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
if path == baseDir {
// Only interested in subdirectories.
return nil
}
require.NoError(t, err)
if info.IsDir() {
t.Run(info.Name(), func(t *testing.T) {
specYAML, err := os.ReadFile(filepath.Join(path, "value.yaml"))
require.NoError(t, err)
var res altair.BeaconBlock
require.NoError(t, yaml.Unmarshal(specYAML, &res))

compressedSpecSSZ, err := os.ReadFile(filepath.Join(path, "serialized.ssz_snappy"))
require.NoError(t, err)
var specSSZ []byte
specSSZ, err = snappy.Decode(specSSZ, compressedSpecSSZ)
require.NoError(t, err)

unmarshalled := &altair.BeaconBlock{}
require.NoError(t, unmarshalled.UnmarshalSSZ(specSSZ))
remarshalled, err := unmarshalled.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, specSSZ, remarshalled)

ssz, err := res.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, specSSZ, ssz)

root, err := res.HashTreeRoot()
require.NoError(t, err)
rootsYAML, err := os.ReadFile(filepath.Join(path, "roots.yaml"))
require.NoError(t, err)
require.Equal(t, string(rootsYAML), fmt.Sprintf("{root: '%#x'}\n", root))
})
}
return nil
}))
}
49 changes: 0 additions & 49 deletions spec/altair/beaconblockbody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ package altair_test
import (
"bytes"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/goccy/go-yaml"
"github.com/golang/snappy"
"github.com/stretchr/testify/assert"
require "github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -235,48 +231,3 @@ func TestBeaconBlockBodyYAML(t *testing.T) {
})
}
}

func TestBeaconBlockBodySpec(t *testing.T) {
if os.Getenv("ETH2_SPEC_TESTS_DIR") == "" {
t.Skip("ETH2_SPEC_TESTS_DIR not suppplied, not running spec tests")
}
baseDir := filepath.Join(os.Getenv("ETH2_SPEC_TESTS_DIR"), "tests", "mainnet", "altair", "ssz_static", "BeaconBlockBody", "ssz_random")
require.NoError(t, filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
if path == baseDir {
// Only interested in subdirectories.
return nil
}
require.NoError(t, err)
if info.IsDir() {
t.Run(info.Name(), func(t *testing.T) {
specYAML, err := os.ReadFile(filepath.Join(path, "value.yaml"))
require.NoError(t, err)
var res altair.BeaconBlockBody
require.NoError(t, yaml.Unmarshal(specYAML, &res))

compressedSpecSSZ, err := os.ReadFile(filepath.Join(path, "serialized.ssz_snappy"))
require.NoError(t, err)
var specSSZ []byte
specSSZ, err = snappy.Decode(specSSZ, compressedSpecSSZ)
require.NoError(t, err)

unmarshalled := &altair.BeaconBlockBody{}
require.NoError(t, unmarshalled.UnmarshalSSZ(specSSZ))
remarshalled, err := unmarshalled.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, specSSZ, remarshalled)

ssz, err := res.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, specSSZ, ssz)

root, err := res.HashTreeRoot()
require.NoError(t, err)
rootsYAML, err := os.ReadFile(filepath.Join(path, "roots.yaml"))
require.NoError(t, err)
require.Equal(t, string(rootsYAML), fmt.Sprintf("{root: '%#x'}\n", root))
})
}
return nil
}))
}
71 changes: 0 additions & 71 deletions spec/altair/beaconstate_test.go

This file was deleted.

Loading

0 comments on commit 6b1fb2f

Please sign in to comment.