From d30b4ea4f281a85c4cae5e346d8e150a2663d636 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Fri, 19 Jul 2019 09:40:02 -0500 Subject: [PATCH] Update GetStorageValueMetadata --- libraries/shared/storage/utils/value.go | 26 ++++++++++++++------ libraries/shared/storage/utils/value_test.go | 19 +++++++++++++- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/libraries/shared/storage/utils/value.go b/libraries/shared/storage/utils/value.go index 865bf9ae..ba463ab1 100644 --- a/libraries/shared/storage/utils/value.go +++ b/libraries/shared/storage/utils/value.go @@ -30,17 +30,27 @@ const ( type Key string type StorageValueMetadata struct { - Name string - Keys map[Key]string - Type ValueType + Name string + Keys map[Key]string + Type ValueType + PackedNames map[int]string //name of each item packed and their order PackedTypes map[int]ValueType //type of each item packed and their order - PackedNames map[int]string //name of each item packed and their order } -func GetStorageValueMetadata(name string, keys map[Key]string, t ValueType) StorageValueMetadata { +func GetStorageValueMetadata(name string, keys map[Key]string, valueType ValueType) StorageValueMetadata { + return getMetadata(name, keys, valueType, nil, nil) +} + +func GetStorageValueMetadataForPackedSlot(name string, keys map[Key]string, valueType ValueType, packedNames map[int]string, packedTypes map[int]ValueType) StorageValueMetadata { + return getMetadata(name, keys, valueType, packedNames, packedTypes) +} + +func getMetadata(name string, keys map[Key]string, t ValueType, packedNames map[int]string, packedTypes map[int]ValueType) StorageValueMetadata { return StorageValueMetadata{ - Name: name, - Keys: keys, - Type: t, + Name: name, + Keys: keys, + Type: t, + PackedNames: packedNames, + PackedTypes: packedTypes, } } diff --git a/libraries/shared/storage/utils/value_test.go b/libraries/shared/storage/utils/value_test.go index 6af20499..f07a8fae 100644 --- a/libraries/shared/storage/utils/value_test.go +++ b/libraries/shared/storage/utils/value_test.go @@ -7,7 +7,7 @@ import ( ) var _ = Describe("Storage value metadata getter", func() { - It("returns a storage value metadata instance with corresponding fields assigned", func() { + It("returns storage value metadata for a single storage variable", func() { metadataName := "fake_name" metadataKeys := map[utils.Key]string{"key": "value"} metadataType := utils.Uint256 @@ -19,4 +19,21 @@ var _ = Describe("Storage value metadata getter", func() { } Expect(utils.GetStorageValueMetadata(metadataName, metadataKeys, metadataType)).To(Equal(expectedMetadata)) }) + + It("returns metadata for a packed storage slot variables", func() { + metadataName := "fake_name" + metadataKeys := map[utils.Key]string{"key": "value"} + metadataType := utils.Uint256 + metadataPackedNames := map[int]string{0: "name"} + metadataPackedTypes := map[int]utils.ValueType{0: utils.Uint48} + + expectedMetadata := utils.StorageValueMetadata{ + Name: metadataName, + Keys: metadataKeys, + Type: metadataType, + PackedTypes: metadataPackedTypes, + PackedNames: metadataPackedNames, + } + Expect(utils.GetStorageValueMetadataForPackedSlot(metadataName, metadataKeys, metadataType, metadataPackedNames, metadataPackedTypes)).To(Equal(expectedMetadata)) + }) })