Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erokhinav committed Sep 18, 2024
1 parent ac7be17 commit e5184a8
Show file tree
Hide file tree
Showing 45 changed files with 402 additions and 126 deletions.
2 changes: 1 addition & 1 deletion pkg/api/emulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func emulatedTreeToTrace(
transaction, err := core.ConvertTransaction(int32(a.AddrStd.WorkchainId), tongo.Transaction{
Transaction: tree.TX,
BlockID: tongo.BlockIDExt{BlockID: tongo.BlockID{Workchain: int32(a.AddrStd.WorkchainId)}},
})
}, nil)
filteredMsgs := make([]core.Message, 0, len(transaction.OutMsgs))
for _, msg := range transaction.OutMsgs {
if msg.Destination == nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/api/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (h *Handler) GetEvent(ctx context.Context, params oas.GetEventParams) (*oas
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace.Transaction, actions)
result := bath.EnrichWithIntentions(trace, actions)
event, err := h.toEvent(ctx, trace, result, params.AcceptLanguage)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -235,12 +235,13 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
skippedInProgress = append(skippedInProgress, traceID.Hash)
continue
}
result, err := bath.FindActions(ctx, trace, bath.ForAccount(account.ID), bath.WithInformationSource(h.storage))
actions, err := bath.FindActions(ctx, trace, bath.ForAccount(account.ID), bath.WithInformationSource(h.storage))
if err != nil {
events = append(events, h.toUnknownAccountEvent(account.ID, traceID))
continue
//return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
e, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
if err != nil {
events = append(events, h.toUnknownAccountEvent(account.ID, traceID))
Expand All @@ -263,10 +264,11 @@ func (h *Handler) GetAccountEvents(ctx context.Context, params oas.GetAccountEve
continue
}
i++
result, err := bath.FindActions(ctx, trace, bath.ForAccount(account.ID), bath.WithInformationSource(h.storage))
actions, err := bath.FindActions(ctx, trace, bath.ForAccount(account.ID), bath.WithInformationSource(h.storage))
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
result := bath.EnrichWithIntentions(trace, actions)
event, err := h.toAccountEvent(ctx, account.ID, trace, result, params.AcceptLanguage, params.SubjectOnly.Value)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/bath/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type (
InscriptionTransfer *InscriptionTransferAction `json:",omitempty"`
Success bool
Type ActionType
Description string
Error *string
BaseTransactions []ton.Bits256
}
TonTransferAction struct {
Expand Down
18 changes: 18 additions & 0 deletions pkg/bath/bath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func TestFindActions(t *testing.T) {
tongo.MustParseBlockID("(0,8000000000000000,34021598)"),
// nft transfer
tongo.MustParseBlockID("(0,8000000000000000,33600829)"),
// failed dedust swap
tongo.MustParseBlockID("(0,7000000000000000,45592983)"),
}),
)

Expand Down Expand Up @@ -394,6 +396,21 @@ func TestFindActions(t *testing.T) {
hash: "e27cdf1d6987a3e74dc8d9c4a52a5b22112fe3946d0dceadf8160b74f80b9d46",
filenamePrefix: "governance_jetton_mint",
},
{
name: "failed simple transfer",
hash: "63d358331c0154ade48ab92b4634c3fff004f42ce7201a37973938862d232c0f",
filenamePrefix: "failed-simple-transfer",
},
{
name: "simple transfers, one of two failed",
hash: "ac0b8bf04949cb72759832ec6c123b3677b8ca140899ac859aa66a558e4f4c11",
filenamePrefix: "simple-transfers-one-failed",
},
{
name: "failed dedust swap",
hash: "887c7763f41ca4a4b9de28900ab514caabc0c27ed5b41d9918d60f5e7f4a9d96",
filenamePrefix: "failed-dedust-swap",
},
} {
t.Run(c.name, func(t *testing.T) {
trace, err := storage.GetTrace(context.Background(), tongo.MustParseHash(c.hash))
Expand All @@ -411,6 +428,7 @@ func TestFindActions(t *testing.T) {
WithStraws(straws),
WithInformationSource(source))
require.Nil(t, err)
actionsList = EnrichWithIntentions(trace, actionsList)
results := result{
Actions: actionsList.Actions,
}
Expand Down
Loading

0 comments on commit e5184a8

Please sign in to comment.