2020-07-16 22:44:43 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2021-07-21 21:34:07 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
2020-07-16 22:44:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestService_TreeHandler(t *testing.T) {
|
|
|
|
req, err := http.NewRequest("GET", "/tree", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2021-09-23 18:53:46 +00:00
|
|
|
headState, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2020-07-16 22:44:43 +00:00
|
|
|
require.NoError(t, headState.SetBalances([]uint64{params.BeaconConfig().GweiPerEth}))
|
2021-11-19 15:59:26 +00:00
|
|
|
fcs := protoarray.New(
|
|
|
|
0, // justifiedEpoch
|
|
|
|
0, // finalizedEpoch
|
|
|
|
[32]byte{'a'},
|
|
|
|
)
|
|
|
|
opts := []Option{
|
|
|
|
WithDatabase(beaconDB),
|
|
|
|
WithStateGen(stategen.New(beaconDB)),
|
|
|
|
WithForkChoiceStore(fcs),
|
2020-07-16 22:44:43 +00:00
|
|
|
}
|
2021-11-19 15:59:26 +00:00
|
|
|
s, err := NewService(ctx, opts...)
|
2020-10-01 18:53:36 +00:00
|
|
|
require.NoError(t, err)
|
2021-03-17 18:36:56 +00:00
|
|
|
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 0, [32]byte{'a'}, [32]byte{'g'}, [32]byte{'c'}, 0, 0))
|
|
|
|
require.NoError(t, s.cfg.ForkChoiceStore.ProcessBlock(ctx, 1, [32]byte{'b'}, [32]byte{'a'}, [32]byte{'c'}, 0, 0))
|
2021-09-23 18:53:46 +00:00
|
|
|
s.setHead([32]byte{'a'}, wrapper.WrappedPhase0SignedBeaconBlock(util.NewBeaconBlock()), headState)
|
2020-07-16 22:44:43 +00:00
|
|
|
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
handler := http.HandlerFunc(s.TreeHandler)
|
|
|
|
|
|
|
|
handler.ServeHTTP(rr, req)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, rr.Code)
|
|
|
|
}
|