Flop kick (#28)

* FlopKick transformer
This commit is contained in:
Elizabeth
2018-09-26 09:42:52 -05:00
committed by GitHub
parent a0ba6ca6bd
commit 31516ea87e
25 changed files with 1247 additions and 100 deletions
+78
View File
@@ -0,0 +1,78 @@
// 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"
"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/flop_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"math/big"
"strconv"
"time"
)
var (
FlopKickLog = types.Log{
Address: common.HexToAddress(shared.FlopperContractAddress),
Topics: []common.Hash{
common.HexToHash("0xefa52d9342a199cb30efd2692463f2c2bef63cd7186b50382d4fb94ad207880e"),
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000005"),
},
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000f00000000000000000000000000000000000000000000000000000000000000020000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000000000000000000000000000000000000002a300"),
BlockNumber: 19,
TxHash: common.HexToHash("0xd8fd67b37a6aa64a3cef4937204765183b180d8dc92eecd0d233f445526d31b5"),
TxIndex: flopTxIndex,
BlockHash: common.HexToHash("0x7891fe725691abc5b94113dc2bfa8c3509e1e1d0e0bb74289e3b996c30d00c8c"),
Index: 32,
Removed: false,
}
flopTxIndex = uint(33)
flopBidId = int64(5)
flopLot = int64(15)
flopBid = int64(2)
flopGal = "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6"
rawFlopLogJson, _ = json.Marshal(FlopKickLog)
flopEnd = int64(172800)
FlopKickEntity = flop_kick.Entity{
Id: big.NewInt(flopBidId),
Lot: big.NewInt(flopLot),
Bid: big.NewInt(flopBid),
Gal: common.HexToAddress(flopGal),
End: big.NewInt(flopEnd),
TransactionIndex: flopTxIndex,
Raw: FlopKickLog,
}
FlopKickModel = flop_kick.Model{
BidId: strconv.FormatInt(flopBidId, 10),
Lot: strconv.FormatInt(flopLot, 10),
Bid: strconv.FormatInt(flopBid, 10),
Gal: flopGal,
End: time.Unix(flopEnd, 0),
TransactionIndex: flopTxIndex,
Raw: rawFlopLogJson,
}
)
type FlopKickDBResult struct {
Id int64
HeaderId int64 `db:"header_id"`
flop_kick.Model
}
@@ -0,0 +1,51 @@
// 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 flop_kick
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flop_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)
type MockConverter struct {
PassedContractAddress string
PassedContractABI string
PassedLogs []types.Log
PassedEntities []flop_kick.Entity
entityConverterError error
modelConverterError error
}
func (c *MockConverter) ToEntities(contractAddress, contractAbi string, ethLogs []types.Log) ([]flop_kick.Entity, error) {
c.PassedContractAddress = contractAddress
c.PassedContractABI = contractAbi
c.PassedLogs = ethLogs
return []flop_kick.Entity{test_data.FlopKickEntity}, c.entityConverterError
}
func (c *MockConverter) ToModels(entities []flop_kick.Entity) ([]flop_kick.Model, error) {
c.PassedEntities = entities
return []flop_kick.Model{test_data.FlopKickModel}, c.modelConverterError
}
func (c *MockConverter) SetToEntityConverterError(err error) {
c.entityConverterError = err
}
func (c *MockConverter) SetToModelConverterError(err error) {
c.modelConverterError = err
}
@@ -0,0 +1,68 @@
// 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 flop_kick
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flop_kick"
)
type MockRepository struct {
PassedStartingBlockNumber int64
PassedEndingBlockNumber int64
CreatedHeaderIds []int64
CreatedModels []flop_kick.Model
CheckedHeaderIds []int64
missingHeaders []core.Header
missingHeadersError error
createError error
checkedHeaderError error
}
func (r *MockRepository) Create(headerId int64, flopKicks []flop_kick.Model) error {
r.CreatedHeaderIds = append(r.CreatedHeaderIds, headerId)
r.CreatedModels = flopKicks
return r.createError
}
func (r *MockRepository) MarkHeaderChecked(headerId int64) error {
r.CheckedHeaderIds = append(r.CheckedHeaderIds, headerId)
return r.checkedHeaderError
}
func (r *MockRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
r.PassedStartingBlockNumber = startingBlockNumber
r.PassedEndingBlockNumber = endingBlockNumber
return r.missingHeaders, r.missingHeadersError
}
func (r *MockRepository) SetMissingHeaders(headers []core.Header) {
r.missingHeaders = headers
}
func (r *MockRepository) SetMissingHeadersError(err error) {
r.missingHeadersError = err
}
func (r *MockRepository) SetCreateError(err error) {
r.createError = err
}
func (r *MockRepository) SetCheckedHeaderError(err error) {
r.checkedHeaderError = err
}