Skip to content

Commit

Permalink
fix(api): add api initialization notice (#4869)
Browse files Browse the repository at this point in the history
  • Loading branch information
gacevicljubisa authored Oct 29, 2024
1 parent 13fc473 commit f5ba590
Show file tree
Hide file tree
Showing 7 changed files with 633 additions and 178 deletions.
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type Service struct {
ethereumAddress common.Address
chequebookEnabled bool
swapEnabled bool
fullAPIEnabled bool

topologyDriver topology.Driver
p2p p2p.DebugService
Expand Down
23 changes: 13 additions & 10 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ type testServerOptions struct {
NodeStatus *status.Service
PinIntegrity api.PinIntegrity
WhitelistedAddr string
FullAPIDisabled bool
ChequebookDisabled bool
SwapDisabled bool
}

func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.Conn, string, *chanStorer) {
Expand Down Expand Up @@ -179,7 +182,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
erc20 := erc20mock.New(o.Erc20Opts...)
backend := backendmock.New(o.BackendOpts...)

var extraOpts = api.ExtraOptions{
extraOpts := api.ExtraOptions{
TopologyDriver: topologyDriver,
Accounting: acc,
Pseudosettle: recipient,
Expand Down Expand Up @@ -207,7 +210,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
o.BeeMode = api.FullMode
}

s := api.New(o.PublicKey, o.PSSPublicKey, o.EthereumAddress, []string{o.WhitelistedAddr}, o.Logger, transaction, o.BatchStore, o.BeeMode, true, true, backend, o.CORSAllowedOrigins, inmemstore.New())
s := api.New(o.PublicKey, o.PSSPublicKey, o.EthereumAddress, []string{o.WhitelistedAddr}, o.Logger, transaction, o.BatchStore, o.BeeMode, !o.ChequebookDisabled, !o.SwapDisabled, backend, o.CORSAllowedOrigins, inmemstore.New())
testutil.CleanupCloser(t, s)

s.SetP2P(o.P2P)
Expand All @@ -231,9 +234,10 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
WsPingPeriod: o.WsPingPeriod,
}, extraOpts, 1, erc20)

s.MountTechnicalDebug()
s.MountDebug()
s.MountAPI()
s.Mount()
if !o.FullAPIDisabled {
s.EnableFullAPI()
}

if o.DirectUpload {
chanStore = newChanStore(o.Storer.PusherFeed())
Expand Down Expand Up @@ -316,7 +320,7 @@ func TestParseName(t *testing.T) {
const bzzHash = "89c17d0d8018a19057314aa035e61c9d23c47581a61dd3a79a7839692c617e4d"
log := log.Noop

var errInvalidNameOrAddress = errors.New("invalid name or bzz address")
errInvalidNameOrAddress := errors.New("invalid name or bzz address")

testCases := []struct {
desc string
Expand Down Expand Up @@ -377,7 +381,8 @@ func TestParseName(t *testing.T) {

s := api.New(pk.PublicKey, pk.PublicKey, common.Address{}, nil, log, nil, nil, 1, false, false, nil, []string{"*"}, inmemstore.New())
s.Configure(signer, nil, api.Options{}, api.ExtraOptions{Resolver: tC.res}, 1, nil)
s.MountAPI()
s.Mount()
s.EnableFullAPI()

tC := tC
t.Run(tC.desc, func(t *testing.T) {
Expand Down Expand Up @@ -503,9 +508,7 @@ func TestPostageHeaderError(t *testing.T) {
func TestOptions(t *testing.T) {
t.Parallel()

var (
client, _, _, _ = newTestServer(t, testServerOptions{})
)
client, _, _, _ := newTestServer(t, testServerOptions{})
for _, tc := range []struct {
endpoint string
expectedMethods string // expectedMethods contains HTTP methods like GET, POST, HEAD, PATCH, DELETE, OPTIONS. These are in alphabetical sorted order
Expand Down
Loading

0 comments on commit f5ba590

Please sign in to comment.