Skip to content

Commit

Permalink
services/horizon/internal/expingest: Fix signer update effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuiles committed Mar 2, 2020
1 parent a7b48ae commit 8ccaaf4
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,13 @@ func (operation *transactionOperationWrapper) setOptionsEffects() ([]effect, err
})
continue
}
effects.add(source.Address(), history.EffectSignerUpdated, map[string]interface{}{
"public_key": addy,
"weight": weight,
})

if weight != before[addy] {
effects.add(source.Address(), history.EffectSignerUpdated, map[string]interface{}{
"public_key": addy,
"weight": weight,
})
}
}

afterSortedSigners := []string{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,120 @@ func TestOperationEffectsSetOptionsSignersOrder(t *testing.T) {
tt.Equal(expected, effects)
}

// Regression for https://github.com/stellar/go/issues/2136
func TestOperationEffectsSetOptionsSignersNoUpdated(t *testing.T) {
tt := assert.New(t)
transaction := io.LedgerTransaction{
Meta: createTransactionMeta([]xdr.OperationMeta{
xdr.OperationMeta{
Changes: []xdr.LedgerEntryChange{
// State
xdr.LedgerEntryChange{
Type: xdr.LedgerEntryChangeTypeLedgerEntryState,
State: &xdr.LedgerEntry{
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"),
Signers: []xdr.Signer{
xdr.Signer{
Key: xdr.MustSigner("GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV"),
Weight: 10,
},
xdr.Signer{
Key: xdr.MustSigner("GCAHY6JSXQFKWKP6R7U5JPXDVNV4DJWOWRFLY3Y6YPBF64QRL4BPFDNS"),
Weight: 10,
},
xdr.Signer{
Key: xdr.MustSigner("GA4O5DLUUTLCTMM2UOWOYPNIH2FTD4NLO6KDZOFQRUISQ3FYKABGJLPC"),
Weight: 17,
},
},
},
},
},
},
// Updated
xdr.LedgerEntryChange{
Type: xdr.LedgerEntryChangeTypeLedgerEntryUpdated,
Updated: &xdr.LedgerEntry{
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress("GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML"),
Signers: []xdr.Signer{
xdr.Signer{
Key: xdr.MustSigner("GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV"),
Weight: 16,
},
xdr.Signer{
Key: xdr.MustSigner("GCAHY6JSXQFKWKP6R7U5JPXDVNV4DJWOWRFLY3Y6YPBF64QRL4BPFDNS"),
Weight: 10,
},
xdr.Signer{
Key: xdr.MustSigner("GCR3TQ2TVH3QRI7GQMC3IJGUUBR32YQHWBIKIMTYRQ2YH4XUTDB75UKE"),
Weight: 14,
},
},
},
},
},
},
},
},
}),
}
transaction.Index = 1
transaction.Envelope.Tx.SourceAccount = xdr.MustAddress("GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV")

operation := transactionOperationWrapper{
index: 0,
transaction: transaction,
operation: xdr.Operation{
Body: xdr.OperationBody{
Type: xdr.OperationTypeSetOptions,
SetOptionsOp: &xdr.SetOptionsOp{},
},
},
ledgerSequence: 46,
}

effects, err := operation.effects()
tt.NoError(err)
expected := []effect{
effect{
address: "GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV",
operationID: int64(197568499713),
details: map[string]interface{}{
"public_key": "GA4O5DLUUTLCTMM2UOWOYPNIH2FTD4NLO6KDZOFQRUISQ3FYKABGJLPC",
},
effectType: history.EffectSignerRemoved,
order: uint32(1),
},
effect{
address: "GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV",
operationID: int64(197568499713),
details: map[string]interface{}{
"public_key": "GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV",
"weight": int32(16),
},
effectType: history.EffectSignerUpdated,
order: uint32(2),
},
effect{
address: "GCBBDQLCTNASZJ3MTKAOYEOWRGSHDFAJVI7VPZUOP7KXNHYR3HP2BUKV",
operationID: int64(197568499713),
details: map[string]interface{}{
"public_key": "GCR3TQ2TVH3QRI7GQMC3IJGUUBR32YQHWBIKIMTYRQ2YH4XUTDB75UKE",
"weight": int32(14),
},
effectType: history.EffectSignerCreated,
order: uint32(3),
},
}
tt.Equal(expected, effects)
}

func TestOperationRegressionAccountTrustItself(t *testing.T) {
tt := assert.New(t)
// NOTE: when an account trusts itself, the transaction is successful but
Expand Down

0 comments on commit 8ccaaf4

Please sign in to comment.