2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
package fakes
|
|
|
|
|
2018-10-11 20:25:14 +00:00
|
|
|
import (
|
2019-03-19 19:11:26 +00:00
|
|
|
"bytes"
|
2018-10-11 20:25:14 +00:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2018-11-12 20:59:16 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-10-11 20:25:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2019-08-26 21:43:14 +00:00
|
|
|
"math/rand"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
2018-10-11 20:25:14 +00:00
|
|
|
)
|
2018-07-18 20:59:40 +00:00
|
|
|
|
2018-11-12 20:59:16 +00:00
|
|
|
var (
|
2019-08-26 21:43:14 +00:00
|
|
|
FakeAddress = common.HexToAddress("0x" + RandomString(40))
|
2018-11-15 11:57:29 +00:00
|
|
|
FakeError = errors.New("failed")
|
|
|
|
FakeHash = common.BytesToHash([]byte{1, 2, 3, 4, 5})
|
2019-09-13 16:20:13 +00:00
|
|
|
fakeTimestamp = rand.Int63n(1500000000)
|
2018-11-12 20:59:16 +00:00
|
|
|
)
|
2018-10-11 20:25:14 +00:00
|
|
|
|
|
|
|
var rawFakeHeader, _ = json.Marshal(types.Header{})
|
|
|
|
var FakeHeader = core.Header{
|
2018-11-12 20:59:16 +00:00
|
|
|
Hash: FakeHash.String(),
|
2018-10-11 20:25:14 +00:00
|
|
|
Raw: rawFakeHeader,
|
2018-11-15 11:57:29 +00:00
|
|
|
Timestamp: strconv.FormatInt(fakeTimestamp, 10),
|
2018-10-11 20:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetFakeHeader(blockNumber int64) core.Header {
|
2019-04-09 22:06:33 +00:00
|
|
|
return GetFakeHeaderWithTimestamp(fakeTimestamp, blockNumber)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetFakeHeaderWithTimestamp(timestamp, blockNumber int64) core.Header {
|
2018-10-11 20:25:14 +00:00
|
|
|
return core.Header{
|
2018-11-12 20:59:16 +00:00
|
|
|
Hash: FakeHash.String(),
|
2018-10-11 20:25:14 +00:00
|
|
|
BlockNumber: blockNumber,
|
|
|
|
Raw: rawFakeHeader,
|
2019-04-09 22:06:33 +00:00
|
|
|
Timestamp: strconv.FormatInt(timestamp, 10),
|
2018-10-11 20:25:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-19 19:11:26 +00:00
|
|
|
|
|
|
|
var fakeTransaction types.Transaction
|
|
|
|
var rawTransaction bytes.Buffer
|
|
|
|
var _ = fakeTransaction.EncodeRLP(&rawTransaction)
|
2019-03-27 04:05:30 +00:00
|
|
|
var FakeTransaction = core.TransactionModel{
|
|
|
|
Data: []byte{},
|
2019-03-19 19:11:26 +00:00
|
|
|
From: "",
|
|
|
|
GasLimit: 0,
|
|
|
|
GasPrice: 0,
|
|
|
|
Hash: "",
|
|
|
|
Nonce: 0,
|
|
|
|
Raw: rawTransaction.Bytes(),
|
|
|
|
Receipt: core.Receipt{},
|
|
|
|
To: "",
|
|
|
|
TxIndex: 0,
|
|
|
|
Value: "0",
|
|
|
|
}
|
|
|
|
|
2019-03-27 04:05:30 +00:00
|
|
|
func GetFakeTransaction(hash string, receipt core.Receipt) core.TransactionModel {
|
2019-03-19 19:11:26 +00:00
|
|
|
gethTransaction := types.Transaction{}
|
|
|
|
var raw bytes.Buffer
|
|
|
|
err := gethTransaction.EncodeRLP(&raw)
|
|
|
|
if err != nil {
|
2019-04-02 18:30:15 +00:00
|
|
|
panic("failed to marshal transaction while creating test fake")
|
2019-03-19 19:11:26 +00:00
|
|
|
}
|
2019-03-27 04:05:30 +00:00
|
|
|
return core.TransactionModel{
|
|
|
|
Data: []byte{},
|
2019-03-19 19:11:26 +00:00
|
|
|
From: "",
|
|
|
|
GasLimit: 0,
|
|
|
|
GasPrice: 0,
|
|
|
|
Hash: hash,
|
|
|
|
Nonce: 0,
|
|
|
|
Raw: raw.Bytes(),
|
|
|
|
Receipt: receipt,
|
|
|
|
To: "",
|
|
|
|
TxIndex: 0,
|
|
|
|
Value: "0",
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 18:30:15 +00:00
|
|
|
|
|
|
|
func GetFakeUncle(hash, reward string) core.Uncle {
|
|
|
|
return core.Uncle{
|
|
|
|
Miner: FakeAddress.String(),
|
|
|
|
Hash: hash,
|
|
|
|
Reward: reward,
|
|
|
|
Raw: rawFakeHeader,
|
|
|
|
Timestamp: strconv.FormatInt(fakeTimestamp, 10),
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 21:43:14 +00:00
|
|
|
|
|
|
|
func RandomString(length int) string {
|
|
|
|
var seededRand = rand.New(
|
|
|
|
rand.NewSource(time.Now().UnixNano()))
|
|
|
|
charset := "abcdef1234567890"
|
|
|
|
b := make([]byte, length)
|
|
|
|
for i := range b {
|
|
|
|
b[i] = charset[seededRand.Intn(len(charset))]
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(b)
|
|
|
|
}
|