Skip to content

Commit

Permalink
Fix/requests test (#34)
Browse files Browse the repository at this point in the history
* Add inverted filter by event type

* Add inverted filter also for public event types

* Add auxiliary test functions

* Reduce boilerplate code in testing request functions

* Fix auth in create balance. Fix points and level accruing after claim.

* Refactor balance creation architecture

* Add AutoClaim test. Refactoring

* Refactor test for levels logic

* Claim tests refactoring

* Add testing config, check for balances and genesis code on setup

* Now init level for balance it is 0. Fix bug with adding fulfilled events for referrer without scanned passport

* fix genesis balance creation

* Fix bag with level accruing, because map can be indexed by for in different order each execution

* Tests fix & refactoring

* Country pools tests

* Referral status tests

* Add withdraw tests

* Config for tests

* Fix docs

* Comments refactoring

* Errorhandling, tests refactoring

* Remove unnecessary code

---------

Co-authored-by: violog <51th.apprent1ce.f0rce@gmail.com>
  • Loading branch information
Zaptoss and violog authored Jun 20, 2024
1 parent 0a83a31 commit 2cf00ee
Show file tree
Hide file tree
Showing 4 changed files with 954 additions and 308 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,18 @@ and in handlers/verify_passport:
// return nil, problems.BadRequest(err)
// }
```
and in handlers/withdraw(lines 49-58):
```go
// validated in requests.NewWithdraw
// addr, _ := cosmos.AccAddressFromBech32(req.Data.Attributes.Address)
// never panics because of request validation
// proof.PubSignals[zk.Nullifier] = mustHexToInt(nullifier)

// err = Verifier(r).VerifyProof(proof, zk.WithEventData(addr))
// if err != nil {
// ape.RenderErr(w, problems.BadRequest(err)...)
// return
// }
```

Run service with standart config (you need to configure db url only) and run tests.
Run service with config-testing.yaml (you need to configure db url) and run tests.
139 changes: 139 additions & 0 deletions config-testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
log:
level: debug
disable_sentry: true

db:
url: postgres://points:points@localhost:5432/points?sslmode=disable

listener:
addr: localhost:8000

event_types:
types:
- name: free_weekly
reward: 1
frequency: weekly
title: Free weekly points
short_description: Get free points every week, just pressing the button
description: "## Free Weekly Points\n\nThis is a weekly event where users can earn free points.\n\n### How it works\n\n- Users are eligible to participate once every week.\n- Upon participation, users will receive 100 points.\n- These points can be used for various features in the application.\n\nParticipate every week and maximize your rewards!\n"
logo: https://pbs.twimg.com/profile_images/1639021161257263105/XmT0EBnK_400x400.jpg
starts_at: 2024-03-23T12:42:00Z
- name: passport_scan
reward: 5
frequency: one-time
title: Passport verification
short_description: Scan your passport to unlock features and get points
description: "## Passport verification\n\nThis is a general event description.\n\n### How it works\n\n- Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n- Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nParticipate every week and maximize your rewards!\n"
logo: https://pbs.twimg.com/profile_images/1639021161257263105/XmT0EBnK_400x400.jpg
starts_at: 2024-03-23T12:42:00Z
auto_claim: true
- name: referral_common
reward: 15
frequency: one-time
title: Refer new users
short_description: Refer friends and get a reward for each friend who verifies the passport
description: "## Referral program\n\nThis is a general event description.\n\n### How it works\n\n- Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n- Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nParticipate every week and maximize your rewards!\n"
action_url: https://rarimo.com
- name: referral_specific
reward: 1
frequency: unlimited
no_auto_open: true
title: Refer user <did>
short_description: The user <did> has verified the passport. Claim the reward!
description: "## Referral program\n\nThis is a general event description.\n\n### How it works\n\n- Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n- Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nParticipate every week and maximize your rewards!\n"
action_url: https://rarimo.com
auto_claim: true
- name: new_limited_event
title: Limited event
reward: 5
frequency: one-time
short_description: This event will expire soon
description: "## Limited event\n\nThis is a general event description.\n\n### How it works\n\n- Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n- Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nParticipate every week and maximize your rewards!\n"
action_url: https://rarimo.com
expires_at: 2024-11-01T00:00:00Z
- name: new_expired_event
title: Expired event
reward: 3
frequency: one-time
short_description: This event has expired
description: "## Expired event\n\nThis is a general event description.\n\n### How it works\n\n- Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n- Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nParticipate every week and maximize your rewards!\n"
action_url: https://rarimo.com
expires_at: 2024-06-10T00:00:00Z

levels:
levels:
- lvl: 1
threshold: 0
referrals: 5
withdrawal_allowed: false
- lvl: 2
threshold: 5
referrals: 5
withdrawal_allowed: true
- lvl: 3
threshold: 6
referrals: 5
withdrawal_allowed: true

countries:
countries:
- code: "UKR"
reserve_limit: 100000
reserve_allowed: true
withdrawal_allowed: true
- code: "USA"
reserve_limit: 100
reserve_allowed: false
withdrawal_allowed: false
- code: "GBR"
reserve_limit: 5
reserve_allowed: false
withdrawal_allowed: true
- code: "CAN"
reserve_limit: 5
reserve_allowed: true
withdrawal_allowed: true
- code: "FRA"
reserve_limit: 6
reserve_allowed: true
withdrawal_allowed: true
- code: "IND"
reserve_limit: 1
reserve_allowed: false
withdrawal_allowed: true
- code: "MCO"
reserve_limit: 100
reserve_allowed: false
withdrawal_allowed: false
- code: "BEL"
reserve_limit: 100
reserve_allowed: true
withdrawal_allowed: false
- code: "MNG"
reserve_limit: 100
reserve_allowed: false
withdrawal_allowed: true
- code: "default"
reserve_limit: 5
reserve_allowed: true
withdrawal_allowed: true

auth:
addr: http://localhost:9030

broadcaster:
addr: localhost:9010
sender_account: "rarimo1ghcxdrgmy8duq8cu68fgmlp2sfmfwkh2dl4chl"

verifier:
verification_key_path: "./verification_key.json"
allowed_age: 18
allowed_identity_timestamp: 1715698750

root_verifier:
rpc: https://your-rpc
contract: 0x7DdAde70efADf832A600ba483FAD26fCA477FE2A
request_timeout: 10s

withdrawal:
point_price_urmo: 1000000 # 1 RMO
12 changes: 5 additions & 7 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ event_types:
frequency: one-time
action_url: https://...
logo: https://...
auto_claim: true
- name: free_weekly
title: Free weekly points
reward: 1
Expand All @@ -44,6 +45,7 @@ event_types:
description: The user {:did} has verified the passport. Claim the reward!
short_description: Short description
no_auto_open: true
auto_claim: true

levels:
levels:
Expand All @@ -68,15 +70,11 @@ countries:
reserve_allowed: true
withdrawal_allowed: true
- code: "USA"
reserve_limit: 5
reserve_allowed: true
withdrawal_allowed: true
- code: "GBR"
reserve_limit: 5
reserve_limit: 0
reserve_allowed: false
withdrawal_allowed: true
withdrawal_allowed: false
- code: "default"
reserve_limit: 5
reserve_limit: 100
reserve_allowed: true
withdrawal_allowed: true

Expand Down
Loading

0 comments on commit 2cf00ee

Please sign in to comment.