|
19 | 19 | import static org.mockito.Mockito.verify;
|
20 | 20 |
|
21 | 21 | import org.hyperledger.besu.cli.CommandTestAbstract;
|
22 |
| -import org.hyperledger.besu.datatypes.Address; |
23 | 22 | import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
|
24 | 23 | import org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration;
|
25 | 24 | import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
|
26 |
| -import org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration; |
27 | 25 | import org.hyperledger.besu.plugin.data.EnodeURL;
|
28 | 26 |
|
29 | 27 | import java.io.IOException;
|
@@ -83,218 +81,6 @@ public void errorIsRaisedIfStaticNodesAreNotAllowed(final @TempDir Path testFold
|
83 | 81 | .contains(staticNodeURI.toString(), "not in nodes-allowlist");
|
84 | 82 | }
|
85 | 83 |
|
86 |
| - @Test |
87 |
| - public void nodePermissionsSmartContractWithoutOptionMustError() { |
88 |
| - parseCommand("--permissions-nodes-contract-address"); |
89 |
| - |
90 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
91 |
| - |
92 |
| - assertThat(commandErrorOutput.toString(UTF_8)) |
93 |
| - .startsWith("Missing required parameter for option '--permissions-nodes-contract-address'"); |
94 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
95 |
| - } |
96 |
| - |
97 |
| - @Test |
98 |
| - public void nodePermissionsEnabledWithoutContractAddressMustError() { |
99 |
| - parseCommand("--permissions-nodes-contract-enabled"); |
100 |
| - |
101 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
102 |
| - |
103 |
| - assertThat(commandErrorOutput.toString(UTF_8)) |
104 |
| - .contains("No node permissioning contract address specified"); |
105 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
106 |
| - } |
107 |
| - |
108 |
| - @Test |
109 |
| - public void nodePermissionsEnabledWithInvalidContractAddressMustError() { |
110 |
| - parseCommand( |
111 |
| - "--permissions-nodes-contract-enabled", |
112 |
| - "--permissions-nodes-contract-address", |
113 |
| - "invalid-smart-contract-address"); |
114 |
| - |
115 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
116 |
| - |
117 |
| - assertThat(commandErrorOutput.toString(UTF_8)).contains("Invalid value"); |
118 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
119 |
| - } |
120 |
| - |
121 |
| - @Test |
122 |
| - public void nodePermissionsEnabledWithTooShortContractAddressMustError() { |
123 |
| - parseCommand( |
124 |
| - "--permissions-nodes-contract-enabled", "--permissions-nodes-contract-address", "0x1234"); |
125 |
| - |
126 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
127 |
| - |
128 |
| - assertThat(commandErrorOutput.toString(UTF_8)).contains("Invalid value"); |
129 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
130 |
| - } |
131 |
| - |
132 |
| - @Test |
133 |
| - public void nodePermissionsSmartContractMustUseOption() { |
134 |
| - |
135 |
| - final String smartContractAddress = "0x0000000000000000000000000000000000001234"; |
136 |
| - |
137 |
| - parseCommand( |
138 |
| - "--permissions-nodes-contract-enabled", |
139 |
| - "--permissions-nodes-contract-address", |
140 |
| - smartContractAddress); |
141 |
| - final SmartContractPermissioningConfiguration smartContractPermissioningConfiguration = |
142 |
| - new SmartContractPermissioningConfiguration(); |
143 |
| - smartContractPermissioningConfiguration.setNodeSmartContractAddress( |
144 |
| - Address.fromHexString(smartContractAddress)); |
145 |
| - smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(true); |
146 |
| - |
147 |
| - verify(mockRunnerBuilder) |
148 |
| - .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); |
149 |
| - verify(mockRunnerBuilder).build(); |
150 |
| - |
151 |
| - final PermissioningConfiguration config = |
152 |
| - permissioningConfigurationArgumentCaptor.getValue().get(); |
153 |
| - assertThat(config.getSmartContractConfig().get()) |
154 |
| - .usingRecursiveComparison() |
155 |
| - .isEqualTo(smartContractPermissioningConfiguration); |
156 |
| - |
157 |
| - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); |
158 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
159 |
| - } |
160 |
| - |
161 |
| - @Test |
162 |
| - public void nodePermissionsContractVersionDefaultValue() { |
163 |
| - final SmartContractPermissioningConfiguration expectedConfig = |
164 |
| - new SmartContractPermissioningConfiguration(); |
165 |
| - expectedConfig.setNodeSmartContractAddress( |
166 |
| - Address.fromHexString("0x0000000000000000000000000000000000001234")); |
167 |
| - expectedConfig.setSmartContractNodeAllowlistEnabled(true); |
168 |
| - expectedConfig.setNodeSmartContractInterfaceVersion(1); |
169 |
| - |
170 |
| - parseCommand( |
171 |
| - "--permissions-nodes-contract-enabled", |
172 |
| - "--permissions-nodes-contract-address", |
173 |
| - "0x0000000000000000000000000000000000001234"); |
174 |
| - |
175 |
| - verify(mockRunnerBuilder) |
176 |
| - .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); |
177 |
| - verify(mockRunnerBuilder).build(); |
178 |
| - |
179 |
| - final PermissioningConfiguration config = |
180 |
| - permissioningConfigurationArgumentCaptor.getValue().get(); |
181 |
| - assertThat(config.getSmartContractConfig().get()) |
182 |
| - .usingRecursiveComparison() |
183 |
| - .isEqualTo(expectedConfig); |
184 |
| - |
185 |
| - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); |
186 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
187 |
| - } |
188 |
| - |
189 |
| - @Test |
190 |
| - public void nodePermissionsContractVersionSetsValue() { |
191 |
| - final SmartContractPermissioningConfiguration expectedConfig = |
192 |
| - new SmartContractPermissioningConfiguration(); |
193 |
| - expectedConfig.setNodeSmartContractAddress( |
194 |
| - Address.fromHexString("0x0000000000000000000000000000000000001234")); |
195 |
| - expectedConfig.setSmartContractNodeAllowlistEnabled(true); |
196 |
| - expectedConfig.setNodeSmartContractInterfaceVersion(2); |
197 |
| - |
198 |
| - parseCommand( |
199 |
| - "--permissions-nodes-contract-enabled", |
200 |
| - "--permissions-nodes-contract-address", |
201 |
| - "0x0000000000000000000000000000000000001234", |
202 |
| - "--permissions-nodes-contract-version", |
203 |
| - "2"); |
204 |
| - |
205 |
| - verify(mockRunnerBuilder) |
206 |
| - .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); |
207 |
| - verify(mockRunnerBuilder).build(); |
208 |
| - |
209 |
| - final PermissioningConfiguration config = |
210 |
| - permissioningConfigurationArgumentCaptor.getValue().get(); |
211 |
| - assertThat(config.getSmartContractConfig().get()) |
212 |
| - .usingRecursiveComparison() |
213 |
| - .isEqualTo(expectedConfig); |
214 |
| - |
215 |
| - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); |
216 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
217 |
| - } |
218 |
| - |
219 |
| - @Test |
220 |
| - public void accountPermissionsSmartContractWithoutOptionMustError() { |
221 |
| - parseCommand("--permissions-accounts-contract-address"); |
222 |
| - |
223 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
224 |
| - |
225 |
| - assertThat(commandErrorOutput.toString(UTF_8)) |
226 |
| - .startsWith( |
227 |
| - "Missing required parameter for option '--permissions-accounts-contract-address'"); |
228 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
229 |
| - } |
230 |
| - |
231 |
| - @Test |
232 |
| - public void accountPermissionsEnabledWithoutContractAddressMustError() { |
233 |
| - parseCommand("--permissions-accounts-contract-enabled"); |
234 |
| - |
235 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
236 |
| - |
237 |
| - assertThat(commandErrorOutput.toString(UTF_8)) |
238 |
| - .contains("No account permissioning contract address specified"); |
239 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
240 |
| - } |
241 |
| - |
242 |
| - @Test |
243 |
| - public void accountPermissionsEnabledWithInvalidContractAddressMustError() { |
244 |
| - parseCommand( |
245 |
| - "--permissions-accounts-contract-enabled", |
246 |
| - "--permissions-accounts-contract-address", |
247 |
| - "invalid-smart-contract-address"); |
248 |
| - |
249 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
250 |
| - |
251 |
| - assertThat(commandErrorOutput.toString(UTF_8)).contains("Invalid value"); |
252 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
253 |
| - } |
254 |
| - |
255 |
| - @Test |
256 |
| - public void accountPermissionsEnabledWithTooShortContractAddressMustError() { |
257 |
| - parseCommand( |
258 |
| - "--permissions-accounts-contract-enabled", |
259 |
| - "--permissions-accounts-contract-address", |
260 |
| - "0x1234"); |
261 |
| - |
262 |
| - Mockito.verifyNoInteractions(mockRunnerBuilder); |
263 |
| - |
264 |
| - assertThat(commandErrorOutput.toString(UTF_8)).contains("Invalid value"); |
265 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
266 |
| - } |
267 |
| - |
268 |
| - @Test |
269 |
| - public void accountPermissionsSmartContractMustUseOption() { |
270 |
| - final String smartContractAddress = "0x0000000000000000000000000000000000001234"; |
271 |
| - |
272 |
| - parseCommand( |
273 |
| - "--permissions-accounts-contract-enabled", |
274 |
| - "--permissions-accounts-contract-address", |
275 |
| - smartContractAddress); |
276 |
| - final SmartContractPermissioningConfiguration smartContractPermissioningConfiguration = |
277 |
| - new SmartContractPermissioningConfiguration(); |
278 |
| - smartContractPermissioningConfiguration.setAccountSmartContractAddress( |
279 |
| - Address.fromHexString(smartContractAddress)); |
280 |
| - smartContractPermissioningConfiguration.setSmartContractAccountAllowlistEnabled(true); |
281 |
| - |
282 |
| - verify(mockRunnerBuilder) |
283 |
| - .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); |
284 |
| - final PermissioningConfiguration permissioningConfiguration = |
285 |
| - permissioningConfigurationArgumentCaptor.getValue().get(); |
286 |
| - assertThat(permissioningConfiguration.getSmartContractConfig()).isPresent(); |
287 |
| - |
288 |
| - final SmartContractPermissioningConfiguration effectiveSmartContractConfig = |
289 |
| - permissioningConfiguration.getSmartContractConfig().get(); |
290 |
| - assertThat(effectiveSmartContractConfig.isSmartContractAccountAllowlistEnabled()).isTrue(); |
291 |
| - assertThat(effectiveSmartContractConfig.getAccountSmartContractAddress()) |
292 |
| - .isEqualTo(Address.fromHexString(smartContractAddress)); |
293 |
| - |
294 |
| - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); |
295 |
| - assertThat(commandOutput.toString(UTF_8)).isEmpty(); |
296 |
| - } |
297 |
| - |
298 | 84 | @Test
|
299 | 85 | public void nodePermissioningTomlPathWithoutOptionMustDisplayUsage() {
|
300 | 86 | parseCommand("--permissions-nodes-config-file");
|
|
0 commit comments