Skip to content

Commit

Permalink
Export index and id in history_effects table (#264)
Browse files Browse the repository at this point in the history
* Export index and id in effects table

* Format

* Update tests

* empty

* empty

---------

Co-authored-by: Amisha Singla <[email protected]>
  • Loading branch information
amishas157 and Amisha Singla authored Jul 10, 2024
1 parent b3fb467 commit e6a47f9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/transform/effects.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func (operation *transactionOperationWrapper) effects() ([]EffectOutput, error)
for i := range wrapper.effects {
wrapper.effects[i].LedgerClosed = operation.ledgerClosed
wrapper.effects[i].LedgerSequence = operation.ledgerSequence
wrapper.effects[i].EffectIndex = uint32(i)
wrapper.effects[i].EffectId = fmt.Sprintf("%d-%d", wrapper.effects[i].OperationID, wrapper.effects[i].EffectIndex)
}

return wrapper.effects, nil
Expand Down
53 changes: 53 additions & 0 deletions internal/transform/effects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transform
import (
"crypto/rand"
"encoding/hex"
"fmt"
"math/big"
"strings"
"testing"
Expand Down Expand Up @@ -1738,6 +1739,10 @@ func TestOperationEffects(t *testing.T) {
ledgerSequence: tc.sequence,
ledgerClosed: LedgerClosed,
}
for i := range tc.expected {
tc.expected[i].EffectIndex = uint32(i)
tc.expected[i].EffectId = fmt.Sprintf("%d-%d", tc.expected[i].OperationID, tc.expected[i].EffectIndex)
}

effects, err := operation.effects()
tt.NoError(err)
Expand Down Expand Up @@ -1882,6 +1887,11 @@ func TestOperationEffectsSetOptionsSignersOrder(t *testing.T) {
LedgerSequence: 46,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2008,6 +2018,11 @@ func TestOperationEffectsSetOptionsSignersNoUpdated(t *testing.T) {
LedgerSequence: 46,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2112,6 +2127,11 @@ func TestOperationEffectsAllowTrustAuthorizedToMaintainLiabilities(t *testing.T)
LedgerSequence: 1,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2177,6 +2197,11 @@ func TestOperationEffectsClawback(t *testing.T) {
LedgerSequence: 1,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2225,6 +2250,11 @@ func TestOperationEffectsClawbackClaimableBalance(t *testing.T) {
LedgerSequence: 1,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2283,6 +2313,11 @@ func TestOperationEffectsSetTrustLineFlags(t *testing.T) {
LedgerSequence: 1,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

tt.Equal(expected, effects)
}

Expand Down Expand Up @@ -2484,6 +2519,10 @@ func TestTrustlineSponsorhipEffects(t *testing.T) {
LedgerSequence: 1,
},
}
for i := range expected {
expected[i].EffectIndex = uint32(i)
expected[i].EffectId = fmt.Sprintf("%d-%d", expected[i].OperationID, expected[i].EffectIndex)
}

// pick an operation with no intrinsic effects
// (the sponsosrhip effects are obtained from the changes, so it doesn't matter)
Expand Down Expand Up @@ -3169,6 +3208,11 @@ func TestLiquidityPoolEffects(t *testing.T) {
},
}

for i := range tc.expected {
tc.expected[i].EffectIndex = uint32(i)
tc.expected[i].EffectId = fmt.Sprintf("%d-%d", tc.expected[i].OperationID, tc.expected[i].EffectIndex)
}

t.Run(tc.desc, func(t *testing.T) {
operation := transactionOperationWrapper{
index: 0,
Expand Down Expand Up @@ -3785,6 +3829,11 @@ func TestInvokeHostFunctionEffects(t *testing.T) {
network: networkPassphrase,
}

for i := range testCase.expected {
testCase.expected[i].EffectIndex = uint32(i)
testCase.expected[i].EffectId = fmt.Sprintf("%d-%d", testCase.expected[i].OperationID, testCase.expected[i].EffectIndex)
}

effects, err := operation.effects()
assert.NoErrorf(t, err, "event type %v", testCase.eventType)
assert.Lenf(t, effects, len(testCase.expected), "event type %v", testCase.eventType)
Expand Down Expand Up @@ -3970,6 +4019,8 @@ func TestBumpFootprintExpirationEffects(t *testing.T) {
TypeString: EffectTypeNames[EffectExtendFootprintTtl],
LedgerClosed: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LedgerSequence: 1,
EffectIndex: 0,
EffectId: fmt.Sprintf("%d-%d", toid.New(1, 0, 1).ToInt64(), 0),
},
},
effects,
Expand Down Expand Up @@ -4085,6 +4136,8 @@ func TestAddRestoreFootprintExpirationEffect(t *testing.T) {
TypeString: EffectTypeNames[EffectRestoreFootprint],
LedgerClosed: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
LedgerSequence: 1,
EffectIndex: 0,
EffectId: fmt.Sprintf("%d-%d", toid.New(1, 0, 1).ToInt64(), 0),
},
},
effects,
Expand Down
2 changes: 2 additions & 0 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ type EffectOutput struct {
TypeString string `json:"type_string"`
LedgerClosed time.Time `json:"closed_at"`
LedgerSequence uint32 `json:"ledger_sequence"`
EffectIndex uint32 `json:"index"`
EffectId string `json:"id"`
}

// EffectType is the numeric type for an effect
Expand Down

0 comments on commit e6a47f9

Please sign in to comment.