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

test: refactor test data generation #51

Merged
merged 9 commits into from
Sep 3, 2024
Merged

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Aug 30, 2024

This PR refactors the tests, including

This is the prerequisite for testing the full validation of finality providers / BTC delegations.

@SebastianElvis SebastianElvis changed the title refactor test data test: refactor test data generation Sep 2, 2024
@SebastianElvis SebastianElvis marked this pull request as ready for review September 2, 2024 05:14
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

LGTM. Just some issues with data files name formatting, and some outdated module refs that would be nice to fix before merging.

.gitmodules Outdated Show resolved Hide resolved
packages/test-utils/testdata/btc_delegation_1_{1,3}.dat Outdated Show resolved Hide resolved
packages/proto/buf.work.yaml Show resolved Hide resolved
Comment on lines -52 to -53
r := rand.New(rand.NewSource(time.Now().UnixNano()))

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, if I understand correctly, the same random source needs to be used for all of the data generation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This seems to be a good practice. The issue I was facing is as follows. I was using two fresh r := rand.New(rand.NewSource(time.Now().UnixNano())) to generate secret keys for covenant members and finality providers in test data. Since the code was fast, the two r end up using the same timestamp and being the same value. Then the 1st covenant secret key is same as the 1st finality provider secret key. As Babylon does not accept duplicate keys in the staking script (i.e., any duplication among FP keys, covenant keys and staker key), the tests panicked. Using the same rand source solves this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense overall, but I find difficult to believe that both r have the same seed, as it's a timestamp in nanoseconds resolution. Are these routines being called in parallel or so?

go.work.sum Outdated Show resolved Hide resolved
datagen/utils/btcstaking.go Outdated Show resolved Hide resolved
datagen/utils/btcstaking.go Outdated Show resolved Hide resolved
contracts/btc-staking/src/queries.rs Show resolved Hide resolved
@SebastianElvis SebastianElvis merged commit a36f194 into main Sep 3, 2024
1 check passed
@SebastianElvis SebastianElvis deleted the refactor-test0-data branch September 3, 2024 00:23
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