Merge pull request #361 from cerc-io/ian/v5_dev
use large balances in unit tests
This commit is contained in:
commit
9ba52345df
6
go.mod
6
go.mod
@ -81,6 +81,11 @@ require (
|
||||
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jackc/pgtype v1.8.1
|
||||
github.com/shopspring/decimal v1.2.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect
|
||||
@ -112,7 +117,6 @@ require (
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.1.1 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||
github.com/jackc/pgtype v1.8.1 // indirect
|
||||
github.com/jackc/puddle v1.1.3 // indirect
|
||||
github.com/klauspost/compress v1.15.15 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
|
@ -20,7 +20,10 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/jackc/pgtype"
|
||||
shopspring "github.com/jackc/pgtype/ext/shopspring-numeric"
|
||||
"github.com/lib/pq"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/database/metrics"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/models"
|
||||
@ -96,13 +99,17 @@ INSERT INTO eth.transaction_cids (block_number, header_id, tx_hash, cid, dst, sr
|
||||
ON CONFLICT (tx_hash, header_id, block_number) DO NOTHING
|
||||
*/
|
||||
func (w *Writer) upsertTransactionCID(tx Tx, transaction models.TxModel) error {
|
||||
val := transaction.Value
|
||||
if val == "" {
|
||||
val = "0"
|
||||
}
|
||||
if w.useCopyForTx(tx) {
|
||||
blockNum, err := strconv.ParseInt(transaction.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return insertError{"eth.transaction_cids", err, "COPY", transaction}
|
||||
}
|
||||
|
||||
value, err := strconv.ParseFloat(transaction.Value, 64)
|
||||
value, err := toNumeric(val)
|
||||
if err != nil {
|
||||
return insertError{"eth.transaction_cids", err, "COPY", transaction}
|
||||
}
|
||||
@ -138,7 +145,7 @@ ON CONFLICT (tx_id, header_id, block_number) DO NOTHING
|
||||
*/
|
||||
func (w *Writer) upsertReceiptCID(tx Tx, rct *models.ReceiptModel) error {
|
||||
if w.useCopyForTx(tx) {
|
||||
blockNum, err := strconv.ParseInt(rct.BlockNumber, 10, 64)
|
||||
blockNum, err := strconv.ParseUint(rct.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return insertError{"eth.receipt_cids", err, "COPY", rct}
|
||||
}
|
||||
@ -174,7 +181,7 @@ func (w *Writer) upsertLogCID(tx Tx, logs []*models.LogsModel) error {
|
||||
if w.useCopyForTx(tx) {
|
||||
var rows [][]interface{}
|
||||
for _, log := range logs {
|
||||
blockNum, err := strconv.ParseInt(log.BlockNumber, 10, 64)
|
||||
blockNum, err := strconv.ParseUint(log.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return insertError{"eth.log_cids", err, "COPY", log}
|
||||
}
|
||||
@ -216,24 +223,25 @@ INSERT INTO eth.state_cids (block_number, header_id, state_leaf_key, cid, remove
|
||||
ON CONFLICT (header_id, state_leaf_key, block_number) DO NOTHING
|
||||
*/
|
||||
func (w *Writer) upsertStateCID(tx Tx, stateNode models.StateNodeModel) error {
|
||||
balance := stateNode.Balance
|
||||
bal := stateNode.Balance
|
||||
if stateNode.Removed {
|
||||
balance = "0"
|
||||
bal = "0"
|
||||
}
|
||||
|
||||
if w.useCopyForTx(tx) {
|
||||
blockNum, err := strconv.ParseInt(stateNode.BlockNumber, 10, 64)
|
||||
blockNum, err := strconv.ParseUint(stateNode.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return insertError{"eth.state_cids", err, "COPY", stateNode}
|
||||
}
|
||||
balInt, err := strconv.ParseInt(balance, 10, 64)
|
||||
|
||||
balance, err := toNumeric(bal)
|
||||
if err != nil {
|
||||
return insertError{"eth.state_cids", err, "COPY", stateNode}
|
||||
}
|
||||
|
||||
_, err = tx.CopyFrom(w.db.Context(), w.db.StateTableName(), w.db.StateColumnNames(),
|
||||
toRows(toRow(blockNum, stateNode.HeaderID, stateNode.StateKey, stateNode.CID,
|
||||
true, balInt, stateNode.Nonce, stateNode.CodeHash, stateNode.StorageRoot, stateNode.Removed)))
|
||||
true, balance, stateNode.Nonce, stateNode.CodeHash, stateNode.StorageRoot, stateNode.Removed)))
|
||||
if err != nil {
|
||||
return insertError{"eth.state_cids", err, "COPY", stateNode}
|
||||
}
|
||||
@ -244,7 +252,7 @@ func (w *Writer) upsertStateCID(tx Tx, stateNode models.StateNodeModel) error {
|
||||
stateNode.StateKey,
|
||||
stateNode.CID,
|
||||
true,
|
||||
balance,
|
||||
bal,
|
||||
stateNode.Nonce,
|
||||
stateNode.CodeHash,
|
||||
stateNode.StorageRoot,
|
||||
@ -263,7 +271,7 @@ ON CONFLICT (header_id, state_leaf_key, storage_leaf_key, block_number) DO NOTHI
|
||||
*/
|
||||
func (w *Writer) upsertStorageCID(tx Tx, storageCID models.StorageNodeModel) error {
|
||||
if w.useCopyForTx(tx) {
|
||||
blockNum, err := strconv.ParseInt(storageCID.BlockNumber, 10, 64)
|
||||
blockNum, err := strconv.ParseUint(storageCID.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return insertError{"eth.storage_cids", err, "COPY", storageCID}
|
||||
}
|
||||
@ -308,6 +316,15 @@ func toRow(args ...interface{}) []interface{} {
|
||||
return row
|
||||
}
|
||||
|
||||
func toNumeric(value string) (*shopspring.Numeric, error) {
|
||||
decimalValue, err := decimal.NewFromString(value)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &shopspring.Numeric{Decimal: decimalValue, Status: pgtype.Present}, nil
|
||||
}
|
||||
|
||||
// combine row (or rows) into a slice of rows for CopyFrom
|
||||
func toRows(rows ...[]interface{}) [][]interface{} {
|
||||
return rows
|
||||
|
@ -182,9 +182,10 @@ var (
|
||||
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
|
||||
AccountLeafKey = test_helpers.Account2LeafKey
|
||||
RemovedLeafKey = test_helpers.Account1LeafKey
|
||||
Balance, _ = new(big.Int).SetString("106387458790507306766", 10)
|
||||
Account = &types.StateAccount{
|
||||
Nonce: nonce0,
|
||||
Balance: big.NewInt(1000),
|
||||
Balance: Balance,
|
||||
CodeHash: AccountCodeHash.Bytes(),
|
||||
Root: common.HexToHash(AccountRoot),
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ func TestPublishAndIndexStateIPLDs(t *testing.T, db sql.Database) {
|
||||
require.Equal(t, common.BytesToHash(mocks.AccountLeafKey).Hex(), stateNode.StateKey)
|
||||
require.Equal(t, mocks.AccountLeafNode, data)
|
||||
require.Equal(t, mocks.BlockNumber.String(), stateNode.BlockNumber)
|
||||
require.Equal(t, "1000", stateNode.Balance)
|
||||
require.Equal(t, mocks.Balance.String(), stateNode.Balance)
|
||||
require.Equal(t, mocks.AccountCodeHash.String(), stateNode.CodeHash)
|
||||
require.Equal(t, mocks.AccountRoot, stateNode.StorageRoot)
|
||||
require.Equal(t, uint64(0), stateNode.Nonce)
|
||||
|
Loading…
Reference in New Issue
Block a user