Transform and persist Tend log events

This commit is contained in:
Elizabeth
2018-08-16 16:36:35 -05:00
committed by GitHub
parent 634604d0b5
commit 66ad7e3021
34 changed files with 1290 additions and 147 deletions
+27
View File
@@ -0,0 +1,27 @@
// 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 test_data
var (
FlipAddress = "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d"
FlipKickTransactionHash = "0x6b155a55fd77b751195deeebf7abfd8691ca01ee588817a920f19d5b27f65191"
FlipKickData = "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000008cb6176addcca2e1d1ffe21bee464b72ee4cd8d00000000000000000000000038219779a699d67d7e7740b8c8f43d3e2dae218266616b6520696c6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a09200000000000000000000000007fa9ef6609ca7921112231f8f195138ebba2977000000000000000000000000000000000000000000000000000000005b69b8e7000000000000000000000000000000000000000000000000000000005b607e670000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca0000000000000000000000000000000000000000000000000000000000000032"
FlipKickBlockHash = "0x32f8b12023b3a1b4c73f9a46da976931b0355714ada8b8044ebcb2cd295751a9"
FlipKickBlockNumber = int64(10)
TendData = "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000003200000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a0920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b6db414"
TendTransactionHash = "0xadeddf804e0fef88b6145807df063c538c9942df2725a0458a084900c0fbf5e9"
TendBlockHash = "0xdd6238b841c8cf4d91b05da7540b7f0851176fcc8477cdc4b75c93e28dfe0a88"
TendBlockNumber = int64(11)
)
+15 -16
View File
@@ -15,21 +15,16 @@
package test_data
import (
"encoding/json"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"math/big"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flip_kick"
"time"
)
var (
TemporaryFlipBlockNumber = int64(10)
TemporaryFlipAddress = "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d"
TemporaryFlipKickBlockHash = "0x32f8b12023b3a1b4c73f9a46da976931b0355714ada8b8044ebcb2cd295751a9"
TemporaryFlipKickData = "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000008cb6176addcca2e1d1ffe21bee464b72ee4cd8d00000000000000000000000038219779a699d67d7e7740b8c8f43d3e2dae218266616b6520696c6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a09200000000000000000000000007fa9ef6609ca7921112231f8f195138ebba2977000000000000000000000000000000000000000000000000000000005b69b8e7000000000000000000000000000000000000000000000000000000005b607e670000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca0000000000000000000000000000000000000000000000000000000000000032"
TemporaryFlipKickTransaction = "0x6b155a55fd77b751195deeebf7abfd8691ca01ee588817a920f19d5b27f65191"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
)
var idString = "1"
@@ -48,15 +43,17 @@ var era = int64(1533050471)
var lad = "0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca"
var tabString = "50"
var tab, _ = new(big.Int).SetString(tabString, 10)
var rawLogJson, _ = json.Marshal(EthFlipKickLog)
var rawLogString = string(rawLogJson)
var EthFlipKickLog = types.Log{
Address: common.HexToAddress(TemporaryFlipAddress),
Topics: []common.Hash{common.HexToHash(flip_kick.FlipKickSignature)},
Data: hexutil.MustDecode(TemporaryFlipKickData),
BlockNumber: uint64(TemporaryFlipBlockNumber),
TxHash: common.HexToHash(TemporaryFlipKickTransaction),
Address: common.HexToAddress(FlipAddress),
Topics: []common.Hash{common.HexToHash(shared.FlipKickSignature)},
Data: hexutil.MustDecode(FlipKickData),
BlockNumber: uint64(FlipKickBlockNumber),
TxHash: common.HexToHash(FlipKickTransactionHash),
TxIndex: 0,
BlockHash: common.HexToHash(TemporaryFlipKickBlockHash),
BlockHash: common.HexToHash(FlipKickBlockHash),
Index: 0,
Removed: false,
}
@@ -74,6 +71,7 @@ var FlipKickEntity = flip_kick.FlipKickEntity{
Era: big.NewInt(era),
Lad: common.HexToAddress(lad),
Tab: tab,
Raw: EthFlipKickLog,
}
var FlipKickModel = flip_kick.FlipKickModel{
@@ -89,6 +87,7 @@ var FlipKickModel = flip_kick.FlipKickModel{
Era: time.Unix(era, 0),
Lad: lad,
Tab: tabString,
Raw: rawLogString,
}
type FlipKickDBRow struct {
@@ -0,0 +1,46 @@
// 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 tend
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)
type MockTendConverter struct {
ConverterContract string
ConverterAbi string
LogsToConvert []types.Log
EntitiesToConvert []tend.TendEntity
ConverterError error
}
func (c *MockTendConverter) ToEntity(contractAddress string, contractAbi string, ethLog types.Log) (tend.TendEntity, error) {
c.ConverterContract = contractAddress
c.ConverterAbi = contractAbi
c.LogsToConvert = append(c.LogsToConvert, ethLog)
return test_data.TendEntity, c.ConverterError
}
func (c *MockTendConverter) ToModel(entity tend.TendEntity) (tend.TendModel, error) {
c.EntitiesToConvert = append(c.EntitiesToConvert, entity)
return test_data.TendModel, c.ConverterError
}
func (c *MockTendConverter) SetConverterError(err error) {
c.ConverterError = err
}
@@ -0,0 +1,54 @@
// 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 tend
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
)
type MockTendRepository struct {
createError error
PassedEndingBlockNumber int64
PassedHeaderID int64
PassedStartingBlockNumber int64
PassedTendModel tend.TendModel
missingHeaders []core.Header
missingHeadersErr error
}
func (repository *MockTendRepository) Create(headerId int64, tend tend.TendModel) error {
repository.PassedHeaderID = headerId
repository.PassedTendModel = tend
return repository.createError
}
func (repository *MockTendRepository) SetCreateError(err error) {
repository.createError = err
}
func (repository *MockTendRepository) SetMissingHeadersErr(err error) {
repository.missingHeadersErr = err
}
func (repository *MockTendRepository) SetMissingHeaders(headers []core.Header) {
repository.missingHeaders = headers
}
func (repository *MockTendRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
repository.PassedStartingBlockNumber = startingBlockNumber
repository.PassedEndingBlockNumber = endingBlockNumber
return repository.missingHeaders, repository.missingHeadersErr
}
+72
View File
@@ -0,0 +1,72 @@
// 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 test_data
import (
"encoding/json"
"math/big"
"strconv"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
)
var tendLot = big.NewInt(100)
var tendBid = big.NewInt(50)
var tendGuy = common.HexToAddress("0x64d922894153be9eef7b7218dc565d1d0ce2a092")
var tic = new(big.Int).SetBytes([]byte{0})
var tendEra = big.NewInt(1533916180)
var RawJson, _ = json.Marshal(TendLog)
var rawString = string(RawJson)
var TendLog = types.Log{
Address: common.HexToAddress(FlipAddress),
Topics: []common.Hash{common.HexToHash(shared.TendSignature)},
Data: hexutil.MustDecode(TendData),
BlockNumber: uint64(TendBlockNumber),
TxHash: common.HexToHash(TendTransactionHash),
TxIndex: 1,
BlockHash: common.HexToHash(TendBlockHash),
Index: 0,
Removed: false,
}
var tendId = int64(1)
var TendEntity = tend.TendEntity{
Id: big.NewInt(tendId),
Lot: tendLot,
Bid: tendBid,
Guy: tendGuy,
Tic: tic,
Era: tendEra,
TransactionIndex: TendLog.TxIndex,
Raw: TendLog,
}
var TendModel = tend.TendModel{
Id: strconv.FormatInt(tendId, 10),
Lot: tendLot.String(),
Bid: tendBid.String(),
Guy: tendGuy[:],
Tic: tic.String(),
Era: time.Unix(tendEra.Int64(), 0),
TransactionIndex: TendLog.TxIndex,
Raw: rawString,
}