forked from cerc-io/laconicd-deprecated
keeper: StateDB unit tests (#47)
* keeper: statedb unit tests * evm: balance tests * evm: nonce and code tests * evm: refund test * evm: fix tx encoding * storage and access list tests
This commit is contained in:
+7
-15
@@ -4,8 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
log "github.com/xlab/suplog"
|
||||
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
@@ -77,9 +75,9 @@ func (log *Log) Validate() error {
|
||||
|
||||
// ToEthereum returns the Ethereum type Log from a Ethermint-proto compatible Log.
|
||||
func (log *Log) ToEthereum() *ethtypes.Log {
|
||||
topics := make([]ethcmn.Hash, len(log.Topics))
|
||||
var topics []ethcmn.Hash // nolint: prealloc
|
||||
for i := range log.Topics {
|
||||
topics[i] = ethcmn.HexToHash(log.Topics[i])
|
||||
topics = append(topics, ethcmn.HexToHash(log.Topics[i]))
|
||||
}
|
||||
|
||||
return ðtypes.Log{
|
||||
@@ -97,24 +95,18 @@ func (log *Log) ToEthereum() *ethtypes.Log {
|
||||
|
||||
// LogsToEthereum casts the Ethermint Logs to a slice of Ethereum Logs.
|
||||
func LogsToEthereum(logs []*Log) []*ethtypes.Log {
|
||||
ethLogs := make([]*ethtypes.Log, len(logs))
|
||||
var ethLogs []*ethtypes.Log // nolint: prealloc
|
||||
for i := range logs {
|
||||
err := logs[i].Validate()
|
||||
if err != nil {
|
||||
log.WithError(err).Errorln("failed log validation", logs[i].String())
|
||||
continue
|
||||
}
|
||||
|
||||
ethLogs[i] = logs[i].ToEthereum()
|
||||
ethLogs = append(ethLogs, logs[i].ToEthereum())
|
||||
}
|
||||
return ethLogs
|
||||
}
|
||||
|
||||
// NewLogFromEth creates a new Log instance from a Ethereum type Log.
|
||||
func NewLogFromEth(log *ethtypes.Log) *Log {
|
||||
topics := make([]string, len(log.Topics))
|
||||
for i := range log.Topics {
|
||||
topics[i] = log.Topics[i].String()
|
||||
var topics []string // nolint: prealloc
|
||||
for _, topic := range log.Topics {
|
||||
topics = append(topics, topic.String())
|
||||
}
|
||||
|
||||
return &Log{
|
||||
|
||||
+3
-3
@@ -89,7 +89,7 @@ func newMsgEthereumTx(
|
||||
}
|
||||
|
||||
// fromEthereumTx populates the message fields from the given ethereum transaction
|
||||
func (msg *MsgEthereumTx) fromEthereumTx(tx *ethtypes.Transaction) {
|
||||
func (msg *MsgEthereumTx) FromEthereumTx(tx *ethtypes.Transaction) {
|
||||
to := ""
|
||||
if tx.To() != nil {
|
||||
to = tx.To().Hex()
|
||||
@@ -227,7 +227,7 @@ func (msg *MsgEthereumTx) DecodeRLP(stream *rlp.Stream) error {
|
||||
return err
|
||||
}
|
||||
|
||||
msg.fromEthereumTx(tx)
|
||||
msg.FromEthereumTx(tx)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -258,7 +258,7 @@ func (msg *MsgEthereumTx) Sign(ethSigner ethtypes.Signer, keyringSigner keyring.
|
||||
return err
|
||||
}
|
||||
|
||||
msg.fromEthereumTx(tx)
|
||||
msg.FromEthereumTx(tx)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user