-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compose: add vouch to compose (#1814)
Adds vouch to compose and also made some changes to beaconmock which were needed by vouch specifically. Note: Vouch doesn't support block proposals because of RANDAO check in go-eth2-client. category: feature ticket: #1403
- Loading branch information
Showing
11 changed files
with
335 additions
and
15 deletions.
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
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,123 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package beaconmock_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/r3labs/sse/v2" | ||
"github.com/stretchr/testify/require" | ||
"gopkg.in/cenkalti/backoff.v1" | ||
|
||
"github.com/obolnetwork/charon/app/errors" | ||
"github.com/obolnetwork/charon/testutil/beaconmock" | ||
) | ||
|
||
func TestHeadProducer(t *testing.T) { | ||
bmock, err := beaconmock.New() | ||
require.NoError(t, err) | ||
|
||
defer bmock.Close() | ||
|
||
base, err := url.Parse(bmock.Address()) | ||
require.NoError(t, err) | ||
|
||
unsupportedTopicErr := errors.New("unknown topic requested") | ||
|
||
tests := []struct { | ||
name string | ||
topics []string | ||
statusCode int | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "2 supported topics requested", | ||
topics: []string{"head", "block"}, | ||
statusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "head topic", | ||
topics: []string{"head"}, | ||
statusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "block topic", | ||
topics: []string{"block"}, | ||
statusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "unsupported topic", | ||
topics: []string{"exit"}, | ||
statusCode: http.StatusInternalServerError, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
endpoint, err := url.Parse(fmt.Sprintf("eth/v1/events?topics=%s", strings.Join(test.topics, "&topics="))) | ||
require.NoError(t, err) | ||
|
||
addr := base.ResolveReference(endpoint).String() | ||
|
||
requiredTopics := make(map[string]bool) | ||
for _, topic := range test.topics { | ||
requiredTopics[topic] = true | ||
} | ||
|
||
client := sse.NewClient(addr, func(c *sse.Client) { | ||
c.ResponseValidator = func(c *sse.Client, resp *http.Response) error { | ||
require.Equal(t, test.statusCode, resp.StatusCode) | ||
|
||
if resp.StatusCode == http.StatusInternalServerError { | ||
data, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.Contains(t, string(data), "unknown topic") | ||
|
||
return backoff.Permanent(unsupportedTopicErr) | ||
} | ||
|
||
if len(requiredTopics) == 0 { | ||
return backoff.Permanent(nil) | ||
} | ||
|
||
return nil | ||
} | ||
}) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
if test.expectErr { | ||
require.ErrorIs(t, client.SubscribeWithContext(ctx, addr, func(msg *sse.Event) {}), unsupportedTopicErr) | ||
} else { | ||
require.NoError(t, client.SubscribeWithContext(ctx, addr, func(msg *sse.Event) { | ||
require.True(t, requiredTopics[string(msg.Event)]) | ||
delete(requiredTopics, string(msg.Event)) | ||
if len(requiredTopics) == 0 { | ||
cancel() | ||
} | ||
})) | ||
} | ||
}) | ||
} | ||
} |
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
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,9 @@ | ||
FROM wealdtech/ethdo:1.25.3 as ethdo | ||
|
||
FROM attestant/vouch:1.6.2 | ||
|
||
COPY --from=ethdo /app/ethdo /app/ethdo | ||
|
||
RUN apt-get update && apt-get install -y curl jq wget | ||
|
||
ENTRYPOINT ["/compose/vouch/run.sh"] |
Oops, something went wrong.