diff --git a/x/exchange/events.go b/x/exchange/events.go index 2b07a81fff..380949274b 100644 --- a/x/exchange/events.go +++ b/x/exchange/events.go @@ -54,6 +54,24 @@ func NewEventOrderExternalIDUpdated(order OrderI) *EventOrderExternalIDUpdated { } } +func NewEventFundsCommitted(account string, marketID uint32, amount sdk.Coins, tag string) *EventFundsCommitted { + return &EventFundsCommitted{ + Account: account, + MarketId: marketID, + Amount: amount.String(), + Tag: tag, + } +} + +func NewEventFundsReleased(account string, marketID uint32, amount sdk.Coins, tag string) *EventFundsReleased { + return &EventFundsReleased{ + Account: account, + MarketId: marketID, + Amount: amount.String(), + Tag: tag, + } +} + func NewEventMarketWithdraw(marketID uint32, amount sdk.Coins, destination sdk.AccAddress, withdrawnBy string) *EventMarketWithdraw { return &EventMarketWithdraw{ MarketId: marketID, @@ -94,7 +112,7 @@ func NewEventMarketDisabled(marketID uint32, updatedBy string) *EventMarketDisab } // NewEventMarketUserSettleUpdated returns a new EventMarketUserSettleEnabled if isAllowed == true, -// or a new EventMarketUserSettleDisabled if isActive == false. +// or a new EventMarketUserSettleDisabled if isAllowed == false. func NewEventMarketUserSettleUpdated(marketID uint32, updatedBy string, isAllowed bool) proto.Message { if isAllowed { return NewEventMarketUserSettleEnabled(marketID, updatedBy) @@ -116,6 +134,36 @@ func NewEventMarketUserSettleDisabled(marketID uint32, updatedBy string) *EventM } } +// NewEventMarketAllowCommitmentsUpdated returns a new NewEventMarketCommitmentsEnabled if isAllowed == true, +// or a new NewEventMarketCommitmentsDisabled if isAllowed == false. +func NewEventMarketAllowCommitmentsUpdated(marketID uint32, updatedBy string, isAllowed bool) proto.Message { + if isAllowed { + return NewEventMarketCommitmentsEnabled(marketID, updatedBy) + } + return NewEventMarketCommitmentsDisabled(marketID, updatedBy) +} + +func NewEventMarketCommitmentsEnabled(marketID uint32, updatedBy string) *EventMarketCommitmentsEnabled { + return &EventMarketCommitmentsEnabled{ + MarketId: marketID, + UpdatedBy: updatedBy, + } +} + +func NewEventMarketCommitmentsDisabled(marketID uint32, updatedBy string) *EventMarketCommitmentsDisabled { + return &EventMarketCommitmentsDisabled{ + MarketId: marketID, + UpdatedBy: updatedBy, + } +} + +func NewEventMarketIntermediaryDenomUpdated(marketID uint32, updatedBy string) *EventMarketIntermediaryDenomUpdated { + return &EventMarketIntermediaryDenomUpdated{ + MarketId: marketID, + UpdatedBy: updatedBy, + } +} + func NewEventMarketPermissionsUpdated(marketID uint32, updatedBy string) *EventMarketPermissionsUpdated { return &EventMarketPermissionsUpdated{ MarketId: marketID, diff --git a/x/exchange/events_test.go b/x/exchange/events_test.go index 211308e57b..b1db2fe6d5 100644 --- a/x/exchange/events_test.go +++ b/x/exchange/events_test.go @@ -368,6 +368,10 @@ func TestNewEventOrderExternalIDUpdated(t *testing.T) { } } +// TODO[1789]: func TestNewEventFundsCommitted(t *testing.T) + +// TODO[1789]: func TestNewEventFundsReleased(t *testing.T) + func TestNewEventMarketWithdraw(t *testing.T) { marketID := uint32(55) amountWithdrawn := sdk.NewCoins(sdk.NewInt64Coin("mine", 188382), sdk.NewInt64Coin("yours", 3)) @@ -537,6 +541,14 @@ func TestNewEventMarketUserSettleDisabled(t *testing.T) { assertEverythingSet(t, event, "EventMarketUserSettleDisabled") } +// TODO[1789]: func TestNewEventMarketAllowCommitmentsUpdated(t *testing.T) + +// TODO[1789]: func TestNewEventMarketCommitmentsEnabled(t *testing.T) + +// TODO[1789]: func TestNewEventMarketCommitmentsDisabled(t *testing.T) + +// TODO[1789]: func TestNewEventMarketIntermediaryDenomUpdated(t *testing.T) + func TestNewEventMarketPermissionsUpdated(t *testing.T) { marketID := uint32(5432) updatedBy := sdk.AccAddress("updatedBy___________").String() @@ -602,6 +614,8 @@ func TestTypedEventToEvent(t *testing.T) { quoteBz := func(str string) []byte { return []byte(fmt.Sprintf("%q", str)) } + account := "account_____________" + accountQ := quoteBz(account) cancelledBy := "cancelledBy_________" cancelledByQ := quoteBz(cancelledBy) destination := sdk.AccAddress("destination_________") @@ -784,6 +798,32 @@ func TestTypedEventToEvent(t *testing.T) { }, }, }, + { + name: "EventFundsCommitted", + tev: NewEventFundsCommitted(account, 44, coins1, "tagTagTAG"), + expEvent: sdk.Event{ + Type: "provenance.exchange.v1.EventFundsCommitted", + Attributes: []abci.EventAttribute{ + {Key: []byte("account"), Value: accountQ}, + {Key: []byte("amount"), Value: coins1Q}, + {Key: []byte("market_id"), Value: []byte("44")}, + {Key: []byte("tag"), Value: quoteBz("tagTagTAG")}, + }, + }, + }, + { + name: "EventFundsReleased", + tev: NewEventFundsReleased(account, 15, coins1, "something"), + expEvent: sdk.Event{ + Type: "provenance.exchange.v1.EventFundsReleased", + Attributes: []abci.EventAttribute{ + {Key: []byte("account"), Value: accountQ}, + {Key: []byte("amount"), Value: coins1Q}, + {Key: []byte("market_id"), Value: []byte("15")}, + {Key: []byte("tag"), Value: quoteBz("something")}, + }, + }, + }, { name: "EventMarketWithdraw", tev: NewEventMarketWithdraw(6, coins1, destination, withdrawnBy.String()), @@ -852,6 +892,39 @@ func TestTypedEventToEvent(t *testing.T) { }, }, }, + { + name: "EventMarketCommitmentsEnabled", + tev: NewEventMarketCommitmentsEnabled(52, updatedBy), + expEvent: sdk.Event{ + Type: "provenance.exchange.v1.EventMarketCommitmentsEnabled", + Attributes: []abci.EventAttribute{ + {Key: []byte("market_id"), Value: []byte("52")}, + {Key: []byte("updated_by"), Value: updatedByQ}, + }, + }, + }, + { + name: "EventMarketCommitmentsDisabled", + tev: NewEventMarketCommitmentsDisabled(25, updatedBy), + expEvent: sdk.Event{ + Type: "provenance.exchange.v1.EventMarketCommitmentsDisabled", + Attributes: []abci.EventAttribute{ + {Key: []byte("market_id"), Value: []byte("25")}, + {Key: []byte("updated_by"), Value: updatedByQ}, + }, + }, + }, + { + name: "EventMarketIntermediaryDenomUpdated", + tev: NewEventMarketIntermediaryDenomUpdated(18, updatedBy), + expEvent: sdk.Event{ + Type: "provenance.exchange.v1.EventMarketIntermediaryDenomUpdated", + Attributes: []abci.EventAttribute{ + {Key: []byte("market_id"), Value: []byte("18")}, + {Key: []byte("updated_by"), Value: updatedByQ}, + }, + }, + }, { name: "EventMarketPermissionsUpdated", tev: NewEventMarketPermissionsUpdated(12, updatedBy),