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

Add integration tests #85

Merged
merged 2 commits into from
Aug 11, 2022
Merged

Add integration tests #85

merged 2 commits into from
Aug 11, 2022

Conversation

KonradStaniec
Copy link
Collaborator

@KonradStaniec KonradStaniec commented Aug 7, 2022

Add:

  • integration test
  • make file targets for testing
  • useful query to light client, for getting current best header

I will add CI step in next pr as this require some fiddling with ip address so that testsuite can hit testnet containers and this pr is already quite big.

Currently it can be ran locally with:

make localnet-start
make test-babylon-integration
make localnet-stop

@KonradStaniec KonradStaniec force-pushed the add-integration-tests branch 5 times, most recently from 2ad1341 to 26fb05b Compare August 8, 2022 16:28
@KonradStaniec KonradStaniec marked this pull request as ready for review August 8, 2022 16:32
Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Great start!

Comment on lines 35 to 37
rpc BestHeader(QueryBestHeaderRequest) returns (QueryBestHeaderResponse) {
option (google.api.http).get = "/babylon/btclightclient/v1/bestheader";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rpc BestHeader(QueryBestHeaderRequest) returns (QueryBestHeaderResponse) {
option (google.api.http).get = "/babylon/btclightclient/v1/bestheader";
}
rpc Tip(QueryTipRequest) returns (QueryTipResponse) {
option (google.api.http).get = "/babylon/btclightclient/v1/tip";
}

Nothing against "best header", just curious, why introduce new names for already existing concepts? Do you think "tip" is confusing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I find it a bit ambiguous to be honest it can mean tip of the blockchain, or maybe some tip to the miner. It can be interpreted in too many ways to my taste. I find best header having a bit more precise.

But I can change it to tip, to not introduce new terminolgy. We can debate naming of external apis when we will have some kind public testnet, and biger sample of people using those apis.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I saw that "best block" is a thing in Bitcoin, so it's fine with me.

Comment on lines +81 to +85
// This test serves as a waiting point for testnet to start, it is needed as
// docker compose is usually started in detached mode in CI, therefore tests
// are started even before all nodes are up.
// TODO: investigate starting testnet from golang test file.
func TestTestnetRuninng(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://stackoverflow.com/a/31204016 the execution order of tests should not be relied upon. It suggests calling this from init() or TestMain() instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh I didn't know that.

From what I see one can also provide flag go test -p 1 which will force sequential execution. In general I plan for those tests to be stateful (there will be one testnet running against which there weill be bunch of tx executed) and deterministic, so the execution order of tests will matter, also they do not run with other test due to build tag // +build integration so the won't execute by accident.

So I think I prefer to just add this flag to make target test-babylon-integration and have this smoke test as initial one to just check everything is working.

Copy link
Contributor

Choose a reason for hiding this comment

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

If -p 1 means not just sequential but in the order of appearance, great 👍

for i, c := range clients {
lc := lightclient.NewQueryClient(c)

res, err := lc.BestHeader(context.Background(), lightclient.NewQueryBestHeaderRequest())
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the BestHeader endpoint will always be the best choice to test what the genesis block is, if we assume that an actual local testnet is running. Ostensibly that could include BTC relayers that feed new headers to Babylon, otherwise the testnet will never produce a checkpoint. By the time you run this test, it might already have moved on to a new tip.

The Mainchain method should document what order it returns headers in, but looking at the code you can ask for results to be iterated in reverse in which case it wills tart from the base, and with a limit of 1 you should get the genesis header.

Copy link
Collaborator Author

@KonradStaniec KonradStaniec Aug 10, 2022

Choose a reason for hiding this comment

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

As mention in earlier comment, I intend for those tests to be stateful and deterministic, so as this will be the first test which will run, then at this point best header should be be genesis header. In later tests, after ingesting few header tip should move by expected amount of headers.

Copy link
Contributor

@aakoshh aakoshh Aug 10, 2022

Choose a reason for hiding this comment

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

Sorry that's not what I meant. I meant that according to the PR description you start with make localnet-start; ostensibly that could include a BTC node that starts creating blocks and some relayers, or maybe it could include just relayers who pull data from the BTC testnet, I don't know. A real local testnet would surely not stand still forever.

Admittedly it will probably not move on before this test executes, but just wanted to point out that there is a deterministic endpoint for you to use.

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

👏

@KonradStaniec KonradStaniec merged commit 74c4e9c into main Aug 11, 2022
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.

2 participants