diff --git a/types/testutil/events.go b/types/testutil/events.go index 964f3ec1b0..ed67cfdca9 100644 --- a/types/testutil/events.go +++ b/types/testutil/events.go @@ -25,7 +25,8 @@ func MatchEvent(expected proto.Message, emitted sdk.Event) error { // the proto.MessageName of the passed msg. func GetEvent(msg proto.Message, events []sdk.Event) (e sdk.Event, found bool) { eventName := proto.MessageName(msg) - for _, e := range events { + for i := len(events) - 1; i >= 0; i-- { + e = events[i] if eventName == e.Type { return e, true } diff --git a/x/data/server/features/msg_anchor.feature b/x/data/server/features/msg_anchor.feature index 05b8ea65f4..4d7ed8faa7 100644 --- a/x/data/server/features/msg_anchor.feature +++ b/x/data/server/features/msg_anchor.feature @@ -26,3 +26,15 @@ Feature: Msg/Anchor Given alice has anchored the data at block time "2020-01-01" When bob attempts to anchor the data at block time "2020-01-02" Then the anchor entry exists with timestamp "2020-01-01" + + Rule: Event is emitted + + Scenario: EventAnchor is emitted + When alice attempts to anchor the data at block time "2020-01-01" + Then the anchor entry exists with timestamp "2020-01-01" + And expect event with properties + """ + { + "iri": "regen:112wkBET2rRgE8pahuaczxKbmv7ciehqsne57F9gtzf1PVhwuFTX.bin" + } + """ \ No newline at end of file diff --git a/x/data/server/features/msg_attest.feature b/x/data/server/features/msg_attest.feature index c9051ef40c..0fddb4a5da 100644 --- a/x/data/server/features/msg_attest.feature +++ b/x/data/server/features/msg_attest.feature @@ -38,3 +38,19 @@ Feature: Msg/Attest Given alice has attested to the data at block time "2020-01-01" When bob attempts to attest to the data at block time "2020-01-02" Then the attestor entry for bob exists with timestamp "2020-01-02" + + Rule: event is emitted + + Background: + Given alice's address "regen1k82wewrfkhdmegw6uxrgwwzrsd7593t8tej2d5" + + Scenario: EventAttest is emitted + When alice attempts to attest to the data at block time "2020-01-01" + Then the anchor entry exists with timestamp "2020-01-01" + And event is emitted with properties + """ + { + "iri": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf", + "attestor": "regen1k82wewrfkhdmegw6uxrgwwzrsd7593t8tej2d5" + } + """ \ No newline at end of file diff --git a/x/data/server/features/msg_define_resolver.feature b/x/data/server/features/msg_define_resolver.feature index 8a37ad3a15..3a38cc16ec 100644 --- a/x/data/server/features/msg_define_resolver.feature +++ b/x/data/server/features/msg_define_resolver.feature @@ -14,3 +14,16 @@ Feature: Msg/DefineResolver Given alice has defined a resolver with url "https://foo.bar" When alice attempts to define a resolver with url "https://foo.bar" Then expect the error "a resolver with the same URL and manager already exists: unique key violation" + + Rule: Event is emitted + + Scenario: EventDefineResolver is emitted + Given alice has defined a resolver with url "https://foo.bar" + When bob attempts to define a resolver with url "https://foo.bar" + Then expect the resolver with id "2" and url "https://foo.bar" and manager bob + And expect event with properties + """ + { + "id": 2 + } + """ \ No newline at end of file diff --git a/x/data/server/features/msg_register_resolver.feature b/x/data/server/features/msg_register_resolver.feature index 7a14cac27e..3163628e08 100644 --- a/x/data/server/features/msg_register_resolver.feature +++ b/x/data/server/features/msg_register_resolver.feature @@ -62,3 +62,17 @@ Feature: Msg/RegisterResolver Scenario: the registrant is not the manager When bob attempts to register the data to the resolver Then expect the error "unauthorized resolver manager" + + Rule: event is emitted + + Scenario: EventRegisterResolver is emitted + Given alice has defined the resolver with url "https://foo.bar" + When alice attempts to register the data to the resolver + Then the data resolver entry exists + And expect event with properties + """ + { + "id": 1, + "iri": "regen:112wkBET2rRgE8pahuaczxKbmv7ciehqsne57F9gtzf1PVhwuFTX.bin" + } + """ \ No newline at end of file diff --git a/x/data/server/msg_anchor_test.go b/x/data/server/msg_anchor_test.go index 5198b6ebaa..33cbd2b872 100644 --- a/x/data/server/msg_anchor_test.go +++ b/x/data/server/msg_anchor_test.go @@ -1,6 +1,7 @@ package server import ( + "encoding/json" "testing" "github.com/gogo/protobuf/jsonpb" @@ -10,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -90,3 +92,15 @@ func (s *anchorSuite) TheAnchorEntryExistsWithTimestamp(a string) { require.NotNil(s.t, dataAnchor) require.Equal(s.t, anchorTime, dataAnchor.Timestamp.AsTime()) } + +func (s *anchorSuite) ExpectEventWithProperties(a gocuke.DocString) { + var event data.EventAnchor + err := json.Unmarshal([]byte(a.Content), &event) + require.NoError(s.t, err) + + sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events()) + require.True(s.t, found) + + err = testutil.MatchEvent(&event, sdkEvent) + require.NoError(s.t, err) +} diff --git a/x/data/server/msg_attest_test.go b/x/data/server/msg_attest_test.go index 97fa0a75be..4ea1e48996 100644 --- a/x/data/server/msg_attest_test.go +++ b/x/data/server/msg_attest_test.go @@ -1,6 +1,7 @@ package server import ( + "encoding/json" "testing" "github.com/gogo/protobuf/jsonpb" @@ -10,6 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -37,6 +39,12 @@ func (s *attestSuite) TheContentHash(a gocuke.DocString) { require.NoError(s.t, err) } +func (s *attestSuite) AlicesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.alice = addr +} + func (s *attestSuite) AliceHasAnchoredTheDataAtBlockTime(a string) { blockTime, err := types.ParseDate("block time", a) require.NoError(s.t, err) @@ -118,6 +126,18 @@ func (s *attestSuite) TheAttestorEntryForBobExistsWithTimestamp(a string) { require.Equal(s.t, attestTime, dataAttestor.Timestamp.AsTime()) } +func (s *attestSuite) EventIsEmittedWithProperties(a gocuke.DocString) { + var event data.EventAttest + err := json.Unmarshal([]byte(a.Content), &event) + require.NoError(s.t, err) + + sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events()) + require.True(s.t, found) + + err = testutil.MatchEvent(&event, sdkEvent) + require.NoError(s.t, err) +} + func (s *attestSuite) getDataID() []byte { iri, err := s.ch.ToIRI() require.NoError(s.t, err) diff --git a/x/data/server/msg_define_resolver_test.go b/x/data/server/msg_define_resolver_test.go index a694bb7b9d..49a59e6708 100644 --- a/x/data/server/msg_define_resolver_test.go +++ b/x/data/server/msg_define_resolver_test.go @@ -2,6 +2,7 @@ package server import ( + "encoding/json" "strconv" "testing" @@ -10,6 +11,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + api "github.com/regen-network/regen-ledger/api/regen/data/v1" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -31,9 +34,9 @@ func (s *defineResolverSuite) Before(t gocuke.TestingT) { } func (s *defineResolverSuite) AliceHasDefinedAResolverWithUrl(a string) { - _, err := s.server.DefineResolver(s.ctx, &data.MsgDefineResolver{ - Manager: s.alice.String(), - ResolverUrl: a, + err := s.server.stateStore.ResolverTable().Insert(s.ctx, &api.Resolver{ + Url: a, + Manager: s.alice, }) require.NoError(s.t, err) } @@ -65,3 +68,15 @@ func (s *defineResolverSuite) ExpectTheResolverWithIdAndUrlAndManagerBob(a strin func (s *defineResolverSuite) ExpectTheError(a string) { require.EqualError(s.t, s.err, a) } + +func (s *defineResolverSuite) ExpectEventWithProperties(a gocuke.DocString) { + var event data.EventDefineResolver + err := json.Unmarshal([]byte(a.Content), &event) + require.NoError(s.t, err) + + sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events()) + require.True(s.t, found) + + err = testutil.MatchEvent(&event, sdkEvent) + require.NoError(s.t, err) +} diff --git a/x/data/server/msg_register_resolver_test.go b/x/data/server/msg_register_resolver_test.go index 3e55885d09..1c873611b5 100644 --- a/x/data/server/msg_register_resolver_test.go +++ b/x/data/server/msg_register_resolver_test.go @@ -2,6 +2,7 @@ package server import ( + "encoding/json" "strconv" "testing" @@ -12,6 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/regen-network/regen-ledger/types" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -134,6 +136,18 @@ func (s *registerResolverSuite) ExpectTheError(a string) { require.EqualError(s.t, s.err, a) } +func (s *registerResolverSuite) ExpectEventWithProperties(a gocuke.DocString) { + var event data.EventRegisterResolver + err := json.Unmarshal([]byte(a.Content), &event) + require.NoError(s.t, err) + + sdkEvent, found := testutil.GetEvent(&event, s.sdkCtx.EventManager().Events()) + require.True(s.t, found) + + err = testutil.MatchEvent(&event, sdkEvent) + require.NoError(s.t, err) +} + func (s *registerResolverSuite) getDataID() []byte { iri, err := s.ch.ToIRI() require.NoError(s.t, err)