2019-01-28 22:52:47 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
package utils_test
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
import (
|
2019-01-31 23:14:42 +00:00
|
|
|
"math/big"
|
|
|
|
|
2019-01-28 22:52:47 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2019-01-31 23:14:42 +00:00
|
|
|
|
2019-02-10 22:42:41 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/libraries/shared/storage/utils"
|
2019-01-28 22:52:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Storage decoder", func() {
|
|
|
|
It("decodes uint256", func() {
|
|
|
|
fakeInt := common.HexToHash("0000000000000000000000000000000000000000000000000000000000000539")
|
2019-01-31 23:14:42 +00:00
|
|
|
row := utils.StorageDiffRow{StorageValue: fakeInt}
|
|
|
|
metadata := utils.StorageValueMetadata{Type: utils.Uint256}
|
2019-01-28 22:52:47 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
result, err := utils.Decode(row, metadata)
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(result).To(Equal(big.NewInt(0).SetBytes(fakeInt.Bytes()).String()))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("decodes address", func() {
|
|
|
|
fakeAddress := common.HexToAddress("0x12345")
|
2019-01-31 23:14:42 +00:00
|
|
|
row := utils.StorageDiffRow{StorageValue: fakeAddress.Hash()}
|
|
|
|
metadata := utils.StorageValueMetadata{Type: utils.Address}
|
2019-01-28 22:52:47 +00:00
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
result, err := utils.Decode(row, metadata)
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(result).To(Equal(fakeAddress.Hex()))
|
|
|
|
})
|
|
|
|
})
|