From 421db41f86f7b5212b8ab0a1c0e77204e1310ec6 Mon Sep 17 00:00:00 2001 From: tyler <{ID}+{username}@users.noreply.github.com> Date: Wed, 24 Aug 2022 13:52:24 -0700 Subject: [PATCH 1/4] test: basket event checks --- types/testutil/events.go | 32 +++++++++ types/testutil/events_test.go | 61 ++++++++++++++++ .../server/basket/features/msg_create.feature | 14 ++++ .../server/basket/features/msg_put.feature | 38 ++++++++++ .../server/basket/features/msg_take.feature | 60 ++++++++++++++++ x/ecocredit/server/basket/invariants_test.go | 5 +- x/ecocredit/server/basket/keeper_test.go | 7 +- x/ecocredit/server/basket/msg_create_test.go | 22 +++++- x/ecocredit/server/basket/msg_put_test.go | 40 ++++++++++- x/ecocredit/server/basket/msg_take_test.go | 70 ++++++++++++++++++- .../basket/msg_update_basket_fee_test.go | 2 +- .../server/basket/query_balance_test.go | 2 +- .../server/basket/query_balances_test.go | 2 +- .../server/basket/query_basket_test.go | 2 +- .../server/basket/query_baskets_test.go | 2 +- x/ecocredit/server/basket/util_test.go | 2 +- 16 files changed, 345 insertions(+), 16 deletions(-) create mode 100644 types/testutil/events.go create mode 100644 types/testutil/events_test.go diff --git a/types/testutil/events.go b/types/testutil/events.go new file mode 100644 index 0000000000..c5718a1f71 --- /dev/null +++ b/types/testutil/events.go @@ -0,0 +1,32 @@ +package testutil + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gogo/protobuf/proto" + abci "github.com/tendermint/tendermint/abci/types" +) + +// MatchEvent matches the values in a proto message struct to the attributes in a sdk.Event. +func MatchEvent(expected proto.Message, emitted sdk.Event) error { + msg, err := sdk.ParseTypedEvent(abci.Event(emitted)) + if err != nil { + return err + } + equal := proto.Equal(expected, msg) + if !equal { + return fmt.Errorf("expected %s\ngot %s", expected.String(), msg.String()) + } + return nil +} + +func GetEvent(msg proto.Message, events []sdk.Event) (e sdk.Event, found bool) { + eventName := proto.MessageName(msg) + for _, e := range events { + if eventName == e.Type { + return e, true + } + } + return e, false +} diff --git a/types/testutil/events_test.go b/types/testutil/events_test.go new file mode 100644 index 0000000000..142281ec02 --- /dev/null +++ b/types/testutil/events_test.go @@ -0,0 +1,61 @@ +package testutil + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/group" + "github.com/cosmos/cosmos-sdk/x/nft" + "github.com/stretchr/testify/require" +) + +func TestMatchEvent(t *testing.T) { + event := nft.EventSend{ + ClassId: "foo", + Id: "bar", + Sender: "baz", + Receiver: "qux", + } + + sdkEvent, err := sdk.TypedEventToEvent(&event) + require.NoError(t, err) + + err = MatchEvent(&event, sdkEvent) + require.NoError(t, err) + + event.Receiver = "fail" + err = MatchEvent(&event, sdkEvent) + require.Error(t, err) +} + +func TestGetEvent(t *testing.T) { + events := sdk.Events{} + + event := nft.EventSend{ + ClassId: "foo", + Id: "bar", + Sender: "baz", + Receiver: "qux", + } + event2 := group.EventCreateGroup{GroupId: 2} + + sdkEvent, err := sdk.TypedEventToEvent(&event) + require.NoError(t, err) + + sdkEvent2, err := sdk.TypedEventToEvent(&event2) + require.NoError(t, err) + events = append(events, sdkEvent, sdkEvent2) + + gotEvent, found := GetEvent(&event, events) + require.True(t, found) + + require.Equal(t, gotEvent, sdkEvent) + + gotEvent2, found := GetEvent(&event2, events) + require.True(t, found) + require.Equal(t, gotEvent2, sdkEvent2) + + notInEvents := group.EventSubmitProposal{} + _, found = GetEvent(¬InEvents, events) + require.False(t, found) +} diff --git a/x/ecocredit/server/basket/features/msg_create.feature b/x/ecocredit/server/basket/features/msg_create.feature index cd2fb3c14a..75ccda1c90 100644 --- a/x/ecocredit/server/basket/features/msg_create.feature +++ b/x/ecocredit/server/basket/features/msg_create.feature @@ -237,3 +237,17 @@ Feature: Msg/Create """ # no failing scenario - response should always be empty when message execution fails + + Rule: Event is emitted + + Scenario: EventCreate is emitted + Given a credit type with abbreviation "C" and precision "6" + And alice's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + When alice attempts to create a basket with name "NCT" + Then expect event with properties + """ + { + "curator": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "basket_denom": "eco.uC.NCT" + } + """ \ No newline at end of file diff --git a/x/ecocredit/server/basket/features/msg_put.feature b/x/ecocredit/server/basket/features/msg_put.feature index f0c958fcc4..2585aa4d05 100644 --- a/x/ecocredit/server/basket/features/msg_put.feature +++ b/x/ecocredit/server/basket/features/msg_put.feature @@ -283,3 +283,41 @@ Feature: Msg/Put | precision non-zero, amount decimal | 6 | 2.5 | 2500000 | # no failing scenario - response should always be empty when message execution fails + + Rule: Events are emitted + + Background: + Given a credit type with abbreviation "C" and precision "6" + And a basket with credit type "C" + And Alice's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + And Ecocredit module's address "regen1k82wewrfkhdmegw6uxrgwwzrsd7593t8tej2d5" + And Alice owns credit amount "2" + + Scenario: EventTransfer is emitted + When alice attempts to put credit amount "2" into the basket + Then expect event transfer with properties + """ + { + "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "recipient": "regen1k82wewrfkhdmegw6uxrgwwzrsd7593t8tej2d5", + "batch_denom": "C01-001-20200101-20210101-001", + "tradable_amount": "2" + } + """ + + Scenario: EventPut is emitted + When alice attempts to put credit amount "2" into the basket + Then expect event put with properties + """ + { + "owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "basket_denom": "eco.uC.NCT", + "credits": [ + { + "batch_denom": "C01-001-20200101-20210101-001", + "amount": "2" + } + ], + "amount": "2000000" + } + """ \ No newline at end of file diff --git a/x/ecocredit/server/basket/features/msg_take.feature b/x/ecocredit/server/basket/features/msg_take.feature index 23a4640d6f..2ac4384787 100644 --- a/x/ecocredit/server/basket/features/msg_take.feature +++ b/x/ecocredit/server/basket/features/msg_take.feature @@ -184,3 +184,63 @@ Feature: Msg/Take | precision non-zero, credits decimal | 6 | 2500000 | 2.500000 | # no failing scenario - response should always be empty when message execution fails + + Rule: Events are emitted + + Background: + Given a credit type with abbreviation "C" and precision "6" + And a basket with credit type "C" and disable auto retire "true" + And basket token supply amount "2000000" + And Alice's address "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp" + And Ecocredit module's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + And Alice owns basket token amount "2000000" + + Scenario: EventTake is emitted + When alice attempts to take credits with basket token amount "2000000" + Then expect event take with properties + """ + { + "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "basket_denom": "eco.uC.NCT", + "credits": [ + {"batch_denom": "C01-001-20200101-20210101-001", "amount": "2.000000"} + ], + "amount": "2000000" + } + """ + + Scenario: EventRetire is emitted + When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" + Then expect event retire with properties + """ + { + "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "amount": "2.000000", + "jurisdiction": "US-WA" + } + """ + + Scenario: EventTransfer is emitted when retire on take is true + When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" + Then expect event transfer with properties + """ + { + "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "retired_amount": "2.000000" + } + """ + + Scenario: EventTransfer is emitted when retire on take is false + When alice attempts to take credits with basket token amount "2000000" and retire on take "false" + Then expect event transfer with properties + """ + { + "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "tradable_amount": "2.000000" + } + """ \ No newline at end of file diff --git a/x/ecocredit/server/basket/invariants_test.go b/x/ecocredit/server/basket/invariants_test.go index da48300250..d815e08140 100644 --- a/x/ecocredit/server/basket/invariants_test.go +++ b/x/ecocredit/server/basket/invariants_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" @@ -9,7 +9,6 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/basket/v1" "github.com/regen-network/regen-ledger/types/math" - "github.com/regen-network/regen-ledger/x/ecocredit/server/basket" ) type BasketWithSupply struct { @@ -69,7 +68,7 @@ func TestBasketSupplyInvarint(t *testing.T) { for _, tc := range tcs { tc.bank.GetSupply(s.sdkCtx, "abc") - msg, _ := basket.SupplyInvariant(s.sdkCtx, store, tc.bank, basketBalances) + msg, _ := SupplyInvariant(s.sdkCtx, store, tc.bank, basketBalances) if tc.msg != "" { require.Contains(msg, tc.msg, tc.name) } else { diff --git a/x/ecocredit/server/basket/keeper_test.go b/x/ecocredit/server/basket/keeper_test.go index d447d00921..6f37196aed 100644 --- a/x/ecocredit/server/basket/keeper_test.go +++ b/x/ecocredit/server/basket/keeper_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "context" @@ -24,7 +24,6 @@ import ( ecoApi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/mocks" - "github.com/regen-network/regen-ledger/x/ecocredit/server/basket" ) const ( @@ -36,7 +35,7 @@ type baseSuite struct { t gocuke.TestingT db ormdb.ModuleDB ctx context.Context - k basket.Keeper + k Keeper ctrl *gomock.Controller addrs []sdk.AccAddress stateStore api.StateStore @@ -77,7 +76,7 @@ func setupBase(t gocuke.TestingT) *baseSuite { authority, err := sdk.AccAddressFromBech32("regen1nzh226hxrsvf4k69sa8v0nfuzx5vgwkczk8j68") assert.NilError(t, err) - s.k = basket.NewKeeper(s.stateStore, s.coreStore, s.bankKeeper, s.paramsKeeper, moduleAddress, authority) + s.k = NewKeeper(s.stateStore, s.coreStore, s.bankKeeper, s.paramsKeeper, moduleAddress, authority) s.coreStore, err = ecoApi.NewStateStore(s.db) assert.NilError(t, err) diff --git a/x/ecocredit/server/basket/msg_create_test.go b/x/ecocredit/server/basket/msg_create_test.go index 8ee8e01155..ef68cc7fc4 100644 --- a/x/ecocredit/server/basket/msg_create_test.go +++ b/x/ecocredit/server/basket/msg_create_test.go @@ -1,7 +1,8 @@ //nolint:revive,stylecheck -package basket_test +package basket import ( + "encoding/json" "strconv" "testing" @@ -14,6 +15,7 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/basket/v1" coreapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/ecocredit/basket" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -97,6 +99,12 @@ func (s *createSuite) ACreditTypeWithAbbreviationAndPrecision(a string, b string require.NoError(s.t, err) } +func (s *createSuite) AlicesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.alice = addr +} + func (s *createSuite) ACreditClassWithId(a string) { creditTypeAbbrev := core.GetCreditTypeAbbrevFromClassID(a) @@ -222,6 +230,18 @@ func (s *createSuite) ExpectTheResponse(a gocuke.DocString) { require.Equal(s.t, res, s.res) } +func (s *createSuite) ExpectEventWithProperties(a gocuke.DocString) { + var event basket.EventCreate + 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 *createSuite) createExpectCalls() { var expectedFee sdk.Coin diff --git a/x/ecocredit/server/basket/msg_put_test.go b/x/ecocredit/server/basket/msg_put_test.go index 71a0f15073..f7a7d324e2 100644 --- a/x/ecocredit/server/basket/msg_put_test.go +++ b/x/ecocredit/server/basket/msg_put_test.go @@ -1,6 +1,7 @@ -package basket_test +package basket import ( + "encoding/json" "strconv" "strings" "testing" @@ -18,6 +19,7 @@ import ( coreapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/math" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/ecocredit/basket" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -504,6 +506,42 @@ func (s *putSuite) ExpectTheResponse(a gocuke.DocString) { require.Equal(s.t, res, s.res) } +func (s *putSuite) ExpectEventTransferWithProperties(a gocuke.DocString) { + var event core.EventTransfer + 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 *putSuite) AlicesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.alice = addr +} + +func (s *putSuite) EcocreditModulesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.k.moduleAddress = addr +} + +func (s *putSuite) ExpectEventPutWithProperties(a gocuke.DocString) { + var event basket.EventPut + 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 *putSuite) putExpectCalls() { sendCoin := s.calculateExpectedCoin(s.tradableCredits) sendCoins := sdk.NewCoins(sendCoin) diff --git a/x/ecocredit/server/basket/msg_take_test.go b/x/ecocredit/server/basket/msg_take_test.go index 8feea8b30b..5428e031cb 100644 --- a/x/ecocredit/server/basket/msg_take_test.go +++ b/x/ecocredit/server/basket/msg_take_test.go @@ -1,6 +1,7 @@ -package basket_test +package basket import ( + "encoding/json" "strconv" "testing" @@ -12,6 +13,7 @@ import ( api "github.com/regen-network/regen-ledger/api/regen/ecocredit/basket/v1" coreapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + "github.com/regen-network/regen-ledger/types/testutil" "github.com/regen-network/regen-ledger/x/ecocredit/basket" "github.com/regen-network/regen-ledger/x/ecocredit/core" ) @@ -166,6 +168,18 @@ func (s *takeSuite) ABasketWithCreditTypeAndCreditBalance(a string, b string) { s.addBasketClassAndBalance(basketID, b) } +func (s *takeSuite) AlicesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.alice = addr +} + +func (s *takeSuite) EcocreditModulesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.k.moduleAddress = addr +} + func (s *takeSuite) AliceOwnsBasketTokens() { amount, ok := sdk.NewIntFromString(s.tokenAmount) require.True(s.t, ok) @@ -320,6 +334,60 @@ func (s *takeSuite) ExpectTheResponse(a gocuke.DocString) { require.Equal(s.t, res, s.res) } +func (s *takeSuite) ExpectEventTakeWithProperties(a gocuke.DocString) { + var event basket.EventTake + 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 *takeSuite) AliceAttemptsToTakeCreditsWithBasketTokenAmountAndRetireOnTakeFrom(a, b, c string) { + s.tokenAmount = a + + retireOnTake, err := strconv.ParseBool(b) + require.NoError(s.t, err) + + s.takeExpectCalls() + + s.res, s.err = s.k.Take(s.ctx, &basket.MsgTake{ + Owner: s.alice.String(), + BasketDenom: s.basketDenom, + Amount: s.tokenAmount, + RetirementJurisdiction: c, + RetireOnTake: retireOnTake, + }) + require.NoError(s.t, err) +} + +func (s *takeSuite) ExpectEventRetireWithProperties(a gocuke.DocString) { + var event core.EventRetire + 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 *takeSuite) ExpectEventTransferWithProperties(a gocuke.DocString) { + var event core.EventTransfer + 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 *takeSuite) addBasketClassAndBalance(basketID uint64, creditAmount string) { err := s.stateStore.BasketClassTable().Insert(s.ctx, &api.BasketClass{ BasketId: basketID, diff --git a/x/ecocredit/server/basket/msg_update_basket_fee_test.go b/x/ecocredit/server/basket/msg_update_basket_fee_test.go index 2afa01db91..5a6be5c663 100644 --- a/x/ecocredit/server/basket/msg_update_basket_fee_test.go +++ b/x/ecocredit/server/basket/msg_update_basket_fee_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "encoding/json" diff --git a/x/ecocredit/server/basket/query_balance_test.go b/x/ecocredit/server/basket/query_balance_test.go index c1e436cd84..d4fac719df 100644 --- a/x/ecocredit/server/basket/query_balance_test.go +++ b/x/ecocredit/server/basket/query_balance_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" diff --git a/x/ecocredit/server/basket/query_balances_test.go b/x/ecocredit/server/basket/query_balances_test.go index 3f45d8e2a4..18a31828fb 100644 --- a/x/ecocredit/server/basket/query_balances_test.go +++ b/x/ecocredit/server/basket/query_balances_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" diff --git a/x/ecocredit/server/basket/query_basket_test.go b/x/ecocredit/server/basket/query_basket_test.go index e867e0cbde..b024a4ba4a 100644 --- a/x/ecocredit/server/basket/query_basket_test.go +++ b/x/ecocredit/server/basket/query_basket_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" diff --git a/x/ecocredit/server/basket/query_baskets_test.go b/x/ecocredit/server/basket/query_baskets_test.go index 7d3b24d44d..26019f558f 100644 --- a/x/ecocredit/server/basket/query_baskets_test.go +++ b/x/ecocredit/server/basket/query_baskets_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" diff --git a/x/ecocredit/server/basket/util_test.go b/x/ecocredit/server/basket/util_test.go index bbe4ef8be5..848dda78bb 100644 --- a/x/ecocredit/server/basket/util_test.go +++ b/x/ecocredit/server/basket/util_test.go @@ -1,4 +1,4 @@ -package basket_test +package basket import ( "testing" From 33fe388f55e94b05375899f882f9b79ce4cae81f Mon Sep 17 00:00:00 2001 From: tyler <{ID}+{username}@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:01:39 -0700 Subject: [PATCH 2/4] docs: util godocs --- types/testutil/events.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/testutil/events.go b/types/testutil/events.go index c5718a1f71..964f3ec1b0 100644 --- a/types/testutil/events.go +++ b/types/testutil/events.go @@ -8,7 +8,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// MatchEvent matches the values in a proto message struct to the attributes in a sdk.Event. +// MatchEvent matches the values in a proto message to a sdk.Event. func MatchEvent(expected proto.Message, emitted sdk.Event) error { msg, err := sdk.ParseTypedEvent(abci.Event(emitted)) if err != nil { @@ -21,6 +21,8 @@ func MatchEvent(expected proto.Message, emitted sdk.Event) error { return nil } +// GetEvent searches through the sdk.Events and attempts to return the sdk.Event whose type matches +// 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 { From fdcddc92ada6fa6b0c909b70dab17904e8402404 Mon Sep 17 00:00:00 2001 From: tyler <{ID}+{username}@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:04:25 -0700 Subject: [PATCH 3/4] style: feature file formatting --- .../server/basket/features/msg_take.feature | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/x/ecocredit/server/basket/features/msg_take.feature b/x/ecocredit/server/basket/features/msg_take.feature index 2ac4384787..702c4f0701 100644 --- a/x/ecocredit/server/basket/features/msg_take.feature +++ b/x/ecocredit/server/basket/features/msg_take.feature @@ -187,60 +187,60 @@ Feature: Msg/Take Rule: Events are emitted - Background: - Given a credit type with abbreviation "C" and precision "6" - And a basket with credit type "C" and disable auto retire "true" - And basket token supply amount "2000000" - And Alice's address "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp" - And Ecocredit module's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" - And Alice owns basket token amount "2000000" - - Scenario: EventTake is emitted - When alice attempts to take credits with basket token amount "2000000" - Then expect event take with properties - """ - { - "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", - "basket_denom": "eco.uC.NCT", - "credits": [ - {"batch_denom": "C01-001-20200101-20210101-001", "amount": "2.000000"} - ], - "amount": "2000000" - } - """ - - Scenario: EventRetire is emitted - When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" - Then expect event retire with properties - """ - { - "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", - "batch_denom": "C01-001-20200101-20210101-001", - "amount": "2.000000", - "jurisdiction": "US-WA" - } - """ - - Scenario: EventTransfer is emitted when retire on take is true - When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" - Then expect event transfer with properties - """ - { - "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", - "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", - "batch_denom": "C01-001-20200101-20210101-001", - "retired_amount": "2.000000" - } - """ + Background: + Given a credit type with abbreviation "C" and precision "6" + And a basket with credit type "C" and disable auto retire "true" + And basket token supply amount "2000000" + And Alice's address "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp" + And Ecocredit module's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6" + And Alice owns basket token amount "2000000" + + Scenario: EventTake is emitted + When alice attempts to take credits with basket token amount "2000000" + Then expect event take with properties + """ + { + "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "basket_denom": "eco.uC.NCT", + "credits": [ + {"batch_denom": "C01-001-20200101-20210101-001", "amount": "2.000000"} + ], + "amount": "2000000" + } + """ + + Scenario: EventRetire is emitted + When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" + Then expect event retire with properties + """ + { + "owner": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "amount": "2.000000", + "jurisdiction": "US-WA" + } + """ + + Scenario: EventTransfer is emitted when retire on take is true + When alice attempts to take credits with basket token amount "2000000" and retire on take "true" from "US-WA" + Then expect event transfer with properties + """ + { + "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "retired_amount": "2.000000" + } + """ Scenario: EventTransfer is emitted when retire on take is false When alice attempts to take credits with basket token amount "2000000" and retire on take "false" Then expect event transfer with properties """ { - "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", - "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", - "batch_denom": "C01-001-20200101-20210101-001", - "tradable_amount": "2.000000" + "sender": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6", + "recipient": "regen10z82e5ztmrm4pujgummvmr7aqjzwlp6gz8k8xp", + "batch_denom": "C01-001-20200101-20210101-001", + "tradable_amount": "2.000000" } """ \ No newline at end of file From 39aabd0d19f6acbd57e504ba92aac152065432fe Mon Sep 17 00:00:00 2001 From: tyler <{ID}+{username}@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:06:31 -0700 Subject: [PATCH 4/4] style: step ordering --- x/ecocredit/server/basket/msg_put_test.go | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/x/ecocredit/server/basket/msg_put_test.go b/x/ecocredit/server/basket/msg_put_test.go index f7a7d324e2..83b067f415 100644 --- a/x/ecocredit/server/basket/msg_put_test.go +++ b/x/ecocredit/server/basket/msg_put_test.go @@ -238,6 +238,18 @@ func (s *putSuite) ACreditBatchWithDenom(a string) { require.NoError(s.t, err) } +func (s *putSuite) AlicesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.alice = addr +} + +func (s *putSuite) EcocreditModulesAddress(a string) { + addr, err := sdk.AccAddressFromBech32(a) + require.NoError(s.t, err) + s.k.moduleAddress = addr +} + func (s *putSuite) AliceOwnsCredits() { classID := core.GetClassIDFromBatchDenom(s.batchDenom) creditTypeAbbrev := core.GetCreditTypeAbbrevFromClassID(classID) @@ -518,18 +530,6 @@ func (s *putSuite) ExpectEventTransferWithProperties(a gocuke.DocString) { require.NoError(s.t, err) } -func (s *putSuite) AlicesAddress(a string) { - addr, err := sdk.AccAddressFromBech32(a) - require.NoError(s.t, err) - s.alice = addr -} - -func (s *putSuite) EcocreditModulesAddress(a string) { - addr, err := sdk.AccAddressFromBech32(a) - require.NoError(s.t, err) - s.k.moduleAddress = addr -} - func (s *putSuite) ExpectEventPutWithProperties(a gocuke.DocString) { var event basket.EventPut err := json.Unmarshal([]byte(a.Content), &event)