Skip to content

Commit

Permalink
#81: Expand on pathpayment strict send assertions, add path payment s…
Browse files Browse the repository at this point in the history
…trict receive test
  • Loading branch information
aristidesstaffieri committed Nov 27, 2024
1 parent 9b9b259 commit f4b5257
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion internal/services/ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,93 @@ func TestIngestPathPaymentsSend(t *testing.T) {
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, "efgh")
assert.Equal(t, payments[0].TransactionHash, *&ledgerTransaction.Hash)

Check failure on line 292 in internal/services/ingest_test.go

View workflow job for this annotation

GitHub Actions / check

SA4001: *&x will be simplified to x. It will not copy x. (staticcheck)
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")
})
}

func TestIngestPathPaymentsReceive(t *testing.T) {
dbt := dbtest.Open(t)
defer dbt.Close()

dbConnectionPool, err := db.OpenDBConnectionPool(dbt.DSN)
require.NoError(t, err)
defer dbConnectionPool.Close()
models, _ := data.NewModels(dbConnectionPool)
mockAppTracker := apptracker.MockAppTracker{}
mockRPCService := RPCServiceMock{}
mockRouter := tssrouter.MockRouter{}
tssStore, _ := tssstore.NewStore(dbConnectionPool)
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_path_payment_receive", 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.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)

signer := keypair.MustRandom()
errSigner := models.Account.Insert(context.Background(), signer.Address())
require.NoError(t, errSigner)

signedTx, err := transaction.Sign(network.TestNetworkPassphrase, signer)
require.NoError(t, err)

txEnvXDR, err := signedTx.Base64()
require.NoError(t, err)

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)

Check failure on line 369 in internal/services/ingest_test.go

View workflow job for this annotation

GitHub Actions / check

ineffectual assignment to err (ineffassign)

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)

Check failure on line 374 in internal/services/ingest_test.go

View workflow job for this annotation

GitHub Actions / check

SA4001: *&x will be simplified to x. It will not copy x. (staticcheck)
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")
})
}

0 comments on commit f4b5257

Please sign in to comment.