Convert and persist LogNote events as dent records
This commit is contained in:
Elizabeth
2018-09-11 14:01:45 -05:00
committed by GitHub
parent d4a4748246
commit 9abe3ffa68
29 changed files with 1116 additions and 49 deletions
+64
View File
@@ -0,0 +1,64 @@
// 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/dent"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"strconv"
)
var (
DentData = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000645ff3a382000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000098a7d9b8314c000000000000000000000000000000000000000000000000000029a2241af62c0000"
DentTransactionHash = "0x5a210319fcd31eea5959fedb4a1b20881c21a21976e23ff19dff3b44cc1c71e8"
DentBlockHash = "0x105b771e04d7b8516f9291b1f006c46c09cfbff9efa8bc52498b171ff99d28b5"
dentBidId = int64(1)
dentLot = "11000000000000000000"
dentBid = "3000000000000000000"
DentTic = "0"
dentGuy = "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092"
dentRawJson, _ = json.Marshal(DentLog)
)
var DentLog = types.Log{
Address: common.StringToAddress(shared.FlipperContractAddress),
Topics: []common.Hash{
common.HexToHash("0x5ff3a38200000000000000000000000000000000000000000000000000000000"),
common.HexToHash("0x00000000000000000000000064d922894153be9eef7b7218dc565d1d0ce2a092"),
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001"),
common.HexToHash("0x00000000000000000000000000000000000000000000000098a7d9b8314c0000"),
},
Data: hexutil.MustDecode(DentData),
BlockNumber: 15,
TxHash: common.HexToHash(DentTransactionHash),
TxIndex: 5,
BlockHash: common.HexToHash(DentBlockHash),
Index: 2,
Removed: false,
}
var DentModel = dent.DentModel{
BidId: strconv.FormatInt(dentBidId, 10),
Lot: dentLot,
Bid: dentBid,
Guy: dentGuy,
Tic: DentTic,
TransactionIndex: DentLog.TxIndex,
Raw: dentRawJson,
}
@@ -0,0 +1,40 @@
// 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 dent
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/vulcanize/vulcanizedb/pkg/transformers/dent"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
)
type MockDentConverter struct {
converterError error
PassedContractAddress string
PassedContractAbi string
LogsToConvert []types.Log
}
func (c *MockDentConverter) Convert(contractAddress string, contractAbi string, ethLog types.Log) (dent.DentModel, error) {
c.PassedContractAddress = contractAddress
c.PassedContractAbi = contractAbi
c.LogsToConvert = append(c.LogsToConvert, ethLog)
return test_data.DentModel, c.converterError
}
func (c *MockDentConverter) SetConverterError(err error) {
c.converterError = err
}
@@ -0,0 +1,56 @@
// 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 dent
import (
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/transformers/dent"
)
type MockDentRepository struct {
PassedStartingBlockNumber int64
PassedEndingBlockNumber int64
PassedDentModels []dent.DentModel
PassedHeaderIds []int64
missingHeaders []core.Header
missingHeadersError error
createError error
}
func (r *MockDentRepository) Create(headerId int64, model dent.DentModel) error {
r.PassedHeaderIds = append(r.PassedHeaderIds, headerId)
r.PassedDentModels = append(r.PassedDentModels, model)
return r.createError
}
func (r *MockDentRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
r.PassedStartingBlockNumber = startingBlockNumber
r.PassedEndingBlockNumber = endingBlockNumber
return r.missingHeaders, r.missingHeadersError
}
func (r *MockDentRepository) SetMissingHeadersError(err error) {
r.missingHeadersError = err
}
func (r *MockDentRepository) SetMissingHeaders(headers []core.Header) {
r.missingHeaders = headers
}
func (r *MockDentRepository) SetCreateError(err error) {
r.createError = err
}
+4 -5
View File
@@ -16,7 +16,6 @@ package test_data
import (
"encoding/json"
"math/big"
"strconv"
"github.com/ethereum/go-ethereum/common"
@@ -28,14 +27,14 @@ import (
)
var (
tendId = int64(10)
tendBidId = int64(10)
tendLot = "85000000000000000000"
tendBid = "1000000000000000000"
tendGuy = "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6"
tic = new(big.Int).SetBytes([]byte{0})
tendData = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000644b43ed12000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000049b9ca9a6943400000000000000000000000000000000000000000000000000000de0b6b3a7640000"
tendTransactionHash = "0x7909c8793ded2b8348f5db623044fbc26bb7ab78ad5792897abdf68ddc1df63d"
tendBlockHash = "0xa8ea87147c0a68daeb6b1d9f8c0937ba975a650809cab80d19c969e8d0df452c"
TendTic = "0"
)
var TendLogNote = types.Log{
@@ -57,11 +56,11 @@ var TendLogNote = types.Log{
var RawLogNoteJson, _ = json.Marshal(TendLogNote)
var TendModel = tend.TendModel{
BidId: strconv.FormatInt(tendId, 10),
BidId: strconv.FormatInt(tendBidId, 10),
Lot: tendLot,
Bid: tendBid,
Guy: tendGuy,
Tic: tic.String(),
Tic: TendTic,
TransactionIndex: TendLogNote.TxIndex,
Raw: string(RawLogNoteJson),
}