mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
* WIP on build time configuration changes * add ssz_minimal tests * split up spec tests into mainnet and minimal, skip any minimal test that are failing without --define ssz=minimal * lint * add commentary to ssz_proto_library
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package spectest
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"gopkg.in/d4l3k/messagediff.v1"
|
|
)
|
|
|
|
const transferPrefix = "tests/operations/transfer/"
|
|
|
|
func runTransferTest(t *testing.T, filename string) {
|
|
file, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
t.Fatalf("Could not load file %v", err)
|
|
}
|
|
|
|
test := &BlockOperationTest{}
|
|
if err := testutil.UnmarshalYaml(file, test); err != nil {
|
|
t.Fatalf("Failed to Unmarshal: %v", err)
|
|
}
|
|
|
|
if err := spectest.SetConfig(test.Config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if len(test.TestCases) == 0 {
|
|
t.Fatal("No tests!")
|
|
}
|
|
|
|
for _, tt := range test.TestCases {
|
|
t.Run(tt.Description, func(t *testing.T) {
|
|
helpers.ClearAllCaches()
|
|
|
|
body := ðpb.BeaconBlockBody{Transfers: []*ethpb.Transfer{tt.Transfer}}
|
|
|
|
postState, err := blocks.ProcessTransfers(tt.Pre, body)
|
|
// Note: This doesn't test anything worthwhile. It essentially tests
|
|
// that *any* error has occurred, not any specific error.
|
|
if tt.Post == nil {
|
|
if err == nil {
|
|
t.Fatal("Did not fail when expected")
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !proto.Equal(postState, tt.Post) {
|
|
diff, _ := messagediff.PrettyDiff(postState, tt.Post)
|
|
t.Log(diff)
|
|
t.Fatal("Post state does not match expected")
|
|
}
|
|
})
|
|
}
|
|
}
|