Skip to content

Commit

Permalink
fixed a bug with filtering out fungibleToken deposit/transfer events …
Browse files Browse the repository at this point in the history
…and fixed fee receipient on previewnet
  • Loading branch information
bjartek committed Feb 28, 2024
1 parent 1211fec commit debbac8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
12 changes: 8 additions & 4 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (overflowEvents OverflowEvents) FilterTempWithdrawDeposit() OverflowEvents
return filteredEvents
}

var feeReceipients = []string{"0xf919ee77447b7497", "0x912d5440f7e3769e", "0xe5a8b7f23e8b548f"}
var feeReceipients = []string{"0xf919ee77447b7497", "0x912d5440f7e3769e", "0xe5a8b7f23e8b548f", "0xab086ce9cc29fc80"}

// Filtter out fee events
func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) OverflowEvents {
Expand All @@ -245,6 +245,8 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
if ok && amount == fee && from == payer {
continue
}

withDrawnEvents = append(withDrawnEvents, value)
}
if len(withDrawnEvents) != 0 {
filteredEvents[name] = withDrawnEvents
Expand All @@ -254,7 +256,7 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
}

if strings.HasSuffix(name, ".FungibleToken.Deposited") {
withDrawnEvents := []OverflowEvent{}
depositEvents := []OverflowEvent{}
for _, value := range events {
ftType := value.Fields["type"].(string)
if !strings.HasSuffix(ftType, "FlowToken.Vault") {
Expand All @@ -266,13 +268,15 @@ func (overflowEvents OverflowEvents) FilterFees(fee float64, payer string) Overf
if ok && amount == fee && slices.Contains(feeReceipients, to) {
continue
}
depositEvents = append(depositEvents, value)
}
if len(withDrawnEvents) != 0 {
filteredEvents[name] = withDrawnEvents
if len(depositEvents) != 0 {
filteredEvents[name] = depositEvents
} else {
delete(filteredEvents, name)
}
}

if strings.HasSuffix(name, "FlowToken.TokensWithdrawn") {

withDrawnEvents := []OverflowEvent{}
Expand Down
12 changes: 6 additions & 6 deletions event_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestIntegrationEvents(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)

_, err = g.FetchEvents(
WithEndIndex(2),
Expand All @@ -39,7 +39,7 @@ func TestIntegrationEvents(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)
ev, err := g.FetchEvents(WithLastBlocks(2), WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"))
assert.NoError(t, err)
assert.Equal(t, 2, len(ev))
Expand All @@ -53,14 +53,14 @@ func TestIntegrationEvents(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)

g.Tx("mint_tokens",
WithSignerServiceAccount(),
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)

ev, err := g.FetchEvents(WithLastBlocks(2), WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"))
assert.NoError(t, err)
Expand All @@ -76,7 +76,7 @@ func TestIntegrationEvents(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)

ev, err := g.FetchEvents(WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), WithTrackProgressIn("progress"))
defer os.Remove("progress")
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestIntegrationEvents(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.0),
).AssertSuccess(t).
AssertEventCount(t, 3)
AssertEventCount(t, 4)

ev, err := g.FetchEvents(WithEvent("A.0ae53cb6e3f42a79.FlowToken.TokensMinted"), WithTrackProgressIn("progress"))
defer os.Remove("progress")
Expand Down
1 change: 0 additions & 1 deletion interaction_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ func (oib OverflowInteractionBuilder) Send() *OverflowResult {
if oib.Overflow.FilterOutFeeEvents && fee != nil {
overflowEvents = overflowEvents.FilterFees(fee.(float64), fmt.Sprintf("0x%s", result.Transaction.Payer.Hex()))
}

if oib.Overflow.FilterOutEmptyWithDrawDepositEvents {
overflowEvents = overflowEvents.FilterTempWithdrawDeposit()
}
Expand Down
13 changes: 7 additions & 6 deletions transaction_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func TestTransactionIntegration(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.1)).
AssertSuccess(t).
AssertEventCount(t, 3).
AssertEmitEventName(t, "FlowToken.TokensDeposited").
AssertEventCount(t, 4).
AssertEvent(t, "FlowToken.TokensDeposited", map[string]interface{}{
"amount": 100.1,
},
)
}).
AssertEvent(t, "FungibleToken.Deposited", map[string]interface{}{
"amount": 100.1,
})
require.NoError(t, result.Err)

oTx, err := o.GetOverflowTransactionById(context.Background(), result.Transaction.ID())
Expand Down Expand Up @@ -69,13 +70,13 @@ func TestTransactionIntegration(t *testing.T) {
WithArg("recipient", "first"),
WithArg("amount", 100.1)).
AssertSuccess(t).
AssertEventCount(t, 3).
AssertEventCount(t, 4).
AssertEmitEventName(t, "FlowToken.TokensDeposited").
AssertEvent(t, "FlowToken.TokensDeposited", map[string]interface{}{
"amount": 100.1,
},
)
assert.Equal(t, 1, len(result.GetEventsWithName("TokensDeposited")))
assert.Equal(t, 1, len(result.GetEventsWithName("FungibleToken.Deposited")))

report := o.GetCoverageReport()
assert.Equal(t, "18.5%", report.Summary().Coverage)
Expand Down

0 comments on commit debbac8

Please sign in to comment.