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 (
|
|
|
|
"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 row parsing", func() {
|
|
|
|
It("converts an array of strings to a row struct", func() {
|
|
|
|
contract := "0x123"
|
|
|
|
blockHash := "0x456"
|
|
|
|
blockHeight := "789"
|
|
|
|
storageKey := "0x987"
|
|
|
|
storageValue := "0x654"
|
|
|
|
data := []string{contract, blockHash, blockHeight, storageKey, storageValue}
|
|
|
|
|
2019-01-31 23:14:42 +00:00
|
|
|
result, err := utils.FromStrings(data)
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(result.Contract).To(Equal(common.HexToAddress(contract)))
|
|
|
|
Expect(result.BlockHash).To(Equal(common.HexToHash(blockHash)))
|
|
|
|
Expect(result.BlockHeight).To(Equal(789))
|
|
|
|
Expect(result.StorageKey).To(Equal(common.HexToHash(storageKey)))
|
|
|
|
Expect(result.StorageValue).To(Equal(common.HexToHash(storageValue)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns an error if row is missing data", func() {
|
2019-01-31 23:14:42 +00:00
|
|
|
_, err := utils.FromStrings([]string{"0x123"})
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
2019-01-31 23:14:42 +00:00
|
|
|
Expect(err).To(MatchError(utils.ErrRowMalformed{Length: 1}))
|
2019-01-28 22:52:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("returns error if block height malformed", func() {
|
2019-01-31 23:14:42 +00:00
|
|
|
_, err := utils.FromStrings([]string{"", "", "", "", ""})
|
2019-01-28 22:52:47 +00:00
|
|
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|