Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into generic-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Jun 22, 2023
2 parents 025be8d + f5ad6a5 commit c4244a0
Show file tree
Hide file tree
Showing 25 changed files with 519 additions and 298 deletions.
111 changes: 53 additions & 58 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ slack-fail-stop-step: &slack-fail-post-step
# ===== Workflow Definitions =====
workflows:
version: 2
"circleci_build_and_test":
nightly_build_and_test:
jobs:
- build_nightly:
name: << matrix.platform >>_build_nightly
Expand All @@ -94,19 +94,6 @@ workflows:
context: slack-secrets
<<: *slack-fail-post-step

- test:
name: << matrix.platform >>_test
matrix: &matrix-default
parameters:
platform: ["amd64", "arm64"]
filters: &filters-default
branches:
ignore:
- /rel\/.*/
- << pipeline.parameters.valid_nightly_branch >>
context: slack-secrets
<<: *slack-fail-post-step

- test_nightly:
name: << matrix.platform >>_test_nightly
matrix:
Expand All @@ -116,15 +103,6 @@ workflows:
context: slack-secrets
<<: *slack-fail-post-step

- integration:
name: << matrix.platform >>_integration
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- integration_nightly:
name: << matrix.platform >>_integration_nightly
matrix:
Expand All @@ -134,15 +112,6 @@ workflows:
context: slack-secrets
<<: *slack-fail-post-step

- e2e_expect:
name: << matrix.platform >>_e2e_expect
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- e2e_expect_nightly:
name: << matrix.platform >>_e2e_expect_nightly
matrix:
Expand All @@ -152,15 +121,6 @@ workflows:
context: slack-secrets
<<: *slack-fail-post-step

- e2e_subs:
name: << matrix.platform >>_e2e_subs
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- e2e_subs_nightly:
name: << matrix.platform >>_e2e_subs_nightly
matrix:
Expand All @@ -172,17 +132,6 @@ workflows:
- aws-secrets
<<: *slack-fail-post-step

- tests_verification_job:
name: << matrix.platform >>_<< matrix.job_type >>_verification
matrix:
parameters:
platform: ["amd64", "arm64"]
job_type: ["test", "integration", "e2e_expect"]
requires:
- << matrix.platform >>_<< matrix.job_type >>
context: slack-secrets
<<: *slack-fail-post-step

- tests_verification_job_nightly:
name: << matrix.platform >>_<< matrix.job_type >>_verification
matrix:
Expand All @@ -203,17 +152,63 @@ workflows:
- << matrix.platform >>_integration_nightly_verification
- << matrix.platform >>_e2e_expect_nightly_verification
- << matrix.platform >>_e2e_subs_nightly
filters:
branches:
only:
- /rel\/.*/
- << pipeline.parameters.valid_nightly_branch >>
context:
- slack-secrets
- aws-secrets
<<: *slack-fail-post-step

#- windows_x64_build
"circleci_build_and_test":
jobs:
- test:
name: << matrix.platform >>_test
matrix: &matrix-default
parameters:
platform: ["amd64"]
filters: &filters-default
branches:
ignore:
- /rel\/.*/
- << pipeline.parameters.valid_nightly_branch >>
context: slack-secrets
<<: *slack-fail-post-step

- integration:
name: << matrix.platform >>_integration
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- e2e_expect:
name: << matrix.platform >>_e2e_expect
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- e2e_subs:
name: << matrix.platform >>_e2e_subs
matrix:
<<: *matrix-default
filters:
<<: *filters-default
context: slack-secrets
<<: *slack-fail-post-step

- tests_verification_job:
name: << matrix.platform >>_<< matrix.job_type >>_verification
matrix:
parameters:
platform: ["amd64"]
job_type: ["test", "integration", "e2e_expect"]
requires:
- << matrix.platform >>_<< matrix.job_type >>
context: slack-secrets
<<: *slack-fail-post-step

# ===== Job Definitions =====
jobs:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ALWAYS:
# build our fork of libsodium, placing artifacts into crypto/lib/ and crypto/include/
crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a:
mkdir -p crypto/copies/$(OS_TYPE)/$(ARCH)
cp -R crypto/libsodium-fork crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork
cp -R crypto/libsodium-fork/. crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork
cd crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork && \
./autogen.sh --prefix $(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH) && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH)" && \
Expand Down
4 changes: 2 additions & 2 deletions config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const VersionMajor = 3

// VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced.
// Not enforced until after initial public release (x > 0).
const VersionMinor = 16
const VersionMinor = 17

// Version is the type holding our full version information.
type Version struct {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (v Version) AsUInt64() (versionInfo uint64) {
versionInfo = uint64(v.Major)
versionInfo <<= 16
versionInfo |= uint64(v.Minor)
versionInfo <<= 16
versionInfo <<= 24
versionInfo |= uint64(v.BuildNumber)
return
}
Expand Down
60 changes: 60 additions & 0 deletions config/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package config

import (
"fmt"
"testing"

"github.com/algorand/go-algorand/test/partitiontest"
"github.com/algorand/go-algorand/util/s3"
"github.com/stretchr/testify/require"
)

func TestAlgodVsUpdatedVersions(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

tests := []struct {
major int
minor int
build int
}{
{major: 1, minor: 1, build: 32111},
{major: 2, minor: 0, build: 0},
{major: 3, minor: 13, build: 170018},
{major: 3, minor: 15, build: 157},
{major: 3, minor: 16, build: 0},
{major: 3, minor: 16, build: 100},
}

for _, tt := range tests {
t.Run(fmt.Sprintf("%d.%d.%d", tt.major, tt.minor, tt.build), func(t *testing.T) {
version := Version{Major: tt.major, Minor: tt.minor, BuildNumber: tt.build}
str := version.String()
ver, err := s3.GetVersionFromName("_" + str)
require.NoError(t, err)
require.Equal(t, version.AsUInt64(), ver)
major, minor, patch, err := s3.GetVersionPartsFromVersion(ver)
require.NoError(t, err)
require.Equal(t, uint64(tt.major), major)
require.Equal(t, uint64(tt.minor), minor)
require.Equal(t, uint64(tt.build), patch)

})
}
}
32 changes: 18 additions & 14 deletions daemon/algod/api/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const (
apiV1Tag = "/v1"
// TokenHeader is the header where we put the token.
TokenHeader = "X-Algo-API-Token"
// maxRequestBodyBytes is the maximum request body size that we allow in our APIs.
maxRequestBodyBytes = "10MB"
// MaxRequestBodyBytes is the maximum request body size that we allow in our APIs.
MaxRequestBodyBytes = "10MB"
)

// wrapCtx passes a common context to each request without a global variable.
Expand All @@ -79,8 +79,13 @@ func NewRouter(logger logging.Logger, node APINodeInterface, shutdown <-chan str
if err := tokens.ValidateAPIToken(adminAPIToken); err != nil {
logger.Errorf("Invalid adminAPIToken was passed to NewRouter ('%s'): %v", adminAPIToken, err)
}
adminAuthenticator := middlewares.MakeAuth(TokenHeader, []string{adminAPIToken})
apiAuthenticator := middlewares.MakeAuth(TokenHeader, []string{adminAPIToken, apiToken})
adminMiddleware := []echo.MiddlewareFunc{
middlewares.MakeAuth(TokenHeader, []string{adminAPIToken}),
}
publicMiddleware := []echo.MiddlewareFunc{
middleware.BodyLimit(MaxRequestBodyBytes),
middlewares.MakeAuth(TokenHeader, []string{adminAPIToken, apiToken}),
}

e := echo.New()

Expand All @@ -93,7 +98,6 @@ func NewRouter(logger logging.Logger, node APINodeInterface, shutdown <-chan str
e.Use(
middlewares.MakeLogger(logger),
middlewares.MakeCORS(TokenHeader),
middleware.BodyLimit(maxRequestBodyBytes),
)

// Request Context
Expand All @@ -104,32 +108,32 @@ func NewRouter(logger logging.Logger, node APINodeInterface, shutdown <-chan str
// Route pprof requests to DefaultServeMux.
// The auth middleware removes /urlAuth/:token so that it can be routed correctly.
if node.Config().EnableProfiler {
e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux), adminAuthenticator)
e.GET(fmt.Sprintf("%s/debug/pprof/*", middlewares.URLAuthPrefix), echo.WrapHandler(http.DefaultServeMux), adminAuthenticator)
e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux), adminMiddleware...)
e.GET(fmt.Sprintf("%s/debug/pprof/*", middlewares.URLAuthPrefix), echo.WrapHandler(http.DefaultServeMux), adminMiddleware...)
}
// Registering common routes (no auth)
registerHandlers(e, "", common.Routes, ctx)

