Fix Fork Copying (#4922)

* add fix and reg test

* goimports
This commit is contained in:
Nishant Das 2020-02-21 21:49:42 +08:00 committed by GitHub
parent 597b21c40a
commit 47bb927029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -46,5 +46,6 @@ go_test(
"//shared/stateutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)

View File

@ -135,8 +135,8 @@ func (b *BeaconState) Fork() *pbp2p.Fork {
prevVersion := make([]byte, len(b.state.Fork.PreviousVersion))
copy(prevVersion, b.state.Fork.PreviousVersion)
currVersion := make([]byte, len(b.state.Fork.PreviousVersion))
copy(currVersion, b.state.Fork.PreviousVersion)
currVersion := make([]byte, len(b.state.Fork.CurrentVersion))
copy(currVersion, b.state.Fork.CurrentVersion)
return &pbp2p.Fork{
PreviousVersion: prevVersion,
CurrentVersion: currVersion,

View File

@ -7,6 +7,7 @@ import (
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@ -226,3 +227,24 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
t.Fatal("Expected a.BlockRoots() to be different from b.BlockRoots()")
}
}
func TestForkManualCopy_OK(t *testing.T) {
params.UseMinimalConfig()
genesis := setupGenesisState(t, 64)
a, err := stateTrie.InitializeFromProto(genesis)
if err != nil {
t.Fatal(err)
}
wantedFork := &pb.Fork{
PreviousVersion: []byte{'a', 'b', 'c'},
CurrentVersion: []byte{'d', 'e', 'f'},
Epoch: 0,
}
a.SetFork(wantedFork)
newState := a.CloneInnerState()
if !ssz.DeepEqual(newState.Fork, wantedFork) {
t.Errorf("Wanted %v but got %v", wantedFork, newState.Fork)
}
}