Cleanups
This commit is contained in:
parent
fdb330eb58
commit
439b4c6e22
@ -364,14 +364,7 @@ func (h *EthHash) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func decodeHexString(s string, expectedLen int) ([]byte, error) {
|
func decodeHexString(s string, expectedLen int) ([]byte, error) {
|
||||||
// Strip the leading 0x or 0X prefix since hex.DecodeString does not support it.
|
s = handleHexStringPrefix(s)
|
||||||
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
|
||||||
s = s[2:]
|
|
||||||
}
|
|
||||||
// Sometimes clients will omit a leading zero in a byte; pad so we can decode correctly.
|
|
||||||
if len(s)%2 == 1 {
|
|
||||||
s = "0" + s
|
|
||||||
}
|
|
||||||
if len(s) != expectedLen*2 {
|
if len(s) != expectedLen*2 {
|
||||||
return nil, xerrors.Errorf("expected hex string length sans prefix %d, got %d", expectedLen*2, len(s))
|
return nil, xerrors.Errorf("expected hex string length sans prefix %d, got %d", expectedLen*2, len(s))
|
||||||
}
|
}
|
||||||
@ -382,6 +375,27 @@ func decodeHexString(s string, expectedLen int) ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeHexString(s string) ([]byte, error) {
|
||||||
|
s = handleHexStringPrefix(s)
|
||||||
|
b, err := hex.DecodeString(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("cannot parse hex value: %w", err)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleHexStringPrefix(s string) string {
|
||||||
|
// Strip the leading 0x or 0X prefix since hex.DecodeString does not support it.
|
||||||
|
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
||||||
|
s = s[2:]
|
||||||
|
}
|
||||||
|
// Sometimes clients will omit a leading zero in a byte; pad so we can decode correctly.
|
||||||
|
if len(s)%2 == 1 {
|
||||||
|
s = "0" + s
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func EthHashFromCid(c cid.Cid) (EthHash, error) {
|
func EthHashFromCid(c cid.Cid) (EthHash, error) {
|
||||||
return ParseEthHash(c.Hash().HexString()[8:])
|
return ParseEthHash(c.Hash().HexString()[8:])
|
||||||
}
|
}
|
||||||
|
10
cli/evm.go
10
cli/evm.go
@ -121,7 +121,7 @@ var EvmCallSimulateCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err := hex.DecodeString(cctx.Args().Get(2))
|
params, err := ethtypes.DecodeHexString(cctx.Args().Get(2))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ var EvmGetContractAddress = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
salt, err := hex.DecodeString(cctx.Args().Get(1))
|
salt, err := ethtypes.DecodeHexString(cctx.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("Could not decode salt: %w", err)
|
return xerrors.Errorf("Could not decode salt: %w", err)
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ var EvmGetContractAddress = &cli.Command{
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
contract, err := hex.DecodeString(string(contractHex))
|
contract, err := ethtypes.DecodeHexString(string(contractHex))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("Could not decode contract file: %w", err)
|
return xerrors.Errorf("Could not decode contract file: %w", err)
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ var EvmDeployCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("failed to read contract: %w", err)
|
return xerrors.Errorf("failed to read contract: %w", err)
|
||||||
}
|
}
|
||||||
if cctx.Bool("hex") {
|
if cctx.Bool("hex") {
|
||||||
contract, err = hex.DecodeString(string(contract))
|
contract, err = ethtypes.DecodeHexString(string(contract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to decode contract: %w", err)
|
return xerrors.Errorf("failed to decode contract: %w", err)
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ var EvmInvokeCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var calldata []byte
|
var calldata []byte
|
||||||
calldata, err = hex.DecodeString(cctx.Args().Get(1))
|
calldata, err = ethtypes.DecodeHexString(cctx.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("decoding hex input data: %w", err)
|
return xerrors.Errorf("decoding hex input data: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -776,7 +776,9 @@ var StateGetActorCmd = &cli.Command{
|
|||||||
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
|
fmt.Printf("Nonce:\t\t%d\n", a.Nonce)
|
||||||
fmt.Printf("Code:\t\t%s (%s)\n", a.Code, strtype)
|
fmt.Printf("Code:\t\t%s (%s)\n", a.Code, strtype)
|
||||||
fmt.Printf("Head:\t\t%s\n", a.Head)
|
fmt.Printf("Head:\t\t%s\n", a.Head)
|
||||||
fmt.Printf("Delegated address:\t\t%s\n", a.Address)
|
if a.Address != nil {
|
||||||
|
fmt.Printf("Delegated address:\t\t%s\n", a.Address)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,22 +46,22 @@ func TestFEVMEvents(t *testing.T) {
|
|||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
t.Logf("actor ID address is %s", idAddr)
|
t.Logf("actor ID address is %s", idAddr)
|
||||||
|
|
||||||
// var (
|
var (
|
||||||
// earliest = "earliest"
|
earliest = "earliest"
|
||||||
// latest = "latest"
|
latest = "latest"
|
||||||
// )
|
)
|
||||||
//
|
|
||||||
// // Install a filter.
|
// Install a filter.
|
||||||
// filter, err := client.EthNewFilter(ctx, &api.EthFilterSpec{
|
filter, err := client.EthNewFilter(ctx, ðtypes.EthFilterSpec{
|
||||||
// FromBlock: &earliest,
|
FromBlock: &earliest,
|
||||||
// ToBlock: &latest,
|
ToBlock: &latest,
|
||||||
// })
|
})
|
||||||
// require.NoError(err)
|
require.NoError(err)
|
||||||
//
|
|
||||||
// // No logs yet.
|
// No logs yet.
|
||||||
// res, err := client.EthGetFilterLogs(ctx, filter)
|
res, err := client.EthGetFilterLogs(ctx, filter)
|
||||||
// require.NoError(err)
|
require.NoError(err)
|
||||||
// require.Empty(res.NewLogs)
|
require.Empty(res.Results)
|
||||||
|
|
||||||
// log a zero topic event with data
|
// log a zero topic event with data
|
||||||
ret := client.EVM().InvokeSolidity(ctx, fromAddr, idAddr, []byte{0x00, 0x00, 0x00, 0x00}, nil)
|
ret := client.EVM().InvokeSolidity(ctx, fromAddr, idAddr, []byte{0x00, 0x00, 0x00, 0x00}, nil)
|
||||||
|
@ -351,13 +351,11 @@ func splitStorePruneIndex(ctx context.Context, t *testing.T, n *kit.TestFullNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ipldExists(ctx context.Context, t *testing.T, c cid.Cid, n *kit.TestFullNode) bool {
|
func ipldExists(ctx context.Context, t *testing.T, c cid.Cid, n *kit.TestFullNode) bool {
|
||||||
_, err := n.ChainReadObj(ctx, c)
|
found, err := n.ChainHasObj(ctx, c)
|
||||||
if ipld.IsNotFound(err) {
|
if err != nil {
|
||||||
return false
|
t.Fatalf("ChainHasObj failure: %s", err)
|
||||||
} else if err != nil {
|
|
||||||
t.Fatalf("ChainReadObj failure on existence check: %s", err)
|
|
||||||
}
|
}
|
||||||
return true
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create on chain unreachable garbage for a network to exercise splitstore
|
// Create on chain unreachable garbage for a network to exercise splitstore
|
||||||
@ -414,12 +412,10 @@ func (g *Garbager) Exists(ctx context.Context, c cid.Cid) bool {
|
|||||||
return false
|
return false
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
g.t.Fatalf("ChainReadObj failure on existence check: %s", err)
|
g.t.Fatalf("ChainReadObj failure on existence check: %s", err)
|
||||||
|
return false // unreachable
|
||||||
} else {
|
} else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
g.t.Fatal("unreachable")
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Garbager) newPeerID(ctx context.Context) abi.ChainEpoch {
|
func (g *Garbager) newPeerID(ctx context.Context) abi.ChainEpoch {
|
||||||
|
Loading…
Reference in New Issue
Block a user