Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add rate limiter admin E2E test #2063

Merged
merged 26 commits into from
Apr 29, 2024

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Apr 22, 2024

Description

Add an admin test to test the rate limiter functionality.
The test so far:

  • Do 5 ZETA withdraws and print data
  • Set rate limiter flags and do 5 other withdraws with values reaching the rate
  • Disabled the flags and do 5 withdraws again

Closes: #2058

@lumtis lumtis changed the base branch from develop to v16.0.0-rc April 24, 2024 14:42
@lumtis lumtis changed the base branch from v16.0.0-rc to unit-test-rate-limit April 24, 2024 18:05
@lumtis lumtis added the no-changelog Skip changelog CI check label Apr 24, 2024
Copy link

!!!WARNING!!!
nosec detected in the following files: x/crosschain/keeper/grpc_query_cctx_rate_limit.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Apr 25, 2024
e2e/runner/evm.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks nice

@lumtis lumtis marked this pull request as ready for review April 29, 2024 09:23
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.48%. Comparing base (c011900) to head (5a4d449).

Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                  @@
##           unit-test-rate-limit    #2063   +/-   ##
=====================================================
  Coverage                 71.48%   71.48%           
=====================================================
  Files                       252      252           
  Lines                     14081    14081           
=====================================================
  Hits                      10066    10066           
  Misses                     3554     3554           
  Partials                    461      461           
Files Coverage Δ
x/crosschain/keeper/grpc_query_cctx_rate_limit.go 96.07% <100.00%> (ø)
x/observer/types/chain_params.go 99.17% <100.00%> (ø)

@ws4charlie ws4charlie merged commit bd13759 into unit-test-rate-limit Apr 29, 2024
18 checks passed
@ws4charlie ws4charlie deleted the e2e/rate-limiter branch April 29, 2024 18:03
@lumtis lumtis mentioned this pull request May 2, 2024
lumtis added a commit that referenced this pull request May 2, 2024
)

* initial commit of grpc pending cctx query with rate limiter

* replace big.Float with sdk.Dec and update mock rate limiter flags

* split big loop into backwards loop and forwards loop to be more accurate

* adjust zetaclient code to query pending cctx with rate limit

* update change log and add one more rate limiter flag test

* use outboun amount for calculation

* some minimum code refactor

* created separate file for cctx query with rate limit

* improved a few error handlling

* use old cctx query as fallback when rate limiter is disabled; some renaming

* fixed unit test compile

* added unit test for fallback query

* added unit tests for cctx value conversion

* add changelog entry

* added unit tests for query pending cctxs within rate limit

* added total value in rate limiter window for monitoring purpose

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit.go

Co-authored-by: Lucas Bertrand <[email protected]>

* change variable name fCoin to foreignCoin

* Update x/fungible/keeper/foreign_coins.go

Co-authored-by: Lucas Bertrand <[email protected]>

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go

Co-authored-by: Lucas Bertrand <[email protected]>

* converted rate limiter query unit tests to table test

* handle edge case when pending cctxs span wider block range than sliding window

* added zero rate check; added comment to make unit test clearer

* added unit test and note for method GetAllForeignCoinMap

* treat Rate as average block rate; stop outbound when current rate limit exceeds Rate; updated metrics

* add commented unit tests back

* replace sdk.Dec with sdkmath.Int to represent cctx value in azeta

