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

Remove use of rand from generated addresses, nonces, salts, and issuer pks #1135

Merged
merged 9 commits into from
Nov 8, 2023

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Nov 7, 2023

What

Remove use of rand from generated addresses, nonces, salts, and issuer pks, replace with sequential values instead.

Why

The SDK generates random addresses, nonces, salts, and issuer pks. This randomness makes it near impossible to write any test that produces predictable and consistent total system state.

The SDK doesn't need to be using random values for these things. It just needs to produce values that don't matter and that are unique.

Predictable and consistent values make it easier to write tests that can be used over time to assess the consistency of a contract. This is an important attribute of tests so that folks can evaluate if their contract is consistent even with dependency upgrades, SDK upgrades, and protocol upgrades.

This change also introduces the concept of a Snapshot, which is a superset of the existing LedgerSnapshot. The LedgerSnapshot contains everything needed to load in a ledger from a network or other source. Snapshot contains everything needed to rehydrate the state of an SDK testutils backed Env.

Related discussion in Discord: https://discord.com/channels/897514728459468821/1171226885171191949

For #1082

@leighmcculloch leighmcculloch requested review from graydon and removed request for graydon November 7, 2023 05:16
@leighmcculloch leighmcculloch marked this pull request as ready for review November 7, 2023 22:08
@leighmcculloch leighmcculloch requested review from dmkozh and graydon and removed request for graydon November 7, 2023 22:21
@leighmcculloch leighmcculloch added this pull request to the merge queue Nov 8, 2023
Merged via the queue into main with commit 3af7527 Nov 8, 2023
14 checks passed
@leighmcculloch leighmcculloch deleted the lessrnd branch November 8, 2023 02:59
github-merge-queue bot pushed a commit that referenced this pull request Nov 11, 2023
### What
Autosave a test snapshot file on every test exit.

### Why
To encourage the over-time consistency testing of contracts. To provide
a mechanism where any developer who commits the generated files can see
changes in observable behavior that arises unexpectedly over time.

Close #1082

### Merging
To be merged to `main` after:

- [x] Adding events to the `Snapshot`.
- [ ] ~Adding budget to the `Snapshot`. _(Maybe, seems less clear if
should be included.)_~
- [x] Support multiple Envs in a single test writing multiple files.
- [x] #1142
- [x] stellar/rs-soroban-env#1182
- [x] #1135
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.

Add test utilities that make it easier to test contract consistency over time
2 participants