feat: add test for sync method

This commit is contained in:
fearlseefe 2024-04-12 13:14:38 +08:00 committed by Chen Kai
parent 0cc10d5436
commit 9077ad49dd
2 changed files with 23 additions and 0 deletions

View file

@ -101,6 +101,14 @@ func NewConsensusLightClient(api ConsensusAPI, config *Config, checkpointBlockRo
return client, nil
}
func (c *ConsensusLightClient) GetHeader() *common.BeaconBlockHeader {
return c.Store.OptimisticHeader
}
func (c *ConsensusLightClient) GetFinalityHeader() *common.BeaconBlockHeader {
return c.Store.FinalizedHeader
}
func (c *ConsensusLightClient) Sync() error {
err := c.bootstrap()
if err != nil {

View file

@ -78,6 +78,7 @@ func getClient(strictCheckpointAge bool, t *testing.T) (*ConsensusLightClient, e
Chain: baseConfig.Chain,
Spec: baseConfig.Spec,
StrictCheckpointAge: strictCheckpointAge,
MaxCheckpointAge: 123123123,
}
checkpoint := common.Root(hexutil.MustDecode("0xc62aa0de55e6f21230fa63713715e1a6c13e73005e89f6389da271955d819bde"))
@ -161,3 +162,17 @@ func TestVerifyOptimisticUpdate(t *testing.T) {
err = client.VerifyOptimisticUpdate(update)
require.Error(t, err)
}
func TestSync(t *testing.T) {
client, err := getClient(false, t)
require.NoError(t, err)
err = client.Sync()
require.NoError(t, err)
header := client.GetHeader()
require.Equal(t, header.Slot, common.Slot(7358726))
finalizedHead := client.GetFinalityHeader()
require.Equal(t, finalizedHead.Slot, common.Slot(7358656))
}