Merge branch 'release/v1.20.0' into fix/EthUint64-args
This commit is contained in:
commit
db749b8fc7
Binary file not shown.
Binary file not shown.
@ -13,13 +13,11 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||
"github.com/filecoin-project/lotus/chain/wallet/key"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
)
|
||||
|
||||
@ -69,11 +67,7 @@ func (ms *MessageSigner) SignMessage(ctx context.Context, msg *types.Message, sp
|
||||
// Sign the message with the nonce
|
||||
msg.Nonce = nonce
|
||||
|
||||
keyInfo, err := ms.wallet.WalletExport(ctx, msg.From)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sb, err := SigningBytes(msg, key.ActSigType(keyInfo.Type))
|
||||
sb, err := SigningBytes(msg, msg.From.Protocol())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -200,8 +194,8 @@ func (ms *MessageSigner) dstoreKey(addr address.Address) datastore.Key {
|
||||
return datastore.KeyWithNamespaces([]string{dsKeyActorNonce, addr.String()})
|
||||
}
|
||||
|
||||
func SigningBytes(msg *types.Message, sigType crypto.SigType) ([]byte, error) {
|
||||
if sigType == crypto.SigTypeDelegated {
|
||||
func SigningBytes(msg *types.Message, sigType address.Protocol) ([]byte, error) {
|
||||
if sigType == address.Delegated {
|
||||
txArgs, err := ethtypes.EthTxArgsFromUnsignedEthMessage(msg)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to reconstruct eth transaction: %w", err)
|
||||
|
@ -44,12 +44,12 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
|
||||
msg.Value = types.NewInt(0)
|
||||
}
|
||||
|
||||
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false)
|
||||
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, false)
|
||||
}
|
||||
|
||||
// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
|
||||
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*api.InvocResult, error) {
|
||||
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true)
|
||||
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, true)
|
||||
}
|
||||
|
||||
// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
|
||||
@ -61,13 +61,13 @@ func (sm *StateManager) CallAtStateAndVersion(ctx context.Context, msg *types.Me
|
||||
return v
|
||||
}
|
||||
|
||||
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true)
|
||||
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, false)
|
||||
}
|
||||
|
||||
// - If no tipset is specified, the first tipset without an expensive migration or one in its parent is used.
|
||||
// - If executing a message at a given tipset or its parent would trigger an expensive migration, the call will
|
||||
// fail with ErrExpensiveFork.
|
||||
func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid, nvGetter rand.NetworkVersionGetter, checkGas bool) (*api.InvocResult, error) {
|
||||
func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid, nvGetter rand.NetworkVersionGetter, checkGas, applyTsMessages bool) (*api.InvocResult, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "statemanager.callInternal")
|
||||
defer span.End()
|
||||
|
||||
@ -107,22 +107,18 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
|
||||
}
|
||||
}
|
||||
|
||||
var vmHeight abi.ChainEpoch
|
||||
if checkGas {
|
||||
// Since we're simulating a future message, pretend we're applying it in the "next" tipset
|
||||
vmHeight = ts.Height() + 1
|
||||
if stateCid == cid.Undef {
|
||||
stateCid, _, err = sm.TipSetState(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("computing tipset state: %w", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we're not checking gas, we don't want to have to execute the tipset like above. This saves a lot of computation time
|
||||
vmHeight = pts.Height() + 1
|
||||
if stateCid == cid.Undef {
|
||||
stateCid = ts.ParentState()
|
||||
// Unless executing on a specific state cid, apply all the messages from the current tipset
|
||||
// first. Unfortunately, we can't just execute the tipset, because that will run cron. We
|
||||
// don't want to apply miner messages after cron runs in a given epoch.
|
||||
if stateCid == cid.Undef {
|
||||
stateCid = ts.ParentState()
|
||||
}
|
||||
if applyTsMessages {
|
||||
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to lookup messages for parent tipset: %w", err)
|
||||
}
|
||||
priorMsgs = append(tsMsgs, priorMsgs...)
|
||||
}
|
||||
|
||||
// Technically, the tipset we're passing in here should be ts+1, but that may not exist.
|
||||
@ -142,14 +138,14 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
|
||||
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
|
||||
vmopt := &vm.VMOpts{
|
||||
StateBase: stateCid,
|
||||
Epoch: vmHeight,
|
||||
Epoch: ts.Height(),
|
||||
Timestamp: ts.MinTimestamp(),
|
||||
Rand: rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, nvGetter),
|
||||
Bstore: buffStore,
|
||||
Actors: sm.tsExec.NewActorRegistry(),
|
||||
Syscalls: sm.Syscalls,
|
||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||
NetworkVersion: nvGetter(ctx, vmHeight),
|
||||
NetworkVersion: nvGetter(ctx, ts.Height()),
|
||||
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
||||
TipSetGetter: TipSetGetterForTipset(sm.cs, ts),
|
||||
|
@ -25,13 +25,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/lib/must"
|
||||
)
|
||||
|
||||
var (
|
||||
EthTopic1 = "t1"
|
||||
EthTopic2 = "t2"
|
||||
EthTopic3 = "t3"
|
||||
EthTopic4 = "t4"
|
||||
)
|
||||
|
||||
var ErrInvalidAddress = errors.New("invalid Filecoin Eth address")
|
||||
|
||||
type EthUint64 uint64
|
||||
@ -637,7 +630,7 @@ type EthLog struct {
|
||||
Data EthBytes `json:"data"`
|
||||
|
||||
// List of topics associated with the event log.
|
||||
Topics []EthBytes `json:"topics"`
|
||||
Topics []EthHash `json:"topics"`
|
||||
|
||||
// Following fields are derived from the transaction containing the log
|
||||
|
||||
|
@ -222,7 +222,7 @@ func TestEthFilterResultMarshalJSON(t *testing.T) {
|
||||
TransactionHash: hash1,
|
||||
BlockHash: hash2,
|
||||
BlockNumber: 53,
|
||||
Topics: []EthBytes{hash1[:]},
|
||||
Topics: []EthHash{hash1},
|
||||
Data: EthBytes(hash1[:]),
|
||||
Address: addr,
|
||||
}
|
||||
|
@ -2790,7 +2790,7 @@ Response:
|
||||
"address": "0x5cbeecf99d3fdb3f25e309cc264f240bb0664031",
|
||||
"data": "0x07",
|
||||
"topics": [
|
||||
"0x07"
|
||||
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
|
||||
],
|
||||
"removed": true,
|
||||
"logIndex": "0x5",
|
||||
|
@ -285,31 +285,31 @@ func TestEthNewFilterDefaultSpec(t *testing.T) {
|
||||
expected := []ExpectedEthLog{
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
paddedEthBytes([]byte{0x11, 0x11}),
|
||||
paddedEthBytes([]byte{0x22, 0x22}),
|
||||
paddedEthBytes([]byte{0x33, 0x33}),
|
||||
paddedEthBytes([]byte{0x44, 0x44}),
|
||||
Topics: []ethtypes.EthHash{
|
||||
paddedEthHash([]byte{0x11, 0x11}),
|
||||
paddedEthHash([]byte{0x22, 0x22}),
|
||||
paddedEthHash([]byte{0x33, 0x33}),
|
||||
paddedEthHash([]byte{0x44, 0x44}),
|
||||
},
|
||||
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||
},
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
paddedEthBytes([]byte{0x11, 0x11}),
|
||||
paddedEthBytes([]byte{0x22, 0x22}),
|
||||
paddedEthBytes([]byte{0x33, 0x33}),
|
||||
paddedEthBytes([]byte{0x44, 0x44}),
|
||||
Topics: []ethtypes.EthHash{
|
||||
paddedEthHash([]byte{0x11, 0x11}),
|
||||
paddedEthHash([]byte{0x22, 0x22}),
|
||||
paddedEthHash([]byte{0x33, 0x33}),
|
||||
paddedEthHash([]byte{0x44, 0x44}),
|
||||
},
|
||||
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||
},
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
paddedEthBytes([]byte{0x11, 0x11}),
|
||||
paddedEthBytes([]byte{0x22, 0x22}),
|
||||
paddedEthBytes([]byte{0x33, 0x33}),
|
||||
paddedEthBytes([]byte{0x44, 0x44}),
|
||||
Topics: []ethtypes.EthHash{
|
||||
paddedEthHash([]byte{0x11, 0x11}),
|
||||
paddedEthHash([]byte{0x22, 0x22}),
|
||||
paddedEthHash([]byte{0x33, 0x33}),
|
||||
paddedEthHash([]byte{0x44, 0x44}),
|
||||
},
|
||||
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||
},
|
||||
@ -344,11 +344,11 @@ func TestEthGetLogsBasic(t *testing.T) {
|
||||
expected := []ExpectedEthLog{
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
paddedEthBytes([]byte{0x11, 0x11}),
|
||||
paddedEthBytes([]byte{0x22, 0x22}),
|
||||
paddedEthBytes([]byte{0x33, 0x33}),
|
||||
paddedEthBytes([]byte{0x44, 0x44}),
|
||||
Topics: []ethtypes.EthHash{
|
||||
paddedEthHash([]byte{0x11, 0x11}),
|
||||
paddedEthHash([]byte{0x22, 0x22}),
|
||||
paddedEthHash([]byte{0x33, 0x33}),
|
||||
paddedEthHash([]byte{0x44, 0x44}),
|
||||
},
|
||||
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||
},
|
||||
@ -409,11 +409,11 @@ func TestEthSubscribeLogsNoTopicSpec(t *testing.T) {
|
||||
for i := range expected {
|
||||
expected[i] = ExpectedEthLog{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
paddedEthBytes([]byte{0x11, 0x11}),
|
||||
paddedEthBytes([]byte{0x22, 0x22}),
|
||||
paddedEthBytes([]byte{0x33, 0x33}),
|
||||
paddedEthBytes([]byte{0x44, 0x44}),
|
||||
Topics: []ethtypes.EthHash{
|
||||
paddedEthHash([]byte{0x11, 0x11}),
|
||||
paddedEthHash([]byte{0x22, 0x22}),
|
||||
paddedEthHash([]byte{0x33, 0x33}),
|
||||
paddedEthHash([]byte{0x44, 0x44}),
|
||||
},
|
||||
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88},
|
||||
}
|
||||
@ -696,10 +696,10 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) {
|
||||
distinctHeights[m.ts.Height()] = true
|
||||
expectedByHeight[m.ts.Height()] = append(expectedByHeight[m.ts.Height()], ExpectedEthLog{
|
||||
Address: addr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(args[0]),
|
||||
paddedUint64(args[1]),
|
||||
uint64EthHash(args[0]),
|
||||
uint64EthHash(args[1]),
|
||||
},
|
||||
Data: paddedUint64(args[2]),
|
||||
})
|
||||
@ -762,7 +762,7 @@ func TestEthGetLogsWithBlockRanges(t *testing.T) {
|
||||
require.True(len(partition3.expected) > 0, "partition should have events")
|
||||
|
||||
// these are the topics we selected for partitioning earlier
|
||||
topics := []ethtypes.EthHash{paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])}
|
||||
topics := []ethtypes.EthHash{kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]}
|
||||
|
||||
union := func(lists ...[]ExpectedEthLog) []ExpectedEthLog {
|
||||
ret := []ExpectedEthLog{}
|
||||
@ -950,30 +950,30 @@ func TestEthNewFilterMergesHistoricWithRealtime(t *testing.T) {
|
||||
expected := []ExpectedEthLog{
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneData"],
|
||||
},
|
||||
Data: paddedUint64(1),
|
||||
},
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(2),
|
||||
uint64EthHash(2),
|
||||
},
|
||||
},
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneData"],
|
||||
},
|
||||
Data: paddedUint64(3),
|
||||
},
|
||||
{
|
||||
Address: ethContractAddr,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(4),
|
||||
uint64EthHash(4),
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -1364,19 +1364,19 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
return []filterTestCase{
|
||||
{
|
||||
name: "find all EventZeroData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventZeroData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventZeroData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventZeroData"],
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventZeroData"],
|
||||
},
|
||||
Data: nil,
|
||||
@ -1385,19 +1385,19 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventOneData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventOneData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneData"],
|
||||
},
|
||||
Data: packUint64Values(23),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneData"],
|
||||
},
|
||||
Data: packUint64Values(44),
|
||||
@ -1406,12 +1406,12 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventTwoData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventTwoData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoData"],
|
||||
},
|
||||
Data: packUint64Values(555, 666),
|
||||
@ -1420,12 +1420,12 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventThreeData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventThreeData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeData"],
|
||||
},
|
||||
Data: packUint64Values(1, 2, 3),
|
||||
@ -1434,14 +1434,14 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventOneIndexed events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexed"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventOneIndexed"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
@ -1449,24 +1449,24 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventTwoIndexed events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexed"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventTwoIndexed"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexed"],
|
||||
paddedUint64(40),
|
||||
paddedUint64(20),
|
||||
uint64EthHash(40),
|
||||
uint64EthHash(20),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
@ -1474,16 +1474,16 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventThreeIndexed events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeIndexed"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventThreeIndexed"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
@ -1491,30 +1491,30 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventOneIndexedWithData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexedWithData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventOneIndexedWithData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
uint64EthHash(46),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
uint64EthHash(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
@ -1522,33 +1522,33 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventTwoIndexedWithData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(14),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(14),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
@ -1556,16 +1556,16 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all EventThreeIndexedWithData events",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventThreeIndexedWithData"])).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic1OneOf(kit.EventMatrixContract.Ev["EventThreeIndexedWithData"]).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
@ -1574,60 +1574,60 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
|
||||
{
|
||||
name: "find all events with topic2 of 44",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(44))).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(uint64EthHash(44)).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
@ -1635,32 +1635,32 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all events with topic2 of 46",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46))).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(uint64EthHash(46)).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
uint64EthHash(46),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(14),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(14),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
@ -1668,14 +1668,14 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all events with topic2 of 50",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(50))).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(uint64EthHash(50)).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
uint64EthHash(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
@ -1683,40 +1683,40 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
},
|
||||
{
|
||||
name: "find all events with topic2 of 46 or 50",
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(paddedEthHash(paddedUint64(46)), paddedEthHash(paddedUint64(50))).Filter(),
|
||||
spec: kit.NewEthFilterBuilder().FromBlock(fromBlock).Topic2OneOf(uint64EthHash(46), uint64EthHash(50)).Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
uint64EthHash(46),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(14),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(14),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
uint64EthHash(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
@ -1727,26 +1727,26 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
name: "find all events with topic1 of EventTwoIndexedWithData and topic3 of 27",
|
||||
spec: kit.NewEthFilterBuilder().
|
||||
FromBlockEpoch(0).
|
||||
Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"])).
|
||||
Topic3OneOf(paddedEthHash(paddedUint64(27))).
|
||||
Topic1OneOf(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]).
|
||||
Topic3OneOf(uint64EthHash(27)).
|
||||
Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(46),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
@ -1757,25 +1757,25 @@ func getTopicFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlock
|
||||
name: "find all events with topic1 of EventTwoIndexedWithData or EventOneIndexed and topic2 of 44",
|
||||
spec: kit.NewEthFilterBuilder().
|
||||
FromBlockEpoch(0).
|
||||
Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]), paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexed"])).
|
||||
Topic2OneOf(paddedEthHash(paddedUint64(44))).
|
||||
Topic1OneOf((kit.EventMatrixContract.Ev["EventTwoIndexedWithData"]), kit.EventMatrixContract.Ev["EventOneIndexed"]).
|
||||
Topic2OneOf(uint64EthHash(44)).
|
||||
Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexed"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
@ -1794,35 +1794,35 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventZeroData"],
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
uint64EthHash(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
@ -1836,20 +1836,20 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventThreeIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(27),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(27),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventTwoIndexed"],
|
||||
paddedUint64(44),
|
||||
paddedUint64(19),
|
||||
uint64EthHash(44),
|
||||
uint64EthHash(19),
|
||||
},
|
||||
Data: nil,
|
||||
},
|
||||
@ -1861,31 +1861,31 @@ func getAddressFilterTestCases(contract1, contract2 ethtypes.EthAddress, fromBlo
|
||||
spec: kit.NewEthFilterBuilder().
|
||||
FromBlockEpoch(0).
|
||||
AddressOneOf(contract1, contract2).
|
||||
Topic1OneOf(paddedEthHash(kit.EventMatrixContract.Ev["EventOneIndexedWithData"])).
|
||||
Topic1OneOf(kit.EventMatrixContract.Ev["EventOneIndexedWithData"]).
|
||||
Filter(),
|
||||
|
||||
expected: []ExpectedEthLog{
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(44),
|
||||
uint64EthHash(44),
|
||||
},
|
||||
Data: paddedUint64(19),
|
||||
},
|
||||
{
|
||||
Address: contract1,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(46),
|
||||
uint64EthHash(46),
|
||||
},
|
||||
Data: paddedUint64(12),
|
||||
},
|
||||
{
|
||||
Address: contract2,
|
||||
Topics: []ethtypes.EthBytes{
|
||||
Topics: []ethtypes.EthHash{
|
||||
kit.EventMatrixContract.Ev["EventOneIndexedWithData"],
|
||||
paddedUint64(50),
|
||||
uint64EthHash(50),
|
||||
},
|
||||
Data: paddedUint64(9),
|
||||
},
|
||||
@ -1906,7 +1906,7 @@ type ExpectedEthLog struct {
|
||||
Address ethtypes.EthAddress `json:"address"`
|
||||
|
||||
// List of topics associated with the event log.
|
||||
Topics []ethtypes.EthBytes `json:"topics"`
|
||||
Topics []ethtypes.EthHash `json:"topics"`
|
||||
|
||||
// Data is the value of the event log, excluding topics
|
||||
Data ethtypes.EthBytes `json:"data"`
|
||||
@ -1918,10 +1918,10 @@ func AssertEthLogs(t *testing.T, actual []*ethtypes.EthLog, expected []ExpectedE
|
||||
|
||||
t.Logf("got %d ethlogs, wanted %d", len(actual), len(expected))
|
||||
|
||||
formatTopics := func(topics []ethtypes.EthBytes) string {
|
||||
formatTopics := func(topics []ethtypes.EthHash) string {
|
||||
ss := make([]string, len(topics))
|
||||
for i := range topics {
|
||||
ss[i] = fmt.Sprintf("%d:%x", i, topics[i])
|
||||
ss[i] = fmt.Sprintf("%d:%s", i, topics[i])
|
||||
}
|
||||
return strings.Join(ss, ",")
|
||||
}
|
||||
@ -1958,7 +1958,7 @@ func AssertEthLogs(t *testing.T, actual []*ethtypes.EthLog, expected []ExpectedE
|
||||
}
|
||||
|
||||
for j := range elog.Topics {
|
||||
if !bytes.Equal(elog.Topics[j], want.Topics[j]) {
|
||||
if elog.Topics[j] != want.Topics[j] {
|
||||
continue LoopExpected
|
||||
}
|
||||
}
|
||||
@ -2132,7 +2132,7 @@ func ParseEthLog(in map[string]interface{}) (*ethtypes.EthLog, error) {
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("%s: %w", k, err)
|
||||
}
|
||||
el.Topics = append(el.Topics, topic)
|
||||
el.Topics = append(el.Topics, paddedEthHash(topic))
|
||||
continue
|
||||
}
|
||||
|
||||
@ -2145,7 +2145,7 @@ func ParseEthLog(in map[string]interface{}) (*ethtypes.EthLog, error) {
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("%s: %w", k, err)
|
||||
}
|
||||
el.Topics = append(el.Topics, topic)
|
||||
el.Topics = append(el.Topics, paddedEthHash(topic))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2153,22 +2153,18 @@ func ParseEthLog(in map[string]interface{}) (*ethtypes.EthLog, error) {
|
||||
return el, err
|
||||
}
|
||||
|
||||
func paddedEthBytes(orig []byte) ethtypes.EthBytes {
|
||||
needed := 32 - len(orig)
|
||||
if needed <= 0 {
|
||||
return orig
|
||||
}
|
||||
ret := make([]byte, 32)
|
||||
copy(ret[needed:], orig)
|
||||
return ret
|
||||
}
|
||||
|
||||
func paddedUint64(v uint64) ethtypes.EthBytes {
|
||||
buf := make([]byte, 32)
|
||||
binary.BigEndian.PutUint64(buf[24:], v)
|
||||
return buf
|
||||
}
|
||||
|
||||
func uint64EthHash(v uint64) ethtypes.EthHash {
|
||||
var buf ethtypes.EthHash
|
||||
binary.BigEndian.PutUint64(buf[24:], v)
|
||||
return buf
|
||||
}
|
||||
|
||||
func paddedEthHash(orig []byte) ethtypes.EthHash {
|
||||
if len(orig) > 32 {
|
||||
panic("exceeds EthHash length")
|
||||
|
@ -2,12 +2,16 @@ package kit
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||
)
|
||||
|
||||
func EthTopicHash(sig string) []byte {
|
||||
func EthTopicHash(sig string) ethtypes.EthHash {
|
||||
hasher := sha3.NewLegacyKeccak256()
|
||||
hasher.Write([]byte(sig))
|
||||
return hasher.Sum(nil)
|
||||
var hash ethtypes.EthHash
|
||||
copy(hash[:], hasher.Sum(nil))
|
||||
return hash
|
||||
}
|
||||
|
||||
func EthFunctionHash(sig string) []byte {
|
||||
@ -18,9 +22,9 @@ func EthFunctionHash(sig string) []byte {
|
||||
|
||||
// SolidityContractDef holds information about one of the test contracts
|
||||
type SolidityContractDef struct {
|
||||
Filename string // filename of the hex of the contract, e.g. contracts/EventMatrix.hex
|
||||
Fn map[string][]byte // mapping of function names to 32-bit selector
|
||||
Ev map[string][]byte // mapping of event names to 256-bit signature hashes
|
||||
Filename string // filename of the hex of the contract, e.g. contracts/EventMatrix.hex
|
||||
Fn map[string][]byte // mapping of function names to 32-bit selector
|
||||
Ev map[string]ethtypes.EthHash // mapping of event names to 256-bit signature hashes
|
||||
}
|
||||
|
||||
var EventMatrixContract = SolidityContractDef{
|
||||
@ -38,7 +42,7 @@ var EventMatrixContract = SolidityContractDef{
|
||||
"logEventTwoIndexedWithData": EthFunctionHash("logEventTwoIndexedWithData(uint256,uint256,uint256)"),
|
||||
"logEventThreeIndexedWithData": EthFunctionHash("logEventThreeIndexedWithData(uint256,uint256,uint256,uint256)"),
|
||||
},
|
||||
Ev: map[string][]byte{
|
||||
Ev: map[string]ethtypes.EthHash{
|
||||
"EventZeroData": EthTopicHash("EventZeroData()"),
|
||||
"EventOneData": EthTopicHash("EventOneData(uint256)"),
|
||||
"EventTwoData": EthTopicHash("EventTwoData(uint256,uint256)"),
|
||||
@ -60,5 +64,5 @@ var EventsContract = SolidityContractDef{
|
||||
"log_zero_nodata": {0x00, 0x00, 0x00, 0x01},
|
||||
"log_four_data": {0x00, 0x00, 0x00, 0x02},
|
||||
},
|
||||
Ev: map[string][]byte{},
|
||||
Ev: map[string]ethtypes.EthHash{},
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func TestWindowPostDispute(t *testing.T) {
|
||||
//stm: @CHAIN_STATE_MINER_CALCULATE_DEADLINE_001
|
||||
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
|
||||
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.Open > 1 {
|
||||
break
|
||||
}
|
||||
build.Clock.Sleep(blocktime)
|
||||
@ -217,7 +217,8 @@ func TestWindowPostDispute(t *testing.T) {
|
||||
//stm: @CHAIN_STATE_MINER_CALCULATE_DEADLINE_001
|
||||
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
if di.Index == evilSectorLoc.Deadline {
|
||||
|
||||
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.Open > 1 {
|
||||
break
|
||||
}
|
||||
build.Clock.Sleep(blocktime)
|
||||
|
@ -1366,6 +1366,67 @@ type filterTipSetCollector interface {
|
||||
TakeCollectedTipSets(context.Context) []types.TipSetKey
|
||||
}
|
||||
|
||||
func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes.EthHash, ok bool) {
|
||||
var (
|
||||
topicsFound [4]bool
|
||||
topicsFoundCount int
|
||||
dataFound bool
|
||||
)
|
||||
for _, entry := range entries {
|
||||
// Drop events with non-raw topics to avoid mistakes.
|
||||
if entry.Codec != cid.Raw {
|
||||
log.Warnw("did not expect an event entry with a non-raw codec", "codec", entry.Codec, "key", entry.Key)
|
||||
return nil, nil, false
|
||||
}
|
||||
// Check if the key is t1..t4
|
||||
if len(entry.Key) == 2 && "t1" <= entry.Key && entry.Key <= "t4" {
|
||||
// '1' - '1' == 0, etc.
|
||||
idx := int(entry.Key[1] - '1')
|
||||
|
||||
// Drop events with mis-sized topics.
|
||||
if len(entry.Value) != 32 {
|
||||
log.Warnw("got an EVM event topic with an invalid size", "key", entry.Key, "size", len(entry.Value))
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
// Drop events with duplicate topics.
|
||||
if topicsFound[idx] {
|
||||
log.Warnw("got a duplicate EVM event topic", "key", entry.Key)
|
||||
return nil, nil, false
|
||||
}
|
||||
topicsFound[idx] = true
|
||||
topicsFoundCount++
|
||||
|
||||
// Extend the topics array
|
||||
for len(topics) <= idx {
|
||||
topics = append(topics, ethtypes.EthHash{})
|
||||
}
|
||||
copy(topics[idx][:], entry.Value)
|
||||
} else if entry.Key == "d" {
|
||||
// Drop events with duplicate data fields.
|
||||
if dataFound {
|
||||
log.Warnw("got duplicate EVM event data")
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
dataFound = true
|
||||
data = entry.Value
|
||||
} else {
|
||||
// Skip entries we don't understand (makes it easier to extend things).
|
||||
// But we warn for now because we don't expect them.
|
||||
log.Warnw("unexpected event entry", "key", entry.Key)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Drop events with skipped topics.
|
||||
if len(topics) != topicsFoundCount {
|
||||
log.Warnw("EVM event topic length mismatch", "expected", len(topics), "actual", topicsFoundCount)
|
||||
return nil, nil, false
|
||||
}
|
||||
return data, topics, true
|
||||
}
|
||||
|
||||
func ethFilterResultFromEvents(evs []*filter.CollectedEvent, sa StateAPI) (*ethtypes.EthFilterResult, error) {
|
||||
res := ðtypes.EthFilterResult{}
|
||||
for _, ev := range evs {
|
||||
@ -1375,19 +1436,14 @@ func ethFilterResultFromEvents(evs []*filter.CollectedEvent, sa StateAPI) (*etht
|
||||
TransactionIndex: ethtypes.EthUint64(ev.MsgIdx),
|
||||
BlockNumber: ethtypes.EthUint64(ev.Height),
|
||||
}
|
||||
var (
|
||||
err error
|
||||
ok bool
|
||||
)
|
||||
|
||||
var err error
|
||||
|
||||
for _, entry := range ev.Entries {
|
||||
// Skip all events that aren't "raw" data.
|
||||
if entry.Codec != cid.Raw {
|
||||
continue
|
||||
}
|
||||
if entry.Key == ethtypes.EthTopic1 || entry.Key == ethtypes.EthTopic2 || entry.Key == ethtypes.EthTopic3 || entry.Key == ethtypes.EthTopic4 {
|
||||
log.Topics = append(log.Topics, entry.Value)
|
||||
} else {
|
||||
log.Data = entry.Value
|
||||
}
|
||||
log.Data, log.Topics, ok = ethLogFromEvent(ev.Entries)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Address, err = ethtypes.EthAddressFromFilecoinAddress(ev.EmitterAddr)
|
||||
@ -1915,18 +1971,16 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook
|
||||
BlockNumber: blockNumber,
|
||||
}
|
||||
|
||||
for _, entry := range evt.Entries {
|
||||
// Ignore any non-raw values/keys.
|
||||
if entry.Codec != cid.Raw {
|
||||
continue
|
||||
}
|
||||
if entry.Key == ethtypes.EthTopic1 || entry.Key == ethtypes.EthTopic2 || entry.Key == ethtypes.EthTopic3 || entry.Key == ethtypes.EthTopic4 {
|
||||
ethtypes.EthBloomSet(receipt.LogsBloom, entry.Value)
|
||||
l.Topics = append(l.Topics, entry.Value)
|
||||
} else {
|
||||
l.Data = entry.Value
|
||||
}
|
||||
data, topics, ok := ethLogFromEvent(evt.Entries)
|
||||
if !ok {
|
||||
// not an eth event.
|
||||
continue
|
||||
}
|
||||
for _, topic := range topics {
|
||||
ethtypes.EthBloomSet(receipt.LogsBloom, topic[:])
|
||||
}
|
||||
l.Data = data
|
||||
l.Topics = topics
|
||||
|
||||
addr, err := address.NewIDAddress(uint64(evt.Emitter))
|
||||
if err != nil {
|
||||
|
102
node/impl/full/eth_test.go
Normal file
102
node/impl/full/eth_test.go
Normal file
@ -0,0 +1,102 @@
|
||||
package full
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||
)
|
||||
|
||||
func TestEthLogFromEvent(t *testing.T) {
|
||||
// basic empty
|
||||
data, topics, ok := ethLogFromEvent(nil)
|
||||
require.True(t, ok)
|
||||
require.Nil(t, data)
|
||||
require.Nil(t, topics)
|
||||
|
||||
// basic topic
|
||||
data, topics, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "t1",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}})
|
||||
require.True(t, ok)
|
||||
require.Nil(t, data)
|
||||
require.Len(t, topics, 1)
|
||||
require.Equal(t, topics[0], ethtypes.EthHash{})
|
||||
|
||||
// basic topic with data
|
||||
data, topics, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "t1",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}, {
|
||||
Flags: 0,
|
||||
Key: "d",
|
||||
Codec: cid.Raw,
|
||||
Value: []byte{0x0},
|
||||
}})
|
||||
require.True(t, ok)
|
||||
require.Equal(t, data, []byte{0x0})
|
||||
require.Len(t, topics, 1)
|
||||
require.Equal(t, topics[0], ethtypes.EthHash{})
|
||||
|
||||
// skip topic
|
||||
_, _, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "t2",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}})
|
||||
require.False(t, ok)
|
||||
|
||||
// duplicate topic
|
||||
_, _, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "t1",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}, {
|
||||
Flags: 0,
|
||||
Key: "t1",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}})
|
||||
require.False(t, ok)
|
||||
|
||||
// duplicate data
|
||||
_, _, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "d",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}, {
|
||||
Flags: 0,
|
||||
Key: "d",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}})
|
||||
require.False(t, ok)
|
||||
|
||||
// unknown key is fine
|
||||
data, topics, ok = ethLogFromEvent([]types.EventEntry{{
|
||||
Flags: 0,
|
||||
Key: "t5",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}, {
|
||||
Flags: 0,
|
||||
Key: "t1",
|
||||
Codec: cid.Raw,
|
||||
Value: make([]byte, 32),
|
||||
}})
|
||||
require.True(t, ok)
|
||||
require.Nil(t, data)
|
||||
require.Len(t, topics, 1)
|
||||
require.Equal(t, topics[0], ethtypes.EthHash{})
|
||||
}
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
"github.com/filecoin-project/lotus/chain/wallet/key"
|
||||
"github.com/filecoin-project/lotus/lib/sigs"
|
||||
)
|
||||
|
||||
@ -53,11 +52,7 @@ func (a *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, ms
|
||||
return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr)
|
||||
}
|
||||
|
||||
keyInfo, err := a.Wallet.WalletExport(ctx, k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sb, err := messagesigner.SigningBytes(msg, key.ActSigType(keyInfo.Type))
|
||||
sb, err := messagesigner.SigningBytes(msg, keyAddr.Protocol())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user