From b91da8eb32eb3e31b3c332c1ab680341ddf1129e Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 4 Mar 2024 20:55:12 +1100 Subject: [PATCH] test: add additional actor events checks --- itests/direct_data_onboard_verified_test.go | 14 +++++++++ itests/sector_terminate_test.go | 33 +++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/itests/direct_data_onboard_verified_test.go b/itests/direct_data_onboard_verified_test.go index 37f437a8e..0c3de2448 100644 --- a/itests/direct_data_onboard_verified_test.go +++ b/itests/direct_data_onboard_verified_test.go @@ -232,6 +232,20 @@ func TestOnboardRawPieceVerified_WithActorEvents(t *testing.T) { require.ElementsMatch(t, expectedEntries, allocationEvents[1].Entries) } + { + allocationEvents := filterEvents(eventsFromMessages, "allocation-removed") + require.Len(t, allocationEvents, 1) + + // manual removal of the bogus allocation + expectedEntries := []types.EventEntry{ + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "$type", Value: must.One(ipld.Encode(basicnode.NewString("allocation-removed"), dagcbor.Encode))}, + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "id", Value: must.One(ipld.Encode(basicnode.NewInt(int64(allocationId)-1), dagcbor.Encode))}, + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "provider", Value: must.One(ipld.Encode(basicnode.NewInt(int64(minerId)), dagcbor.Encode))}, + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "client", Value: must.One(ipld.Encode(basicnode.NewInt(int64(clientId)), dagcbor.Encode))}, + } + require.ElementsMatch(t, expectedEntries, allocationEvents[0].Entries) + } + { claimEvents := filterEvents(eventsFromMessages, "claim") require.Len(t, claimEvents, 1) diff --git a/itests/sector_terminate_test.go b/itests/sector_terminate_test.go index 34b325f2a..57cffb006 100644 --- a/itests/sector_terminate_test.go +++ b/itests/sector_terminate_test.go @@ -2,10 +2,15 @@ package itests import ( + "bytes" "context" "testing" "time" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/codec/dagcbor" + "github.com/ipld/go-ipld-prime/node/basicnode" + "github.com/multiformats/go-multicodec" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-bitfield" @@ -13,6 +18,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/itests/kit" + "github.com/filecoin-project/lotus/lib/must" sealing "github.com/filecoin-project/lotus/storage/pipeline" ) @@ -164,4 +170,31 @@ loop: require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, types.NewInt(uint64(ssz)*uint64(nSectors-1)), p.MinerPower.RawBytePower) + + // check "sector-terminated" actor event + var epochZero abi.ChainEpoch + allEvents, err := miner.FullNode.GetActorEvents(ctx, &types.ActorEventFilter{ + FromHeight: &epochZero, + }) + require.NoError(t, err) + for _, key := range []string{"sector-precommitted", "sector-activated", "sector-terminated"} { + var found bool + keyBytes := must.One(ipld.Encode(basicnode.NewString(key), dagcbor.Encode)) + for _, event := range allEvents { + for _, e := range event.Entries { + if e.Key == "$type" && bytes.Equal(e.Value, keyBytes) { + found = true + if key == "sector-terminated" { + expectedEntries := []types.EventEntry{ + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "$type", Value: keyBytes}, + {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "sector", Value: must.One(ipld.Encode(basicnode.NewInt(int64(toTerminate)), dagcbor.Encode))}, + } + require.ElementsMatch(t, expectedEntries, event.Entries) + } + break + } + } + } + require.True(t, found, "expected to find event %s", key) + } }