// Registering v1 routes
registerHandlers(e, apiV1Tag, routes.V1Routes, ctx, apiAuthenticator)
registerHandlers(e, apiV1Tag, routes.V1Routes, ctx, publicMiddleware...)

// Registering v2 routes
v2Handler := v2.Handlers{
Node: node,
Log: logger,
Shutdown: shutdown,
}
nppublic.RegisterHandlers(e, &v2Handler, apiAuthenticator)
npprivate.RegisterHandlers(e, &v2Handler, adminAuthenticator)
ppublic.RegisterHandlers(e, &v2Handler, apiAuthenticator)
pprivate.RegisterHandlers(e, &v2Handler, adminAuthenticator)
nppublic.RegisterHandlers(e, &v2Handler, publicMiddleware...)
npprivate.RegisterHandlers(e, &v2Handler, adminMiddleware...)
ppublic.RegisterHandlers(e, &v2Handler, publicMiddleware...)
pprivate.RegisterHandlers(e, &v2Handler, adminMiddleware...)

if node.Config().EnableFollowMode {
data.RegisterHandlers(e, &v2Handler, apiAuthenticator)
data.RegisterHandlers(e, &v2Handler, publicMiddleware...)
}

if node.Config().EnableExperimentalAPI {
experimental.RegisterHandlers(e, &v2Handler, apiAuthenticator)
experimental.RegisterHandlers(e, &v2Handler, publicMiddleware...)
}

return e
Expand Down
37 changes: 14 additions & 23 deletions daemon/algod/api/server/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ import (

"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"

"github.com/algorand/go-algorand/daemon/algod/api/server/lib"
"github.com/algorand/go-algorand/daemon/algod/api/server/v1/routes"

"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/test/partitiontest"
)

type TestSuite struct {
suite.Suite
e *echo.Echo
}

func (s *TestSuite) SetupSuite() {
s.e = echo.New()
func setupRouter() *echo.Echo {
e := echo.New()
// Make a deep copy of the routes array with handlers.
v1RoutesCopy := make([]lib.Route, len(routes.V1Routes))
for _, route := range routes.V1Routes {
Expand All @@ -51,10 +44,13 @@ func (s *TestSuite) SetupSuite() {
// Make a ReqContext with an initialized logger to prevent nil dereferencing.
reqCtx := lib.ReqContext{Log: logging.NewLogger()}
// Registering v1 routes
registerHandlers(s.e, apiV1Tag, v1RoutesCopy, reqCtx)
registerHandlers(e, apiV1Tag, v1RoutesCopy, reqCtx)
return e
}

func (s *TestSuite) TestGetTransactionV1Sunset() {
func TestGetTransactionV1Sunset(t *testing.T) {
partitiontest.PartitionTest(t)

testCases := []struct {
path string
route string
Expand All @@ -67,21 +63,16 @@ func (s *TestSuite) TestGetTransactionV1Sunset() {
}

rec := httptest.NewRecorder()
ctx := s.e.NewContext(nil, rec)
e := setupRouter()
ctx := e.NewContext(nil, rec)

for _, testCase := range testCases {
s.e.Router().Find(http.MethodGet, testCase.path, ctx)
assert.Equal(s.T(), testCase.route, ctx.Path())
e.Router().Find(http.MethodGet, testCase.path, ctx)
assert.Equal(t, testCase.route, ctx.Path())

// Check that router correctly routes to the v1Sunset handler.
assert.Equal(s.T(), nil, ctx.Handler()(ctx))
assert.NotNil(s.T(), rec.Body)
assert.Equal(s.T(), http.StatusGone, rec.Code)
assert.Equal(t, nil, ctx.Handler()(ctx))
assert.NotNil(t, rec.Body)
assert.Equal(t, http.StatusGone, rec.Code)
}

}

func TestTestSuite(t *testing.T) {
partitiontest.PartitionTest(t)
suite.Run(t, new(TestSuite))
}

0 comments on commit c4244a0

Please sign in to comment.