Skip to content

Commit

Permalink
Merge pull request #100 from makerdao/add-type-for-storage
Browse files Browse the repository at this point in the history
Add type for median storage
  • Loading branch information
yaoandrew committed Jun 2, 2020
2 parents 3f6afb7 + 93c5b72 commit 37df39e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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
Uint32
Uint48
Uint128
Expand Down

0 comments on commit 37df39e

Please sign in to comment.