Skip to content

Commit

Permalink
[1789]: Write Event constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Jan 13, 2024
1 parent 3206d17 commit b30f73b
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
50 changes: 49 additions & 1 deletion x/exchange/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
73 changes: 73 additions & 0 deletions x/exchange/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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_________")
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit b30f73b

Please sign in to comment.