Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #102 from vulcanize/fix-mappings-util
Browse files Browse the repository at this point in the history
Fix mappings util
  • Loading branch information
rmulhol authored Jun 17, 2019
2 parents d761f88 + 95fa628 commit 7d6629e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/shared/storage/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
)

func GetMapping(indexOnContract, key string) common.Hash {
keyBytes := common.FromHex("0x" + key + indexOnContract)
keyBytes := common.FromHex(key + indexOnContract)
encoded := crypto.Keccak256(keyBytes)
return common.BytesToHash(encoded)
}
Expand Down
10 changes: 10 additions & 0 deletions libraries/shared/storage/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ var _ = Describe("Mappings", func() {
expectedStorageKey := common.HexToHash("0xee0c1b59a3856bafbfb8730e7694c4badc271eb5f01ce4a8d7a53d8a6499676f")
Expect(storageKey).To(Equal(expectedStorageKey))
})

It("returns same result if value includes hex prefix", func() {
indexOfMappingOnContract := storage.IndexZero
keyForDesiredValueInMapping := "0x1234567890abcdef"

storageKey := storage.GetMapping(indexOfMappingOnContract, keyForDesiredValueInMapping)

expectedStorageKey := common.HexToHash("0xee0c1b59a3856bafbfb8730e7694c4badc271eb5f01ce4a8d7a53d8a6499676f")
Expect(storageKey).To(Equal(expectedStorageKey))
})
})

Describe("GetNestedMapping", func() {
Expand Down

0 comments on commit 7d6629e

Please sign in to comment.