1
+ 'use strict'
2
+
3
+ import { NightwatchBrowser } from 'nightwatch'
4
+ import init from '../helpers/init'
5
+
6
+ const templatesToCheck = [
7
+ {
8
+ value : "remixDefault" ,
9
+ displayName : "Basic" ,
10
+ checkSelectors : [
11
+ '*[data-id="treeViewLitreeViewItemcontracts/3_Ballot.sol"]' ,
12
+ '*[data-id="treeViewLitreeViewItemscripts/deploy_with_web3.ts"]'
13
+ ]
14
+ } ,
15
+ {
16
+ value : "blank" ,
17
+ displayName : "Blank" ,
18
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItem.prettierrc.json"]' ]
19
+ } ,
20
+ {
21
+ value : "simpleEip7702" ,
22
+ displayName : "Simple EIP-7702" ,
23
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/Example7702.sol"]' ]
24
+ } ,
25
+ {
26
+ value : "introToEIP7702" ,
27
+ displayName : "Intro to EIP-7702" ,
28
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/Spender.sol"]' ]
29
+ } ,
30
+ {
31
+ value : "accountAbstraction" ,
32
+ displayName : "Account Abstraction" ,
33
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemfunding.json"]' ]
34
+ } ,
35
+ {
36
+ value : "ozerc20" ,
37
+ displayName : "ERC20" ,
38
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]' ] ,
39
+ clickOk : true
40
+ } ,
41
+ {
42
+ value : "ozerc721" ,
43
+ displayName : "ERC721" ,
44
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]' ] ,
45
+ clickOk : true
46
+ } ,
47
+ {
48
+ value : "ozerc1155" ,
49
+ displayName : "ERC1155" ,
50
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]' ] ,
51
+ clickOk : true
52
+ } ,
53
+ {
54
+ value : "zeroxErc20" ,
55
+ displayName : "ERC20" ,
56
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/SampleERC20.sol"]' ]
57
+ } ,
58
+ {
59
+ value : "gnosisSafeMultisig" ,
60
+ displayName : "MultiSig" ,
61
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcontracts/MultisigWallet.sol"]' ]
62
+ } ,
63
+ {
64
+ value : "semaphore" ,
65
+ displayName : "Semaphore" ,
66
+ checkSelectors : [ '*[data-id="treeViewLitreeViewItemcircuits/semaphore.circom"]' ]
67
+ } ,
68
+ {
69
+ value : "hashchecker" ,
70
+ displayName : "Hash" ,
71
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemcircuits/calculate_hash.circom"]' ]
72
+ } ,
73
+ {
74
+ value : "rln" ,
75
+ displayName : "Rate" ,
76
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemcircuits/rln.circom"]' ]
77
+ } ,
78
+ {
79
+ value : "multNr" ,
80
+ displayName : "Multiplier" ,
81
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemsrc/main.nr"]' ]
82
+ } ,
83
+ {
84
+ value : "sindriScripts" ,
85
+ displayName : "Add Sindri ZK scripts" ,
86
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemscripts/sindri/run_compile.ts"]' ]
87
+ } ,
88
+ {
89
+ value : "uniswapV4Template" ,
90
+ displayName : "v4 Template" ,
91
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemfoundry.toml"]' ]
92
+ } ,
93
+ {
94
+ value : "contractCreate2Factory" ,
95
+ displayName : "Add Create2 Solidity factory" ,
96
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemcontracts/libs/create2-factory.sol"]' ]
97
+ } ,
98
+ {
99
+ value : "contractDeployerScripts" ,
100
+ displayName : "Add contract deployer scripts" ,
101
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemscripts/contract-deployer/basic-contract-deploy.ts"]' ]
102
+ } ,
103
+ {
104
+ value : "etherscanScripts" ,
105
+ displayName : "Add Etherscan scripts" ,
106
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItemscripts/etherscan/receiptGuidScript.ts"]' ]
107
+ } ,
108
+ {
109
+ value : "runJsTestAction" ,
110
+ displayName : "Mocha Chai Test Workflow" ,
111
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItem.github/workflows/run-js-test.yml"]' ]
112
+ } ,
113
+ {
114
+ value : "runSolidityUnittestingAction" ,
115
+ displayName : "Solidity Test Workflow" ,
116
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItem.github/workflows/run-solidity-unittesting.yml"]' ]
117
+ } ,
118
+ {
119
+ value : "runSlitherAction" ,
120
+ displayName : "Slither Workflo" ,
121
+ checkSelectors : [ '*[data-id="treeViewDivtreeViewItem.github/workflows/run-slither-action.yml"]' ]
122
+ }
123
+ ]
124
+
125
+ function setTemplateOptions ( browser : NightwatchBrowser , opts : { [ key : string ] : any } ) {
126
+ if ( opts . mintable ) browser . click ( '*[data-id="featureTypeMintable"]' )
127
+ if ( opts . burnable ) browser . click ( '*[data-id="featureTypeBurnable"]' )
128
+ if ( opts . pausable ) browser . click ( '*[data-id="featureTypePausable"]' )
129
+ if ( opts . upgradeability === 'transparent' ) browser . click ( '*[data-id="upgradeTypeTransparent"]' )
130
+ if ( opts . upgradeability === 'uups' ) browser . click ( '*[data-id="upgradeTypeUups"]' )
131
+ }
132
+
133
+ function openTemplatesExplorer ( browser : NightwatchBrowser ) {
134
+ browser
135
+ . click ( '*[data-id="workspacesMenuDropdown"]' )
136
+ . click ( '*[data-id="workspacecreate"]' )
137
+ . waitForElementPresent ( '*[data-id="create-remixDefault"]' )
138
+ }
139
+
140
+ function runTemplateChecks (
141
+ browser : NightwatchBrowser ,
142
+ start : number ,
143
+ end : number ,
144
+ mode : 'create' | 'add' = 'create' ,
145
+ ) {
146
+ templatesToCheck . slice ( start , end ) . forEach ( ( { value, displayName, checkSelectors, clickOk } ) => {
147
+ console . log ( `Checking template: ${ value } in ${ mode } mode` )
148
+ openTemplatesExplorer ( browser )
149
+
150
+ if ( mode === 'create' ) {
151
+ browser
152
+ . waitForElementVisible ( `[data-id="create-${ value } "]` , 5000 )
153
+ . click ( `[data-id="create-${ value } "]` )
154
+ } else {
155
+ browser
156
+ . waitForElementVisible ( `[data-id="create-blank"]` , 5000 )
157
+ . click ( `[data-id="create-blank"]` )
158
+ }
159
+
160
+ browser
161
+ . waitForElementVisible ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' , 2000 )
162
+ . click ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' )
163
+ . pause ( 1000 )
164
+
165
+ if ( mode === 'add' ) {
166
+ browser . element ( 'css selector' , `[data-id="add-${ value } "]` , result => {
167
+ console . log ( `Element add-${ value } status: ${ result . status } ` )
168
+ if ( result . status == 0 ) {
169
+ openTemplatesExplorer ( browser )
170
+ browser
171
+ . waitForElementVisible ( `[data-id="add-${ value } "]` , 5000 )
172
+ . click ( `[data-id="add-${ value } "]` )
173
+ if ( clickOk ) {
174
+ browser
175
+ . waitForElementVisible ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' , 2000 )
176
+ . click ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' )
177
+ }
178
+
179
+ checkSelectors . forEach ( selector => {
180
+ console . log ( `Checking selector: ${ selector } ` )
181
+ browser . waitForElementVisible ( selector , 30000 )
182
+ } )
183
+ }
184
+ } )
185
+ } else {
186
+ browser
187
+ . useXpath ( )
188
+ . waitForElementVisible ( `//div[contains(@data-id, "dropdown-content") and contains(., "${ displayName } ")]` , 5000 )
189
+ . useCss ( )
190
+
191
+ checkSelectors . forEach ( selector => {
192
+ console . log ( `Checking selector: ${ selector } ` )
193
+ browser . waitForElementVisible ( selector , 30000 )
194
+ } )
195
+ }
196
+ } )
197
+ }
198
+
199
+ function testTemplateOptions ( browser : NightwatchBrowser , mode : 'create' | 'add' ) {
200
+ openTemplatesExplorer ( browser )
201
+
202
+ const selector = mode === 'create' ? '[data-id="create-ozerc20"]' : '[data-id="add-ozerc20"]'
203
+
204
+ browser
205
+ . waitForElementVisible ( selector , 5000 )
206
+ . click ( selector )
207
+
208
+ browser
209
+ . waitForElementVisible ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' , 2000 )
210
+
211
+ // Simulate user selecting options
212
+ setTemplateOptions ( browser , { mintable : true , burnable : true , upgradeability : 'uups' } )
213
+
214
+ // Confirm selection
215
+ browser
216
+ . click ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' )
217
+
218
+ // Verify expected file was created
219
+ browser
220
+ . waitForElementVisible ( '*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]' , 10000 )
221
+ . click ( '*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]' )
222
+ . pause ( 1000 )
223
+ . getEditorValue ( editorValue => {
224
+ const expected = 'contract MyToken is Initializable, ERC20Upgradeable, ERC20BurnableUpgradeable, OwnableUpgradeable, ERC20PermitUpgradeable, UUPSUpgradeable'
225
+ if ( editorValue . includes ( expected ) ) {
226
+ console . log ( `✅ Template with options applied successfully (${ mode } )` )
227
+ browser . assert . ok ( true , `Template with options applied successfully (${ mode } )` )
228
+ } else {
229
+ browser . assert . fail ( `❌ Template with options was not applied correctly (${ mode } )` )
230
+ }
231
+ } )
232
+ }
233
+
234
+ module . exports = {
235
+ '@disabled' : true ,
236
+ before : function ( browser : NightwatchBrowser , done : VoidFunction ) {
237
+ init ( browser , done )
238
+ } ,
239
+ openFilePanel : function ( browser : NightwatchBrowser ) {
240
+ browser . clickLaunchIcon ( 'filePanel' )
241
+ } ,
242
+ 'Loop through templates and click create #group1' : function ( browser ) {
243
+ runTemplateChecks ( browser , 0 , templatesToCheck . length , 'create' )
244
+ } ,
245
+ 'Loop through templates and click add buttons #group1' : function ( browser ) {
246
+ runTemplateChecks ( browser , 0 , templatesToCheck . length , 'add' )
247
+ } ,
248
+ 'Test template options with create #group2' : function ( browser : NightwatchBrowser ) {
249
+ testTemplateOptions ( browser , 'create' )
250
+ } ,
251
+
252
+ 'Test template options with add #group2' : function ( browser : NightwatchBrowser ) {
253
+ openTemplatesExplorer ( browser )
254
+ browser
255
+ . waitForElementVisible ( `[data-id="create-remixDefault"]` , 5000 )
256
+ . click ( `[data-id="create-remixDefault"]` )
257
+ . waitForElementVisible ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' , 2000 )
258
+ . click ( '*[data-id="TemplatesSelection-modal-footer-ok-react"]' )
259
+ . pause ( 1000 )
260
+
261
+ testTemplateOptions ( browser , 'add' )
262
+ }
263
+ }
0 commit comments