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

feat!: add launchTestNode utility #1356

Merged
merged 181 commits into from
Jun 6, 2024
Merged

feat!: add launchTestNode utility #1356

merged 181 commits into from
Jun 6, 2024

Conversation

nedsalk
Copy link
Contributor

@nedsalk nedsalk commented Oct 17, 2023

This PR introduces the launchTestNode utility. The idea is for it to be the way to setup tests for interacting with sway programs, both internally and for our users. It allows for full test isolation by creating a node for each test and disposing of it at the end of the test. Besides the main benefit of test isolation (which is ideal for defending against flaky tests), this tool would also speed up our test suite.
It makes use of TS 5.2 explicit resource management to automatically kill the node it launches and provides a way to tweak wallet states in the genesis block, deploy contracts, as well as lower level settings like the provider options and node options.

This builds on the great work done in #1204.

Usage example:

using launched = await launchTestNode({
  walletConfig: { count: 2 },
  deployContracts: [ 
  {
    deployer: TestContract__factory,
    bytecode: contractBytecode
  }
 ],
});

const {
  contracts: [contract],
  wallets: [wallet1, wallet2],
} = launched;

This could be nicely tied into #1330 where a sample test file that's testing the contract can be added, demonstrating the preferred way of testing sway programs. We can add e.g. vitest as the default framework in the scaffold just so that the developer can run the tests immediately.

Breaking changes

  • The account package is not exporting the sleep utility anymore and it has now been moved into the utils package.

closes #1254

@github-actions

This comment was marked as outdated.

@nedsalk nedsalk marked this pull request as ready for review October 23, 2023 18:21
camsjams

This comment was marked as outdated.

@nedsalk nedsalk marked this pull request as draft October 24, 2023 06:11
@nedsalk nedsalk changed the base branch from master to ns/chore/update-formatting-packages October 24, 2023 07:16
@nedsalk

This comment was marked as outdated.

Dhaiwat10

This comment was marked as outdated.

Base automatically changed from ns/chore/update-formatting-packages to master October 30, 2023 21:08
@nedsalk nedsalk marked this pull request as draft October 31, 2023 14:52
@nedsalk

This comment was marked as outdated.

@arboleya

This comment was marked as outdated.

@nedsalk

This comment was marked as outdated.

@nedsalk

This comment was marked as outdated.

@nedsalk nedsalk marked this pull request as ready for review November 14, 2023 15:18
maschad
maschad previously approved these changes Jun 6, 2024
Torres-ssf
Torres-ssf previously approved these changes Jun 6, 2024
Dhaiwat10
Dhaiwat10 previously approved these changes Jun 6, 2024
@nedsalk nedsalk enabled auto-merge (squash) June 6, 2024 16:05
Copy link
Contributor

@petertonysmith94 petertonysmith94 left a comment

Choose a reason for hiding this comment

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

🍏

Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

github-actions bot commented Jun 6, 2024

Coverage Report:

Lines Branches Functions Statements
45.41%(-0.75%) 38.46%(-1.15%) 42.19%(-1.08%) 45.18%(-0.8%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 ✨ packages/account/src/test-utils/asset-id.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/account/src/test-utils/setup-test-provider-and-wallets.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/account/src/test-utils/test-message.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/account/src/test-utils/wallet-config.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/contract/src/test-utils/launch-test-node.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/utils/src/test-utils/wait-until-unreachable.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/utils/src/utils/sleep.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add setupTestProvider test utility
8 participants