diff --git a/libs/custodian/regions.go b/libs/custodian/regions.go index 8fb7dc0fb..130ab58af 100644 --- a/libs/custodian/regions.go +++ b/libs/custodian/regions.go @@ -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 } } @@ -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 @@ -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 diff --git a/libs/custodian/regions_test.go b/libs/custodian/regions_test.go index 0b2889cce..1975b0c47 100644 --- a/libs/custodian/regions_test.go +++ b/libs/custodian/regions_test.go @@ -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{ @@ -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) + }) + } +} diff --git a/schema/rewards/ParametersV1 b/schema/rewards/ParametersV1 index 9cb9f5be2..437aafdc8 100644 --- a/schema/rewards/ParametersV1 +++ b/schema/rewards/ParametersV1 @@ -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"}}} \ No newline at end of file +{"$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"}}} \ No newline at end of file