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

validate address of contract indexer #3874

Merged
merged 4 commits into from Jun 6, 2023

Conversation

envestcc
Copy link
Member

Description

validate address when NewContractStakingIndexer

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@envestcc envestcc requested review from CoderZhi, dustinxie, Liuhaai and a team as code owners May 30, 2023 07:09
@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Merging #3874 (e65ae89) into master (e1f0636) will increase coverage by 0.16%.
The diff coverage is 64.61%.

❗ Current head e65ae89 differs from pull request most recent head 98f4fc6. Consider uploading reports for the commit 98f4fc6 to get more accurate results

@@            Coverage Diff             @@
##           master    #3874      +/-   ##
==========================================
+ Coverage   75.38%   75.54%   +0.16%     
==========================================
  Files         303      325      +22     
  Lines       25923    27600    +1677     
==========================================
+ Hits        19541    20850    +1309     
- Misses       5360     5685     +325     
- Partials     1022     1065      +43     
Impacted Files Coverage Δ
action/protocol/execution/evm/evm.go 43.52% <0.00%> (-2.95%) ⬇️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/poll/consortium.go 0.00% <0.00%> (ø)
action/protocol/poll/staking_committee.go 43.85% <0.00%> (ø)
...tion/protocol/staking/contractstake_bucket_type.go 0.00% <0.00%> (ø)
api/web3server_marshal.go 93.21% <ø> (ø)
blockchain/config.go 74.54% <ø> (ø)
blockindex/contractstaking/dummy_indexer.go 0.00% <0.00%> (ø)
blockindex/sgd_indexer.go 2.45% <2.45%> (ø)
action/protocol/staking/contractstake_indexer.go 14.28% <14.28%> (ø)
... and 37 more

... and 9 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Liuhaai
Copy link
Member

Liuhaai commented May 30, 2023

add invalid address in the test

func NewContractStakingIndexer(kvStore db.KVStore, contractAddr string, contractDeployHeight uint64) (*Indexer, error) {
if _, err := address.FromString(contractAddr); err != nil {
return nil, errors.Wrapf(err, "invalid contract address %s", contractAddr)
}
Copy link
Member

Choose a reason for hiding this comment

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

can simply panic("invalid system staking contract address"), then no need to change other places

Copy link
Member

Choose a reason for hiding this comment

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

also

if kv == nil {
		panic("nil kvstore")
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that it is generally recommended to return an error in most error handling scenarios instead of panic. Excessive use of panic can make the code less maintainable and harder to write unit tests.

Copy link
Member

Choose a reason for hiding this comment

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

ok, then check the kv == nil error?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@sonarcloud
Copy link

sonarcloud bot commented Jun 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
1.5% 1.5% Duplication

@dustinxie dustinxie merged commit fc67863 into iotexproject:master Jun 6, 2023
4 checks passed
@envestcc envestcc deleted the address_validate branch June 6, 2023 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants