package full import ( "testing" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/ethtypes" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" ) 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{}) }