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

Add type for median storage #100

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libraries/shared/storage/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func Decode(diff types.PersistedDiff, metadata types.ValueMetadata) (interface{}
switch metadata.Type {
case types.Uint256:
return decodeInteger(diff.StorageValue.Bytes()), nil
case types.Uint8:
return decodeInteger(diff.StorageValue.Bytes()), nil
case types.Uint32:
return decodeInteger(diff.StorageValue.Bytes()), nil
case types.Uint48:
Expand Down
11 changes: 11 additions & 0 deletions libraries/shared/storage/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ var _ = Describe("Storage decoder", func() {
Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String()))
})

It("decodes uint8", func() {
fakeInt := common.HexToHash("0000000000000000000000000000000000000000000000000000000000000244")
diff := types.PersistedDiff{RawDiff: types.RawDiff{StorageValue: fakeInt}}
metadata := types.ValueMetadata{Type: types.Uint8}

result, err := storage.Decode(diff, metadata)

Expect(err).NotTo(HaveOccurred())
Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String()))
})

It("decodes uint128", func() {
fakeInt := common.HexToHash("0000000000000000000000000000000000000000000000000000000000011123")
diff := types.PersistedDiff{RawDiff: types.RawDiff{StorageValue: fakeInt}}
Expand Down
1 change: 1 addition & 0 deletions libraries/shared/storage/types/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ValueType int

const (
Uint256 ValueType = iota
Uint8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add a branch to the storage decoder so that we'll properly handle this new type

Uint32
Uint48
Uint128
Expand Down