@@ -3,12 +3,16 @@ import { SavebleDocument, Transaction } from '../../metadata/metadataStore';
3
3
import { TStrategyOptions } from '../../signing/strategy' ;
4
4
import { TDeploy } from '../../metadata/schema' ;
5
5
import type { PublicClient , TransactionReceipt } from 'viem' ;
6
- import { mockDeployDocument , mockTransaction } from './mock' ;
6
+ import { mockDeployDocument , mockTransaction , mockNextSelectedStrategy } from './mock' ;
7
+ import { mockForgeScriptOutput , MockStrategy } from './mockStrategy' ;
7
8
8
9
const { runTest} = await import ( '../../signing/strategies/test' ) ;
9
10
const prompts = await import ( '../../commands/prompts' )
10
11
const { executeEOAPhase} = await import ( '../../deploy/handlers/eoa' ) ;
11
12
const { createPublicClient, TransactionReceiptNotFoundError } = await import ( 'viem' ) ;
13
+ const EOASigningStrategyMod = await import ( '../../signing/strategies/eoa/privateKey' ) ;
14
+
15
+ import type EOASigningStrategy from '../../signing/strategies/eoa/privateKey'
12
16
13
17
describe ( 'executeEOAPhase' , ( ) => {
14
18
let deploy : SavebleDocument < TDeploy > ;
@@ -57,14 +61,14 @@ describe('executeEOAPhase', () => {
57
61
58
62
it ( 'should run tests and advance if all goes well (non-interactive = false)' , async ( ) => {
59
63
( runTest as jest . Mock < typeof runTest > ) . mockResolvedValue ( { forge : undefined , code : 0 , stdout : '' , stderr : '' } ) ; // test pass
60
- // We'll let wouldYouLikeToContinue = true (since it's mocked by default)
61
-
62
- // mock strategy out.
64
+
63
65
const txn = mockTransaction ( {
64
66
"environment/testEnv/manifest.json" : { id : "testEnv" }
65
67
} ) ;
66
- ( prompts . pickStrategy as jest . Mock < typeof prompts . pickStrategy > ) . mockResolvedValue ( 'ledger' ) ;
68
+ const mockStrategy = new MockStrategy ( deploy , txn , options ) ;
69
+ mockNextSelectedStrategy ( mockStrategy ) ;
67
70
( prompts . wouldYouLikeToContinue as jest . Mock < typeof prompts . wouldYouLikeToContinue > ) . mockResolvedValue ( true ) ;
71
+
68
72
await executeEOAPhase ( deploy , txn , options ) ;
69
73
70
74
// It should have invoked runTest
@@ -81,13 +85,14 @@ describe('executeEOAPhase', () => {
81
85
} ) ;
82
86
83
87
it ( 'should throw an error if tests fail' , async ( ) => {
84
- ( runTest as jest . Mock < typeof runTest > ) . mockResolvedValue ( { code : 1 , stdout : '' , stderr : '' , forge : undefined } ) ; // test fail
88
+ ( runTest as jest . Mock < typeof runTest > ) . mockResolvedValue ( { code : 1 , stdout : '' , stderr : '' , forge : undefined } ) ; // test failure
85
89
86
- await expect ( executeEOAPhase ( deploy , metatxn , options ) ) . rejects . toThrowError ( ' One or more tests failed.' ) ;
90
+ await expect ( executeEOAPhase ( deploy , metatxn , options ) ) . rejects . toThrowError ( `The deploy halted: One or more tests failed.` ) ;
87
91
88
92
// Should have tried to run tests
89
93
expect ( runTest ) . toHaveBeenCalled ( ) ;
90
- // The function should throw before saving or committing
94
+
95
+ // Doesn't save
91
96
expect ( deploy . save ) . not . toHaveBeenCalled ( ) ;
92
97
expect ( metatxn . commit ) . not . toHaveBeenCalled ( ) ;
93
98
} ) ;
@@ -109,6 +114,41 @@ describe('executeEOAPhase', () => {
109
114
expect ( metatxn . commit ) . not . toHaveBeenCalled ( ) ;
110
115
} ) ;
111
116
117
+ it ( 'should complete successfully' , async ( ) => {
118
+ const metatxn = mockTransaction ( {
119
+ "environment/testEnv/manifest.json" : { id : "testEnv" }
120
+ } ) ;
121
+
122
+ ( runTest as jest . Mock < typeof runTest > ) . mockResolvedValue ( { code : 0 , stdout : '' , stderr : '' , forge : undefined } ) ; // test success
123
+ ( prompts . etherscanApiKey as jest . Mock < typeof prompts . etherscanApiKey > ) . mockResolvedValue ( '123' ) ;
124
+ const options = {
125
+ nonInteractive : false ,
126
+ defaultArgs : { rpcUrl : 'https://google.com' , overrideEoaPk : `0x04ba7e1737815037a348ec201b6433868f8c297d007b5ca605387fbb21f80516` }
127
+ } as const ;
128
+
129
+ const deploy = mockDeployDocument ( 'eoa_start' , '1-eoa.s.sol' ) as SavebleDocument < TDeploy > ;
130
+ const strat = new EOASigningStrategyMod . default ( deploy , metatxn , options ) ;
131
+
132
+ jest . spyOn ( strat , 'runForgeScript' ) ;
133
+ ( strat . runForgeScript as jest . Mock < typeof strat [ 'runForgeScript' ] > ) . mockImplementation ( async function ( this : EOASigningStrategy ) {
134
+ await this . forgeArgs ( ) ; // mock runForgeScript as accessing the args.
135
+ // TODO: this mocking could mock something within runForgeScript instead to be more accurate.
136
+ return mockForgeScriptOutput ;
137
+ } ) ;
138
+
139
+ mockNextSelectedStrategy ( strat ) ;
140
+
141
+ await expect ( executeEOAPhase ( deploy , metatxn , options ) ) . resolves . toBeUndefined ( )
142
+
143
+ expect ( deploy . save ) . toHaveBeenCalled ( ) ;
144
+ expect ( metatxn . commit ) . toHaveBeenCalled ( ) ;
145
+
146
+ // should prompt for etherscan api key.
147
+ expect ( strat . runForgeScript ) . toHaveBeenCalled ( ) ;
148
+ expect ( prompts . etherscanApiKey ) . toHaveBeenCalled ( ) ;
149
+ } ) ;
150
+ } )
151
+
112
152
describe ( 'phase: "eoa_wait_confirm"' , ( ) => {
113
153
beforeEach ( ( ) => {
114
154
deploy . _ . phase = 'eoa_wait_confirm' ;
@@ -189,5 +229,4 @@ describe('executeEOAPhase', () => {
189
229
) ;
190
230
} ) ;
191
231
} ) ;
192
- } )
193
232
} ) ;
0 commit comments