-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[services][feat] #81: Add test for ingesting path payments #84
base: main
Are you sure you want to change the base?
Changes from all commits
9b9b259
f4b5257
90f7d32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"testing" | ||
|
||
"github.com/stellar/go/keypair" | ||
"github.com/stellar/go/network" | ||
"github.com/stellar/go/txnbuild" | ||
"github.com/stellar/go/xdr" | ||
"github.com/stellar/wallet-backend/internal/apptracker" | ||
|
@@ -177,6 +178,9 @@ func TestIngestPayments(t *testing.T) { | |
ingestService, _ := NewIngestService(models, "ingestionLedger", &mockAppTracker, &mockRPCService, &mockRouter, tssStore) | ||
srcAccount := keypair.MustRandom().Address() | ||
destAccount := keypair.MustRandom().Address() | ||
usdIssuer := keypair.MustRandom().Address() | ||
eurIssuer := keypair.MustRandom().Address() | ||
|
||
t.Run("test_op_payment", func(t *testing.T) { | ||
_ = models.Account.Insert(context.Background(), srcAccount) | ||
paymentOp := txnbuild.Payment{ | ||
|
@@ -214,4 +218,131 @@ func TestIngestPayments(t *testing.T) { | |
assert.NoError(t, err) | ||
assert.Equal(t, payments[0].TransactionHash, "abcd") | ||
}) | ||
|
||
t.Run("test_op_path_payment_send", func(t *testing.T) { | ||
err := models.Account.Insert(context.Background(), srcAccount) | ||
require.NoError(t, err) | ||
|
||
path := []txnbuild.Asset{ | ||
txnbuild.CreditAsset{Code: "USD", Issuer: usdIssuer}, | ||
txnbuild.CreditAsset{Code: "EUR", Issuer: eurIssuer}, | ||
} | ||
|
||
pathPaymentOp := txnbuild.PathPaymentStrictSend{ | ||
SourceAccount: srcAccount, | ||
Destination: destAccount, | ||
DestMin: "9", | ||
SendAmount: "10", | ||
SendAsset: txnbuild.NativeAsset{}, | ||
DestAsset: txnbuild.NativeAsset{}, | ||
Path: path, | ||
} | ||
transaction, err := txnbuild.NewTransaction(txnbuild.TransactionParams{ | ||
SourceAccount: &txnbuild.SimpleAccount{ | ||
AccountID: keypair.MustRandom().Address(), | ||
}, | ||
Operations: []txnbuild.Operation{&pathPaymentOp}, | ||
Preconditions: txnbuild.Preconditions{TimeBounds: txnbuild.NewTimeout(10)}, | ||
}) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above. This can be replaced with:
|
||
|
||
signer := keypair.MustRandom() | ||
errSigner := models.Account.Insert(context.Background(), signer.Address()) | ||
require.NoError(t, errSigner) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
signedTx, err := transaction.Sign(network.TestNetworkPassphrase, signer) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
txEnvXDR, err := signedTx.Base64() | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
ledgerTransaction := entities.Transaction{ | ||
Status: entities.SuccessStatus, | ||
Hash: "efgh", | ||
ApplicationOrder: 1, | ||
FeeBump: false, | ||
EnvelopeXDR: txEnvXDR, | ||
ResultXDR: "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAANAAAAAAAAAAAAAAAAXF0V022EgeGIo6QNVbMVvHdxvvl2MfZcVZUJpfph+0QAAAAAAAAAAAX14QAAAAAA", | ||
Ledger: 1, | ||
} | ||
|
||
ledgerTransactions := []entities.Transaction{ledgerTransaction} | ||
|
||
err = ingestService.ingestPayments(context.Background(), ledgerTransactions) | ||
require.NoError(t, err) | ||
|
||
payments, _, _, err := models.Payments.GetPaymentsPaginated(context.Background(), srcAccount, "", "", data.ASC, 1) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, payments, "Expected at least one payment") | ||
assert.Equal(t, payments[0].TransactionHash, ledgerTransaction.Hash) | ||
assert.Equal(t, payments[0].SrcAmount, int64(100000000)) | ||
assert.Equal(t, payments[0].SrcAssetType, xdr.AssetTypeAssetTypeNative.String()) | ||
assert.Equal(t, payments[0].ToAddress, destAccount) | ||
assert.Equal(t, payments[0].FromAddress, srcAccount) | ||
assert.Equal(t, payments[0].SrcAssetCode, "XLM") | ||
assert.Equal(t, payments[0].DestAssetCode, "XLM") | ||
}) | ||
|
||
t.Run("test_op_path_payment_receive", func(t *testing.T) { | ||
err := models.Account.Insert(context.Background(), srcAccount) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
path := []txnbuild.Asset{ | ||
txnbuild.CreditAsset{Code: "USD", Issuer: usdIssuer}, | ||
txnbuild.CreditAsset{Code: "EUR", Issuer: eurIssuer}, | ||
} | ||
|
||
pathPaymentOp := txnbuild.PathPaymentStrictReceive{ | ||
SourceAccount: srcAccount, | ||
Destination: destAccount, | ||
SendMax: "11", | ||
DestAmount: "10", | ||
SendAsset: txnbuild.NativeAsset{}, | ||
DestAsset: txnbuild.NativeAsset{}, | ||
Path: path, | ||
} | ||
transaction, err := txnbuild.NewTransaction(txnbuild.TransactionParams{ | ||
SourceAccount: &txnbuild.SimpleAccount{ | ||
AccountID: keypair.MustRandom().Address(), | ||
}, | ||
Operations: []txnbuild.Operation{&pathPaymentOp}, | ||
Preconditions: txnbuild.Preconditions{TimeBounds: txnbuild.NewTimeout(10)}, | ||
}) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
signer := keypair.MustRandom() | ||
errSigner := models.Account.Insert(context.Background(), signer.Address()) | ||
require.NoError(t, errSigner) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
signedTx, err := transaction.Sign(network.TestNetworkPassphrase, signer) | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
txEnvXDR, err := signedTx.Base64() | ||
require.NoError(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
ledgerTransaction := entities.Transaction{ | ||
Status: entities.SuccessStatus, | ||
Hash: "efgh", | ||
ApplicationOrder: 1, | ||
FeeBump: false, | ||
EnvelopeXDR: txEnvXDR, | ||
ResultXDR: "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAACAAAAAAAAAAAAAAAAjOiEfRh4kaFVQDu/CSTZLMtnyg0DbNowZ/G2nLES3KwAAAAAAAAAAAVdSoAAAAAA", | ||
Ledger: 1, | ||
} | ||
|
||
ledgerTransactions := []entities.Transaction{ledgerTransaction} | ||
|
||
err = ingestService.ingestPayments(context.Background(), ledgerTransactions) | ||
require.NoError(t, err) | ||
|
||
payments, _, _, err := models.Payments.GetPaymentsPaginated(context.Background(), srcAccount, "", "", data.ASC, 1) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, payments, "Expected at least one payment") | ||
assert.Equal(t, payments[0].TransactionHash, ledgerTransaction.Hash) | ||
assert.Equal(t, payments[0].SrcAssetType, xdr.AssetTypeAssetTypeNative.String()) | ||
assert.Equal(t, payments[0].ToAddress, destAccount) | ||
assert.Equal(t, payments[0].FromAddress, srcAccount) | ||
assert.Equal(t, payments[0].SrcAssetCode, "XLM") | ||
assert.Equal(t, payments[0].DestAssetCode, "XLM") | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking here but I don't really think you require this line. This is not a test to see if models are working. I'd replace it with _ := models.Account.Insert(context.Background(), srcAccount)