-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GetGenesis in the beacon API (#8380)
* span * initial implementation * test wip * set nanos to zero * more testing * gzl
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
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
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,65 @@ | ||
package beaconv1 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
ptypes "github.com/gogo/protobuf/types" | ||
chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" | ||
"github.com/prysmaticlabs/prysm/shared/params" | ||
"github.com/prysmaticlabs/prysm/shared/testutil/assert" | ||
"github.com/prysmaticlabs/prysm/shared/testutil/require" | ||
) | ||
|
||
func TestGetGenesis(t *testing.T) { | ||
params.SetupTestConfigCleanup(t) | ||
config := params.BeaconConfig() | ||
config.GenesisForkVersion = []byte("genesis") | ||
params.OverrideBeaconConfig(config) | ||
genesis := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC) | ||
validatorsRoot := [32]byte{1, 2, 3, 4, 5, 6} | ||
|
||
t.Run("OK", func(t *testing.T) { | ||
chainService := &chainMock.ChainService{ | ||
Genesis: genesis, | ||
ValidatorsRoot: validatorsRoot, | ||
} | ||
s := Server{ | ||
GenesisTimeFetcher: chainService, | ||
ChainInfoFetcher: chainService, | ||
} | ||
resp, err := s.GetGenesis(context.Background(), &ptypes.Empty{}) | ||
require.NoError(t, err) | ||
assert.Equal(t, genesis.Unix(), resp.GenesisTime.Seconds) | ||
assert.Equal(t, int32(0), resp.GenesisTime.Nanos) | ||
assert.DeepEqual(t, validatorsRoot[:], resp.GenesisValidatorsRoot) | ||
assert.DeepEqual(t, []byte("genesis"), resp.GenesisForkVersion) | ||
}) | ||
|
||
t.Run("No genesis time", func(t *testing.T) { | ||
chainService := &chainMock.ChainService{ | ||
Genesis: time.Time{}, | ||
ValidatorsRoot: validatorsRoot, | ||
} | ||
s := Server{ | ||
GenesisTimeFetcher: chainService, | ||
ChainInfoFetcher: chainService, | ||
} | ||
_, err := s.GetGenesis(context.Background(), &ptypes.Empty{}) | ||
assert.ErrorContains(t, "Chain genesis info is not yet known", err) | ||
}) | ||
|
||
t.Run("No genesis validator root", func(t *testing.T) { | ||
chainService := &chainMock.ChainService{ | ||
Genesis: genesis, | ||
ValidatorsRoot: [32]byte{}, | ||
} | ||
s := Server{ | ||
GenesisTimeFetcher: chainService, | ||
ChainInfoFetcher: chainService, | ||
} | ||
_, err := s.GetGenesis(context.Background(), &ptypes.Empty{}) | ||
assert.ErrorContains(t, "Chain genesis info is not yet known", err) | ||
}) | ||
} |