Skip to content

Commit

Permalink
Merge pull request #2316 from brave-intl/master
Browse files Browse the repository at this point in the history
Production 2024-01-25_01
  • Loading branch information
clD11 authored Jan 25, 2024
2 parents 004509d + 2d2552a commit d7d487f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
6 changes: 3 additions & 3 deletions libs/custodian/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func contains(countries, allowblock []string) bool {
for _, ab := range allowblock {
for _, country := range countries {
if strings.EqualFold(ab, country) {
fmt.Println("contains ", ab, country)
return true
}
}
Expand All @@ -141,6 +140,7 @@ type Regions struct {
Gemini GeoAllowBlockMap `json:"gemini" valid:"-"`
Bitflyer GeoAllowBlockMap `json:"bitflyer" valid:"-"`
Zebpay GeoAllowBlockMap `json:"zebpay" valid:"-"`
Solana GeoAllowBlockMap `json:"solana" valid:"-"`
}

// HandleErrors - handle any errors in input
Expand All @@ -149,12 +149,12 @@ func (cr *Regions) HandleErrors(err error) *handlers.AppError {
}

// Decode - implement decodable
func (cr *Regions) Decode(ctx context.Context, input []byte) error {
func (cr *Regions) Decode(_ context.Context, input []byte) error {
return json.Unmarshal(input, cr)
}

// Validate - implement validatable
func (cr *Regions) Validate(ctx context.Context) error {
func (cr *Regions) Validate(_ context.Context) error {
isValid, err := govalidator.ValidateStruct(cr)
if err != nil {
return err
Expand Down
51 changes: 50 additions & 1 deletion libs/custodian/regions_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package custodian

import "testing"
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestVerdictAllowList(t *testing.T) {
gabm := GeoAllowBlockMap{
Expand All @@ -27,3 +33,46 @@ func TestVerdictBlockList(t *testing.T) {
t.Error("should have been false, US in block list")
}
}

func TestRegions_Decode(t *testing.T) {
type tcGiven struct {
input []byte
}

type exp struct {
allow []string
block []string
}

type testCase struct {
name string
given tcGiven
exp exp
}

testCases := []testCase{
{
name: "solana",
given: tcGiven{
input: []byte(`{"solana":{"allow":["AA"],"block":["AB"]}}`),
},
exp: exp{
allow: []string{"AA"},
block: []string{"AB"},
},
},
}

for i := range testCases {
tc := testCases[i]

t.Run(tc.name, func(t *testing.T) {
regions := Regions{}
err := regions.Decode(context.Background(), tc.given.input)
require.NoError(t, err)

assert.Equal(t, tc.exp.allow, regions.Solana.Allow)
assert.Equal(t, tc.exp.block, regions.Solana.Block)
})
}
}
2 changes: 1 addition & 1 deletion schema/rewards/ParametersV1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/ParametersV1","definitions":{"AutoContribute":{"properties":{"choices":{"items":{"type":"number"},"type":"array"},"defaultChoice":{"type":"number"}},"additionalProperties":false,"type":"object"},"GeoAllowBlockMap":{"required":["allow","block"],"properties":{"allow":{"items":{"type":"string"},"type":"array"},"block":{"items":{"type":"string"},"type":"array"}},"additionalProperties":false,"type":"object"},"ParametersV1":{"required":["payoutStatus","custodianRegions","vbatExpired"],"properties":{"payoutStatus":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/PayoutStatus"},"custodianRegions":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/Regions"},"batRate":{"type":"number"},"autocontribute":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/AutoContribute"},"tips":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/Tips"},"vbatExpired":{"type":"boolean"},"vbatDeadline":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object"},"PayoutStatus":{"required":["unverified","uphold","gemini","bitflyer","zebpay","payoutDate"],"properties":{"unverified":{"type":"string"},"uphold":{"type":"string"},"gemini":{"type":"string"},"bitflyer":{"type":"string"},"zebpay":{"type":"string"},"payoutDate":{"type":"string"}},"additionalProperties":false,"type":"object"},"Regions":{"required":["uphold","gemini","bitflyer","zebpay"],"properties":{"uphold":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/GeoAllowBlockMap"},"gemini":{"$ref":"#/definitions/GeoAllowBlockMap"},"bitflyer":{"$ref":"#/definitions/GeoAllowBlockMap"},"zebpay":{"$ref":"#/definitions/GeoAllowBlockMap"}},"additionalProperties":false,"type":"object"},"Tips":{"properties":{"defaultTipChoices":{"items":{"type":"number"},"type":"array"},"defaultMonthlyChoices":{"items":{"type":"number"},"type":"array"}},"additionalProperties":false,"type":"object"}}}
{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/ParametersV1","definitions":{"AutoContribute":{"properties":{"choices":{"items":{"type":"number"},"type":"array"},"defaultChoice":{"type":"number"}},"additionalProperties":false,"type":"object"},"GeoAllowBlockMap":{"required":["allow","block"],"properties":{"allow":{"items":{"type":"string"},"type":"array"},"block":{"items":{"type":"string"},"type":"array"}},"additionalProperties":false,"type":"object"},"ParametersV1":{"required":["payoutStatus","custodianRegions","vbatExpired"],"properties":{"payoutStatus":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/PayoutStatus"},"custodianRegions":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/Regions"},"batRate":{"type":"number"},"autocontribute":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/AutoContribute"},"tips":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/Tips"},"vbatExpired":{"type":"boolean"},"vbatDeadline":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object"},"PayoutStatus":{"required":["unverified","uphold","gemini","bitflyer","zebpay","payoutDate"],"properties":{"unverified":{"type":"string"},"uphold":{"type":"string"},"gemini":{"type":"string"},"bitflyer":{"type":"string"},"zebpay":{"type":"string"},"payoutDate":{"type":"string"}},"additionalProperties":false,"type":"object"},"Regions":{"required":["uphold","gemini","bitflyer","zebpay","solana"],"properties":{"uphold":{"$schema":"http://json-schema.org/draft-04/schema#","$ref":"#/definitions/GeoAllowBlockMap"},"gemini":{"$ref":"#/definitions/GeoAllowBlockMap"},"bitflyer":{"$ref":"#/definitions/GeoAllowBlockMap"},"zebpay":{"$ref":"#/definitions/GeoAllowBlockMap"},"solana":{"$ref":"#/definitions/GeoAllowBlockMap"}},"additionalProperties":false,"type":"object"},"Tips":{"properties":{"defaultTipChoices":{"items":{"type":"number"},"type":"array"},"defaultMonthlyChoices":{"items":{"type":"number"},"type":"array"}},"additionalProperties":false,"type":"object"}}}

0 comments on commit d7d487f

Please sign in to comment.