gno icon indicating copy to clipboard operation
gno copied to clipboard

test(bug): In TestDeleteByAddress, delete by address, check deletion of all keys with that address

Open jefft0 opened this issue 7 months ago • 2 comments

This PR demonstrates a bug. In keybase_test, we add a new test TestDeleteByAddress which is similar to the existing TestKeyManagement. We use CreateAccount to add two accounts with the same mnemonic (same bech32 address) but two different names, "john" and "john2". Then we call Delete to delete by the bech32 address. Only one of the keys is deleted. The other still exists.

To run the test:

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

Expected: pass. Actual: The test fails with:

        	Error Trace:	/Users/jefft0/work/gno/gno/tm2/pkg/crypto/keys/keybase_test.go:150
        	Error:      	Should be false
        	Test:       	TestDeleteByAddress

Discussion: Keybase writeInfo stores the same info under the key name and also the key address. This only allows an address to map to one name. When the key (with the same address) is created by the second name, the mapping from the address to the first name is replaced. Therefore, the call to delete by address only deletes the entry by the second name. The key is still accessible by the first name, meaning that "delete" doesn't really delete.

Possible solutions:

  • writeInfo should fail if there is already an entry for the address, or
  • writeInfo should map an address to a set of key names, or
  • don't "double index" by both name and address. (Only by name.)

jefft0 avatar Jul 01 '24 15:07 jefft0