Skip to content
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

First end-to-end transaction Integration test (with http-bridge) #281

Merged
merged 4 commits into from
May 20, 2019

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented May 17, 2019

Issue Number

Overview

  • I have added a simple scenario illustrating sending a transaction from a wallet to another. The transaction has a single output and only selects one input, but it's a start 🎉

Comments

I slightly adjusted the tx size estimator... Seems like we are sometimes off by one byte. I say sometimes because, the node will sometimes be fine with our calculation, and sometimes compute a size that is one byte bigger than what we compute. This is rather weird as I would expect the calculation of a transaction size to be 100% deterministic but cardano-sl is full of surprises. T be honest, we don't have time anymore to look deeper into this. Going for the simple approach here and added +1 to our estimate :/

KtorZ added 4 commits May 17, 2019 18:09
Seems like we are _sometimes_ off by one byte. I say sometimes because, the node will sometimes
be fine with our calculation, and sometimes compute a size that is one byte bigger than what we
compute. This is rather weird and to be honest, we don't have time anymore to look deeper into
this. Going for the simple approach here
@KtorZ KtorZ requested review from paweljakubas and piotr-iohk May 17, 2019 16:12
@KtorZ KtorZ self-assigned this May 17, 2019
"Err submitting transaction: protocol failure: "
<> pretty err
}
ErrSubmitTxNoSuchWallet _ -> err404
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Ideally, we should do this for pretty much all errors as well as making sure we add more context to our errors!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to have.

For an API consumer it is nicer to have error messages as JSON responses (e.g. { "status": "error", "message": "Submiting transaction: protocol failure" }). Then the API consumer can always parse all responses as JSON, rather than worrying about whether it will be text/plain or application/json.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Ideally, something more like { "code": <an_error_code>, "message": <description / message> }, the status is redundant with the HTTP status. However, having a clear discriminant is helpful for clients like Daedalus (instead of having to grep on the message).

Copy link
Contributor

@rvl rvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, a test using local nodes, sending 1 ada from a test wallet to another test wallet.

verify r'
[ expectFieldEqual balanceTotal oneMillionAda
, expectFieldEqual balanceAvailable oneMillionAda
]

it "Single Output Transaction" $ \ctx -> do
(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not write this over two lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. Probably because conceptually, I still prefer using a monadic approach when the ordering of events is relevant. Here, using applicative makes it clear that these two actions could happen in any order, they don't depend on each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I am fine with either ways, the do-notation is perhaps more readable.

(wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx
(_, addrs) <-
unsafeRequest @[ApiAddress] ctx ("GET", getAddresses wb) Empty
let destination = (addrs !! 1) ^. #id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the second address from the wallet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one is already used to inject the initial funds from the faucet. So, it could be any addresses between the 1st and the 21th (with a default gap)

verify r'
[ expectSuccess
, expectEventually ctx balanceAvailable (oneMillionAda + 1)
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding another expectation that the tx in wallet A is eventually confirmed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be! Once we have this feature 😬 ... We can't list or fetch transactions at the moment.

"Err submitting transaction: protocol failure: "
<> pretty err
}
ErrSubmitTxNoSuchWallet _ -> err404
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to have.

For an API consumer it is nicer to have error messages as JSON responses (e.g. { "status": "error", "message": "Submiting transaction: protocol failure" }). Then the API consumer can always parse all responses as JSON, rather than worrying about whether it will be text/plain or application/json.

@piotr-iohk piotr-iohk merged commit 56019ea into master May 20, 2019
@iohk-bors iohk-bors bot deleted the KtorZ/transaction-integration-tests branch May 20, 2019 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants