test(bug): In TestKeyManagement, test GetByAddress after replacing a key with the same name #2684
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR demonstrates a bug.
TestKeyManagement
creates a key named "n2" withInfo
"i2". This PR addsGetByAddress
and confirms that the public key in the retrievedInfo
matches the original public key. So good so far. Then the test callsCreateAccount
to replace the entry for the same name with a new key (address). It callsGetByAddress
with the original address, which successfully returnsInfo
.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:
Discussion:
CreateAccount
is allowed to replace the entry for a name with newInfo
(new address), but it leaves the existing "lookup by address" entry untouched. This creates the possibility ofGetByAddress
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 newInfo
, remove the "lookup by address" entry for the existing address.GetByAddress
with the old address should fail.