remove maker migrations and convert back to timestamps and fix bug in

composeAndExecute command
This commit is contained in:
Ian Norden
2019-02-24 21:52:23 -06:00
parent b449193b16
commit 3d34a9e7c9
25 changed files with 137 additions and 5108 deletions
@@ -1,35 +0,0 @@
// 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/>.
package maker_test
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestMaker(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Maker Suite")
}
var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard)
})
@@ -1,19 +0,0 @@
package pit_test
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestPit(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Pit Suite")
}
var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard)
})
@@ -1,19 +0,0 @@
package vat_test
import (
"github.com/sirupsen/logrus"
"io/ioutil"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestVat(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Vat Suite")
}
var _ = BeforeSuite(func() {
logrus.SetOutput(ioutil.Discard)
})
@@ -1,152 +0,0 @@
/*
* Copyright 2018 Vulcanize
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package vow
import (
"github.com/ethereum/go-ethereum/common"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
)
const (
VowVat = "vat"
VowCow = "cow"
VowRow = "row"
VowSin = "Sin"
VowWoe = "Woe"
VowAsh = "Ash"
VowWait = "wait"
VowSump = "sump"
VowBump = "bump"
VowHump = "hump"
)
var (
VatKey = common.HexToHash(storage_diffs.IndexOne)
VatMetadata = shared.StorageValueMetadata{
Name: VowVat,
Keys: nil,
Type: shared.Address,
}
CowKey = common.HexToHash(storage_diffs.IndexTwo)
CowMetadata = shared.StorageValueMetadata{
Name: VowCow,
Keys: nil,
Type: shared.Address,
}
RowKey = common.HexToHash(storage_diffs.IndexThree)
RowMetadata = shared.StorageValueMetadata{
Name: VowRow,
Keys: nil,
Type: shared.Address,
}
SinKey = common.HexToHash(storage_diffs.IndexFive)
SinMetadata = shared.StorageValueMetadata{
Name: VowSin,
Keys: nil,
Type: shared.Uint256,
}
WoeKey = common.HexToHash(storage_diffs.IndexSix)
WoeMetadata = shared.StorageValueMetadata{
Name: VowWoe,
Keys: nil,
Type: shared.Uint256,
}
AshKey = common.HexToHash(storage_diffs.IndexSeven)
AshMetadata = shared.StorageValueMetadata{
Name: VowAsh,
Keys: nil,
Type: shared.Uint256,
}
WaitKey = common.HexToHash(storage_diffs.IndexEight)
WaitMetadata = shared.StorageValueMetadata{
Name: VowWait,
Keys: nil,
Type: shared.Uint256,
}
SumpKey = common.HexToHash(storage_diffs.IndexNine)
SumpMetadata = shared.StorageValueMetadata{
Name: VowSump,
Keys: nil,
Type: shared.Uint256,
}
BumpKey = common.HexToHash(storage_diffs.IndexTen)
BumpMetadata = shared.StorageValueMetadata{
Name: VowBump,
Keys: nil,
Type: shared.Uint256,
}
HumpKey = common.HexToHash(storage_diffs.IndexEleven)
HumpMetadata = shared.StorageValueMetadata{
Name: VowHump,
Keys: nil,
Type: shared.Uint256,
}
)
type VowMappings struct {
StorageRepository maker.IMakerStorageRepository
mappings map[common.Hash]shared.StorageValueMetadata
}
func (mappings *VowMappings) Lookup(key common.Hash) (shared.StorageValueMetadata, error) {
metadata, ok := mappings.mappings[key]
if !ok {
err := mappings.loadMappings()
if err != nil {
return metadata, err
}
metadata, ok = mappings.mappings[key]
if !ok {
return metadata, shared.ErrStorageKeyNotFound{Key: key.Hex()}
}
}
return metadata, nil
}
func (mappings *VowMappings) loadMappings() error {
staticMappings := make(map[common.Hash]shared.StorageValueMetadata)
staticMappings[VatKey] = VatMetadata
staticMappings[CowKey] = CowMetadata
staticMappings[RowKey] = RowMetadata
staticMappings[SinKey] = SinMetadata
staticMappings[WoeKey] = WoeMetadata
staticMappings[AshKey] = AshMetadata
staticMappings[WaitKey] = WaitMetadata
staticMappings[SumpKey] = SumpMetadata
staticMappings[BumpKey] = BumpMetadata
staticMappings[HumpKey] = HumpMetadata
mappings.mappings = staticMappings
return nil
}
func (mappings *VowMappings) SetDB(db *postgres.DB) {
mappings.StorageRepository.SetDB(db)
}
@@ -1,42 +0,0 @@
package vow_test
import (
"github.com/ethereum/go-ethereum/common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/test_helpers"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/maker/vow"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
)
var _ = Describe("Vow storage mappings", func() {
Describe("looking up static keys", func() {
It("returns value metadata if key exists", func() {
storageRepository := &test_helpers.MockMakerStorageRepository{}
mappings := vow.VowMappings{StorageRepository: storageRepository}
Expect(mappings.Lookup(vow.VatKey)).To(Equal(vow.VatMetadata))
Expect(mappings.Lookup(vow.CowKey)).To(Equal(vow.CowMetadata))
Expect(mappings.Lookup(vow.RowKey)).To(Equal(vow.RowMetadata))
Expect(mappings.Lookup(vow.SinKey)).To(Equal(vow.SinMetadata))
Expect(mappings.Lookup(vow.WoeKey)).To(Equal(vow.WoeMetadata))
Expect(mappings.Lookup(vow.AshKey)).To(Equal(vow.AshMetadata))
Expect(mappings.Lookup(vow.WaitKey)).To(Equal(vow.WaitMetadata))
Expect(mappings.Lookup(vow.SumpKey)).To(Equal(vow.SumpMetadata))
Expect(mappings.Lookup(vow.BumpKey)).To(Equal(vow.BumpMetadata))
Expect(mappings.Lookup(vow.HumpKey)).To(Equal(vow.HumpMetadata))
})
It("returns error if key does not exist", func() {
storageRepository := &test_helpers.MockMakerStorageRepository{}
mappings := vow.VowMappings{StorageRepository: storageRepository}
_, err := mappings.Lookup(common.HexToHash(fakes.FakeHash.Hex()))
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(shared.ErrStorageKeyNotFound{Key: fakes.FakeHash.Hex()}))
})
})
})
@@ -1,117 +0,0 @@
/*
* Copyright 2018 Vulcanize
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package vow
import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
)
type VowStorageRepository struct {
db *postgres.DB
}
func (repository *VowStorageRepository) SetDB(db *postgres.DB) {
repository.db = db
}
func (repository VowStorageRepository) Create(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, value interface{}) error {
switch metadata.Name {
case VowVat:
return repository.insertVowVat(blockNumber, blockHash, value.(string))
case VowCow:
return repository.insertVowCow(blockNumber, blockHash, value.(string))
case VowRow:
return repository.insertVowRow(blockNumber, blockHash, value.(string))
case VowSin:
return repository.insertVowSin(blockNumber, blockHash, value.(string))
case VowWoe:
return repository.insertVowWoe(blockNumber, blockHash, value.(string))
case VowAsh:
return repository.insertVowAsh(blockNumber, blockHash, value.(string))
case VowWait:
return repository.insertVowWait(blockNumber, blockHash, value.(string))
case VowSump:
return repository.insertVowSump(blockNumber, blockHash, value.(string))
case VowBump:
return repository.insertVowBump(blockNumber, blockHash, value.(string))
case VowHump:
return repository.insertVowHump(blockNumber, blockHash, value.(string))
default:
panic("unrecognized storage metadata name")
}
}
func (repository VowStorageRepository) insertVowVat(blockNumber int, blockHash string, vat string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_vat (block_number, block_hash, vat) VALUES ($1, $2, $3)`, blockNumber, blockHash, vat)
return err
}
func (repository VowStorageRepository) insertVowCow(blockNumber int, blockHash string, cow string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_cow (block_number, block_hash, cow) VALUES ($1, $2, $3)`, blockNumber, blockHash, cow)
return err
}
func (repository VowStorageRepository) insertVowRow(blockNumber int, blockHash string, row string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_row (block_number, block_hash, row) VALUES ($1, $2, $3)`, blockNumber, blockHash, row)
return err
}
func (repository VowStorageRepository) insertVowSin(blockNumber int, blockHash string, sin string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_sin (block_number, block_hash, sin) VALUES ($1, $2, $3)`, blockNumber, blockHash, sin)
return err
}
func (repository VowStorageRepository) insertVowWoe(blockNumber int, blockHash string, woe string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_woe (block_number, block_hash, woe) VALUES ($1, $2, $3)`, blockNumber, blockHash, woe)
return err
}
func (repository VowStorageRepository) insertVowAsh(blockNumber int, blockHash string, ash string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_ash (block_number, block_hash, ash) VALUES ($1, $2, $3)`, blockNumber, blockHash, ash)
return err
}
func (repository VowStorageRepository) insertVowWait(blockNumber int, blockHash string, wait string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_wait (block_number, block_hash, wait) VALUES ($1, $2, $3)`, blockNumber, blockHash, wait)
return err
}
func (repository VowStorageRepository) insertVowSump(blockNumber int, blockHash string, sump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_sump (block_number, block_hash, sump) VALUES ($1, $2, $3)`, blockNumber, blockHash, sump)
return err
}
func (repository VowStorageRepository) insertVowBump(blockNumber int, blockHash string, bump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_bump (block_number, block_hash, bump) VALUES ($1, $2, $3)`, blockNumber, blockHash, bump)
return err
}
func (repository VowStorageRepository) insertVowHump(blockNumber int, blockHash string, hump string) error {
_, err := repository.db.Exec(`INSERT INTO maker.vow_hump (block_number, block_hash, hump) VALUES ($1, $2, $3)`, blockNumber, blockHash, hump)
return err
}
@@ -1,13 +0,0 @@
package vow_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestVow(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Storage Diff Vow Suite")
}
@@ -1,63 +0,0 @@
// 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/>.
package storage_diffs
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared"
"math/big"
)
type Mappings interface {
Lookup(key common.Hash) (shared.StorageValueMetadata, error)
SetDB(db *postgres.DB)
}
const (
IndexZero = "0000000000000000000000000000000000000000000000000000000000000000"
IndexOne = "0000000000000000000000000000000000000000000000000000000000000001"
IndexTwo = "0000000000000000000000000000000000000000000000000000000000000002"
IndexThree = "0000000000000000000000000000000000000000000000000000000000000003"
IndexFour = "0000000000000000000000000000000000000000000000000000000000000004"
IndexFive = "0000000000000000000000000000000000000000000000000000000000000005"
IndexSix = "0000000000000000000000000000000000000000000000000000000000000006"
IndexSeven = "0000000000000000000000000000000000000000000000000000000000000007"
IndexEight = "0000000000000000000000000000000000000000000000000000000000000008"
IndexNine = "0000000000000000000000000000000000000000000000000000000000000009"
IndexTen = "0000000000000000000000000000000000000000000000000000000000000010"
IndexEleven = "0000000000000000000000000000000000000000000000000000000000000011 "
)
func GetMapping(indexOnContract, key string) common.Hash {
keyBytes := common.FromHex("0x" + key + indexOnContract)
encoded := crypto.Keccak256(keyBytes)
return common.BytesToHash(encoded)
}
func GetNestedMapping(indexOnContract, primaryKey, secondaryKey string) common.Hash {
primaryMappingIndex := crypto.Keccak256(common.FromHex(primaryKey + indexOnContract))
secondaryMappingIndex := crypto.Keccak256(common.FromHex(secondaryKey), primaryMappingIndex)
return common.BytesToHash(secondaryMappingIndex)
}
func GetIncrementedKey(original common.Hash, incrementBy int64) common.Hash {
originalMappingAsInt := original.Big()
incremented := big.NewInt(0).Add(originalMappingAsInt, big.NewInt(incrementBy))
return common.BytesToHash(incremented.Bytes())
}