* test: disable header proof test in local upgrade test E2E test (#2051)

* add skip header option

* use option for migration test

* move bitcoin addresses tests to advanced

* show cctx in logs

* update version

* fix verification flags error

* test(e2e): add rate limiter admin E2E test (#2063)

* refactor and create Withdraw ZETA general function

* new rate limiter test

* use rate limiter for admin test

* fix the test: single approval and add liquidity

* make generate

* fix liquidity

* fix uniswap pool

* change localnet chain params

* fix lint

* add cli query

* add nil check

* fix nil point

* modify tests

* eliminate nil pending nonce issue

* fix query

* set flags

* Update e2e/runner/evm.go

Co-authored-by: Charlie Chen <[email protected]>

* add back other advanced tests

* make generate

* add comment

* fix eth liquidity cap test

* fix withdraw count

---------

Co-authored-by: Charlie Chen <[email protected]>
Co-authored-by: Charlie Chen <[email protected]>

* removed incorrect Note

* improved variable name

* add E2E test for rate limiter gas and erc20

* remove outdated comment

---------

Co-authored-by: Lucas Bertrand <[email protected]>
ws4charlie added a commit that referenced this pull request May 2, 2024
* refactor: allow zeta deposits to new zevm address (#2076)

* allow zevm coin deposit to unknow addresses

* add e2e tests

* add changelog

* add comments

* test(e2e): fix local e2e upgrade test (#2099)

* add skip header option

* use option for migration test

* move bitcoin addresses tests to advanced

* show cctx in logs

* update version

* fix verification flags error

* update version in changelog

* test: fix and unit tests for query pending cctx within rate limit (#2060)

* initial commit of grpc pending cctx query with rate limiter

* replace big.Float with sdk.Dec and update mock rate limiter flags

* split big loop into backwards loop and forwards loop to be more accurate

* adjust zetaclient code to query pending cctx with rate limit

* update change log and add one more rate limiter flag test

* use outboun amount for calculation

* some minimum code refactor

* created separate file for cctx query with rate limit

* improved a few error handlling

* use old cctx query as fallback when rate limiter is disabled; some renaming

* fixed unit test compile

* added unit test for fallback query

* added unit tests for cctx value conversion

* add changelog entry

* added unit tests for query pending cctxs within rate limit

* added total value in rate limiter window for monitoring purpose

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit.go

Co-authored-by: Lucas Bertrand <[email protected]>

* change variable name fCoin to foreignCoin

* Update x/fungible/keeper/foreign_coins.go

Co-authored-by: Lucas Bertrand <[email protected]>

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go

Co-authored-by: Lucas Bertrand <[email protected]>

* converted rate limiter query unit tests to table test

* handle edge case when pending cctxs span wider block range than sliding window

* added zero rate check; added comment to make unit test clearer

* added unit test and note for method GetAllForeignCoinMap

* treat Rate as average block rate; stop outbound when current rate limit exceeds Rate; updated metrics

* add commented unit tests back

* replace sdk.Dec with sdkmath.Int to represent cctx value in azeta

* test: disable header proof test in local upgrade test E2E test (#2051)

* add skip header option

* use option for migration test

* move bitcoin addresses tests to advanced

* show cctx in logs

* update version

* fix verification flags error

* test(e2e): add rate limiter admin E2E test (#2063)

* refactor and create Withdraw ZETA general function

* new rate limiter test

* use rate limiter for admin test

* fix the test: single approval and add liquidity

* make generate

* fix liquidity

* fix uniswap pool

* change localnet chain params

* fix lint

* add cli query

* add nil check

* fix nil point

* modify tests

* eliminate nil pending nonce issue

* fix query

* set flags

* Update e2e/runner/evm.go

Co-authored-by: Charlie Chen <[email protected]>

* add back other advanced tests

* make generate

* add comment

* fix eth liquidity cap test

* fix withdraw count

---------

Co-authored-by: Charlie Chen <[email protected]>
Co-authored-by: Charlie Chen <[email protected]>

* removed incorrect Note

* improved variable name

* add E2E test for rate limiter gas and erc20

* remove outdated comment

---------

Co-authored-by: Lucas Bertrand <[email protected]>

* more conflict resolution

---------

Co-authored-by: Tanmay <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
Co-authored-by: Alex Gartner <[email protected]>
ws4charlie added a commit that referenced this pull request May 7, 2024
* initial commit of grpc pending cctx query with rate limiter

* replace big.Float with sdk.Dec and update mock rate limiter flags

* split big loop into backwards loop and forwards loop to be more accurate

* adjust zetaclient code to query pending cctx with rate limit

* update change log and add one more rate limiter flag test

* use outboun amount for calculation

* some minimum code refactor

* created separate file for cctx query with rate limit

* improved a few error handlling

* use old cctx query as fallback when rate limiter is disabled; some renaming

* fixed unit test compile

* added unit test for fallback query

* added unit tests for cctx value conversion

* add changelog entry

* added unit tests for query pending cctxs within rate limit

* added total value in rate limiter window for monitoring purpose

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit.go

Co-authored-by: Lucas Bertrand <[email protected]>

* change variable name fCoin to foreignCoin

* Update x/fungible/keeper/foreign_coins.go

Co-authored-by: Lucas Bertrand <[email protected]>

* Update x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go

Co-authored-by: Lucas Bertrand <[email protected]>

* converted rate limiter query unit tests to table test

* handle edge case when pending cctxs span wider block range than sliding window

* added zero rate check; added comment to make unit test clearer

* added unit test and note for method GetAllForeignCoinMap

* treat Rate as average block rate; stop outbound when current rate limit exceeds Rate; updated metrics

* refactor: allow zeta deposits to new zevm address (#2076)

* allow zevm coin deposit to unknow addresses

* add e2e tests

* add changelog

* add comments

* add commented unit tests back

* replace sdk.Dec with sdkmath.Int to represent cctx value in azeta

* test(e2e): add rate limiter admin E2E test (#2063)

* refactor and create Withdraw ZETA general function

* new rate limiter test

* use rate limiter for admin test

* fix the test: single approval and add liquidity

* make generate

* fix liquidity

* fix uniswap pool

* change localnet chain params

* fix lint

* add cli query

* add nil check

* fix nil point

* modify tests

* eliminate nil pending nonce issue

* fix query

* set flags

* Update e2e/runner/evm.go

Co-authored-by: Charlie Chen <[email protected]>

* add back other advanced tests

* make generate

* add comment

* fix eth liquidity cap test

* fix withdraw count

---------

Co-authored-by: Charlie Chen <[email protected]>
Co-authored-by: Charlie Chen <[email protected]>

* removed incorrect Note

* initiated rate limiter refactor and added metrics

* added more unit tests and updated changelog

* print more details from rate limiter output

* reorder observer methods declaration

* fix unit test

* moved state irrelevant methods to types; renaming and cleaning

* code indentation and update variable

* replace  with

* fix unit test

* added extra unit tests and improved func name

---------

Co-authored-by: Lucas Bertrand <[email protected]>
Co-authored-by: Tanmay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rate limiter E2E tests
2 participants