Repository navigation
fix(deployments): verify the recorded stack before a broadcast deposit #61
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { fileURLToPath } from 'node:url' | ||
| import { afterEach, beforeEach, expect, test, vi } from 'vitest' | ||
|
|
||
| import { loadEarnProfileBundle } from './bundle.js' | ||
|
|
||
| const { depositEarnProfile, verifyEarnProfile } = vi.hoisted(() => ({ | ||
| depositEarnProfile: vi.fn(), | ||
| verifyEarnProfile: vi.fn(), | ||
| })) | ||
| vi.mock('./deposit.js', async (actual) => ({ | ||
| ...(await actual<typeof import('./deposit.js')>()), | ||
| depositEarnProfile, | ||
| })) | ||
| vi.mock('./deploy.js', async (actual) => ({ | ||
| ...(await actual<typeof import('./deploy.js')>()), | ||
| verifyEarnProfile, | ||
| })) | ||
|
|
||
| const { main } = await import('./cli.js') | ||
|
|
||
| const profilePath = fileURLToPath( | ||
| new URL('../../profiles/veda-moderato/profile.json', import.meta.url), | ||
| ) | ||
| const deposit = [ | ||
| 'deposit', | ||
| profilePath, | ||
| '--assets', | ||
| '1', | ||
| '--rpc-url', | ||
| 'http://127.0.0.1:1', | ||
| '--json', | ||
| ] | ||
| const output = { log: vi.fn(), warn: vi.fn() } | ||
|
|
||
| beforeEach(() => { | ||
| vi.stubEnv('DEPLOYER_PRIVATE_KEY', '') | ||
| depositEarnProfile.mockReset().mockResolvedValue({ state: 'preview' }) | ||
| verifyEarnProfile.mockReset() | ||
| }) | ||
| afterEach(() => vi.unstubAllEnvs()) | ||
|
|
||
| test('broadcast refuses to fund a record that fails verification', async () => { | ||
| verifyEarnProfile.mockRejectedValue( | ||
| new Error('Runtime bytecode hash changed for addresses.earnVault'), | ||
| ) | ||
| await expect(main([...deposit, '--broadcast'], output, '/')).rejects.toThrow( | ||
| 'Runtime bytecode hash changed', | ||
| ) | ||
| expect(verifyEarnProfile).toHaveBeenCalledOnce() | ||
| expect(depositEarnProfile).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('broadcast funds only the verified record', async () => { | ||
| const verified = { addresses: {} } | ||
| verifyEarnProfile.mockResolvedValue({ record: verified }) | ||
| await main([...deposit, '--broadcast', '--skip-zone'], output, '/') | ||
| expect(verifyEarnProfile).toHaveBeenCalledWith( | ||
| expect.objectContaining({ profilePath, rpcUrl: 'http://127.0.0.1:1', skipLive: ['zone'] }), | ||
| ) | ||
| expect(depositEarnProfile).toHaveBeenCalledWith( | ||
| expect.objectContaining({ broadcast: true, record: verified }), | ||
| ) | ||
| }) | ||
|
|
||
| test('a preview rejects live-check skips it would ignore', async () => { | ||
| await expect(main([...deposit, '--skip-zone'], output, '/')).rejects.toThrow( | ||
| '--skip-zone is supported only by verify or deposit --broadcast', | ||
| ) | ||
| expect(depositEarnProfile).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('a preview quotes the recorded stack without verification', async () => { | ||
| await main(deposit, output, '/') | ||
| expect(verifyEarnProfile).not.toHaveBeenCalled() | ||
| expect(depositEarnProfile).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| broadcast: false, | ||
| record: loadEarnProfileBundle(profilePath).record, | ||
| }), | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.