From 23c3cbc5f6fb59220e2f07372001fcce34274515 Mon Sep 17 00:00:00 2001 From: mrekucci Date: Thu, 21 Sep 2023 19:54:12 +0800 Subject: [PATCH] feat: introduce min bucket depth --- .github/patches/postage_api.patch | 4 ++++ .github/workflows/beekeeper.yml | 1 + pkg/api/postage.go | 2 +- pkg/api/postage_test.go | 14 ++++++++++---- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .github/patches/postage_api.patch diff --git a/.github/patches/postage_api.patch b/.github/patches/postage_api.patch new file mode 100644 index 00000000000..6d85af4ae66 --- /dev/null +++ b/.github/patches/postage_api.patch @@ -0,0 +1,4 @@ +80c80 +< Depth uint8 `map:"depth" validate:"required,min=24"` +--- +> Depth uint8 `map:"depth" validate:"required"` diff --git a/.github/workflows/beekeeper.yml b/.github/workflows/beekeeper.yml index 1bb1379d131..01c83d3e233 100644 --- a/.github/workflows/beekeeper.yml +++ b/.github/workflows/beekeeper.yml @@ -69,6 +69,7 @@ jobs: run: | # patch pkg/postage/postagecontract/contract.go .github/patches/postagecontract.patch # patch pkg/postage/service.go .github/patches/postageservice.patch + patch pkg/api/postage.go .github/patches/postage_api.patch make binary mv dist/bee bee-1 - name: Apply patches and build - 2 diff --git a/pkg/api/postage.go b/pkg/api/postage.go index 7df275c29a7..c9c97b98bf3 100644 --- a/pkg/api/postage.go +++ b/pkg/api/postage.go @@ -77,7 +77,7 @@ func (s *Service) postageCreateHandler(w http.ResponseWriter, r *http.Request) { paths := struct { Amount *big.Int `map:"amount" validate:"required"` - Depth uint8 `map:"depth" validate:"required"` + Depth uint8 `map:"depth" validate:"required,min=24"` }{} if response := s.mapStructure(mux.Vars(r), &paths); response != nil { response("invalid path params", logger, w) diff --git a/pkg/api/postage_test.go b/pkg/api/postage_test.go index e55086117c5..5f35c73fe45 100644 --- a/pkg/api/postage_test.go +++ b/pkg/api/postage_test.go @@ -38,7 +38,7 @@ func TestPostageCreateStamp(t *testing.T) { batchID := []byte{1, 2, 3, 4} initialBalance := int64(1000) - depth := uint8(1) + depth := uint8(24) label := "label" txHash := common.HexToHash("0x1234") createBatch := func(amount int64, depth uint8, label string) string { @@ -139,7 +139,13 @@ func TestPostageCreateStamp(t *testing.T) { jsonhttptest.Request(t, ts, http.MethodPost, "/stamps/1000/9", http.StatusBadRequest, jsonhttptest.WithExpectedJSONResponse(&jsonhttp.StatusResponse{ Code: http.StatusBadRequest, - Message: "invalid depth", + Message: "invalid path params", + Reasons: []jsonhttp.Reason{ + { + Field: "depth", + Error: "want min:24", + }, + }, }), ) }) @@ -793,7 +799,7 @@ func TestPostageAccessHandler(t *testing.T) { { name: "create batch ok", method: http.MethodPost, - url: "/stamps/1000/17?label=test", + url: "/stamps/1000/24?label=test", respCode: http.StatusCreated, resp: &api.PostageCreateResponse{ BatchID: batchOk, @@ -826,7 +832,7 @@ func TestPostageAccessHandler(t *testing.T) { { name: "create batch not ok", method: http.MethodPost, - url: "/stamps/1000/17?label=test", + url: "/stamps/1000/24?label=test", respCode: http.StatusTooManyRequests, resp: &jsonhttp.StatusResponse{ Code: http.StatusTooManyRequests,