-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preprocess _muxed_id fields before unmarshalling from the DB (#3722)
- Loading branch information
Showing
8 changed files
with
183 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
services/horizon/internal/integration/muxed_operations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stellar/go/clients/horizonclient" | ||
"github.com/stellar/go/keypair" | ||
"github.com/stellar/go/protocols/horizon/effects" | ||
"github.com/stellar/go/services/horizon/internal/test/integration" | ||
"github.com/stellar/go/txnbuild" | ||
"github.com/stellar/go/xdr" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMuxedOperations(t *testing.T) { | ||
itest := integration.NewTest(t, integration.Config{ProtocolVersion: 17}) | ||
|
||
sponsored := keypair.MustRandom() | ||
// Is there an easier way? | ||
sponsoredMuxed := xdr.MustMuxedAddress(sponsored.Address()) | ||
sponsoredMuxed.Type = xdr.CryptoKeyTypeKeyTypeMuxedEd25519 | ||
sponsoredMuxed.Med25519 = &xdr.MuxedAccountMed25519{ | ||
Ed25519: *sponsoredMuxed.Ed25519, | ||
Id: 100, | ||
} | ||
|
||
master := itest.Master() | ||
masterMuxed := xdr.MustMuxedAddress(master.Address()) | ||
masterMuxed.Type = xdr.CryptoKeyTypeKeyTypeMuxedEd25519 | ||
masterMuxed.Med25519 = &xdr.MuxedAccountMed25519{ | ||
Ed25519: *masterMuxed.Ed25519, | ||
Id: 200, | ||
} | ||
|
||
ops := []txnbuild.Operation{ | ||
&txnbuild.BeginSponsoringFutureReserves{ | ||
SponsoredID: sponsored.Address(), | ||
}, | ||
&txnbuild.CreateAccount{ | ||
Destination: sponsored.Address(), | ||
Amount: "100", | ||
}, | ||
&txnbuild.ChangeTrust{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Line: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Limit: txnbuild.MaxTrustlineLimit, | ||
}, | ||
&txnbuild.ManageSellOffer{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Selling: txnbuild.NativeAsset{}, | ||
Buying: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Amount: "3", | ||
Price: "1", | ||
}, | ||
// This will generate a trade effect: | ||
&txnbuild.ManageSellOffer{ | ||
SourceAccount: masterMuxed.Address(), | ||
Selling: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Buying: txnbuild.NativeAsset{}, | ||
Amount: "3", | ||
Price: "1", | ||
}, | ||
&txnbuild.ManageData{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Name: "test", | ||
Value: []byte("test"), | ||
}, | ||
&txnbuild.Payment{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: master.Address(), | ||
Amount: "1", | ||
Asset: txnbuild.NativeAsset{}, | ||
}, | ||
&txnbuild.CreateClaimableBalance{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Amount: "2", | ||
Asset: txnbuild.NativeAsset{}, | ||
Destinations: []txnbuild.Claimant{ | ||
txnbuild.NewClaimant(keypair.MustRandom().Address(), nil), | ||
}, | ||
}, | ||
&txnbuild.EndSponsoringFutureReserves{ | ||
SourceAccount: sponsored.Address(), | ||
}, | ||
} | ||
txResp, err := itest.SubmitMultiSigOperations(itest.MasterAccount(), []*keypair.Full{master, sponsored}, ops...) | ||
assert.NoError(t, err) | ||
assert.True(t, txResp.Successful) | ||
|
||
ops = []txnbuild.Operation{ | ||
// Remove subentries to be able to merge account | ||
&txnbuild.Payment{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: master.Address(), | ||
Amount: "3", | ||
Asset: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
}, | ||
&txnbuild.ChangeTrust{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Line: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Limit: "0", | ||
}, | ||
&txnbuild.ManageData{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Name: "test", | ||
}, | ||
&txnbuild.AccountMerge{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: masterMuxed.Address(), | ||
}, | ||
} | ||
txResp, err = itest.SubmitMultiSigOperations(itest.MasterAccount(), []*keypair.Full{master, sponsored}, ops...) | ||
assert.NoError(t, err) | ||
assert.True(t, txResp.Successful) | ||
|
||
// Check if no 5xx after processing the tx above | ||
// TODO expand it to test actual muxed fields | ||
_, err = itest.Client().Operations(horizonclient.OperationRequest{Limit: 200}) | ||
assert.NoError(t, err, "/operations failed") | ||
|
||
_, err = itest.Client().Payments(horizonclient.OperationRequest{Limit: 200}) | ||
assert.NoError(t, err, "/payments failed") | ||
|
||
effectsPage, err := itest.Client().Effects(horizonclient.EffectRequest{Limit: 200}) | ||
assert.NoError(t, err, "/effects failed") | ||
|
||
for _, effect := range effectsPage.Embedded.Records { | ||
if effect.GetType() == "trade" { | ||
trade := effect.(effects.Trade) | ||
oneSet := trade.AccountMuxedID != 0 || trade.SellerMuxedID != 0 | ||
assert.True(t, oneSet, "at least one of account_muxed_id, seller_muxed_id must be set") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters