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(bug): In TestKeyManagement, test GetByAddress after replacing a key with the same name #2684

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jefft0
Copy link
Contributor

@jefft0 jefft0 commented Aug 13, 2024

This PR demonstrates a bug. TestKeyManagement creates a key named "n2" with Info "i2". This PR adds GetByAddress and confirms that the public key in the retrieved Info matches the original public key. So good so far. Then the test calls CreateAccount to replace the entry for the same name with a new key (address). It calls GetByAddress with the original address, which successfully returns Info.

Expected: The public key in the Info should correspond to the address that it is fetched by.
Actual: The test fails because the public key doesn't match. (The "lookup by address" entry maps to the name "n2" but now that name entry has new Info.

To run the test:

cd gno/tm2/pkg/crypto/keys
go test .

Discussion: CreateAccount is allowed to replace the entry for a name with new Info (new address), but it leaves the existing "lookup by address" entry untouched. This creates the possibility of GetByAddress returning a public key which doesn't correspond to that address. This can cause problems with attempting to use the key, expecting it to match the address. A possible solution: When replacing a name entry with new Info, remove the "lookup by address" entry for the existing address. GetByAddress with the old address should fail.

…key with the same name. See the PR.

Signed-off-by: Jeff Thompson <[email protected]>
@jefft0 jefft0 requested review from jaekwon, moul and a team as code owners August 13, 2024 12:16
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Aug 13, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.15%. Comparing base (bbcb2f6) to head (eb9ed77).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2684      +/-   ##
==========================================
+ Coverage   60.11%   60.15%   +0.03%     
==========================================
  Files         560      561       +1     
  Lines       74918    74999      +81     
==========================================
+ Hits        45039    45114      +75     
- Misses      26504    26507       +3     
- Partials     3375     3378       +3     
Flag Coverage Δ
contribs/gnodev 60.58% <ø> (-0.82%) ⬇️
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 64.75% <ø> (+0.57%) ⬆️
gnovm 64.13% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jefft0
Copy link
Contributor Author

jefft0 commented Aug 13, 2024

A possible fix for the bug demonstrated in this PR is #2685, so I set this PR to Draft. If that PR is merged, then we can close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: No status
Status: Triage
Development

Successfully merging this pull request may close these issues.

1 participant