@@ -257,19 +257,25 @@ describe('Testing the http API', () => {
257
257
258
258
describe ( 'Basic Proposer tests' , ( ) => {
259
259
after ( async ( ) => {
260
- // After the proposer tests, re-register proposers
261
- const myAddress = ( await getAccounts ( ) ) [ 0 ] ;
262
- const res = await chai
263
- . request ( optimistUrl )
264
- . post ( '/proposer/register' )
265
- . send ( { address : myAddress } ) ;
266
- const { txDataToSign } = res . body ;
267
- expect ( txDataToSign ) . to . be . a ( 'string' ) ;
268
- const bond = 10 ;
269
- const count = logCounts . registerProposer ;
270
- await submitTransaction ( txDataToSign , privateKey , proposersAddress , gas , bond ) ;
271
- await waitForTxExecution ( count , 'registerProposer' ) ;
272
- stateBalance += bond ;
260
+ // After the proposer tests, re-register proposers, if needed
261
+ try {
262
+ const myAddress = ( await getAccounts ( ) ) [ 0 ] ;
263
+ const res = await chai
264
+ . request ( optimistUrl )
265
+ . post ( '/proposer/register' )
266
+ . send ( { address : myAddress } ) ;
267
+ const { txDataToSign } = res . body ;
268
+ expect ( txDataToSign ) . to . be . a ( 'string' ) ;
269
+ const bond = 10 ;
270
+ const count = logCounts . registerProposer ;
271
+ await submitTransaction ( txDataToSign , privateKey , proposersAddress , gas , bond ) ;
272
+ await waitForTxExecution ( count , 'registerProposer' ) ;
273
+ stateBalance += bond ;
274
+ } catch ( err ) {
275
+ // an EVM revert almost certainly indicates that the proposer is already registered. That's
276
+ // fine, it's ok to continue
277
+ if ( ! err . message . includes ( 'Transaction has been reverted by the EVM' ) ) throw new Error ( err ) ;
278
+ }
273
279
} ) ;
274
280
275
281
it ( 'should register a proposer' , async ( ) => {
@@ -306,6 +312,26 @@ describe('Testing the http API', () => {
306
312
} ) ;
307
313
} ) ;
308
314
315
+ it ( 'should fail to register a proposer twice' , async ( ) => {
316
+ const myAddress = ( await getAccounts ( ) ) [ 0 ] ;
317
+ const res = await chai
318
+ . request ( optimistUrl )
319
+ . post ( '/proposer/register' )
320
+ . send ( { address : myAddress } ) ;
321
+ const { txDataToSign } = res . body ;
322
+ expect ( txDataToSign ) . to . be . a ( 'string' ) ;
323
+ // we have to pay 10 ETH to be registered
324
+ const bond = 10 ;
325
+ // now we need to sign the transaction and send it to the blockchain
326
+ console . log ( 'submitting tx' ) ;
327
+ try {
328
+ await submitTransaction ( txDataToSign , privateKey , proposersAddress , gas , bond ) ;
329
+ expect . fail ( 'Submitting the same proposer registration should have caused an EVM revert' ) ;
330
+ } catch ( err ) {
331
+ expect ( err . message ) . to . include ( 'Transaction has been reverted by the EVM' ) ;
332
+ }
333
+ } ) ;
334
+
309
335
it ( 'should de-register a proposer' , async ( ) => {
310
336
const myAddress = ( await getAccounts ( ) ) [ 0 ] ;
311
337
const res = await chai . request ( optimistUrl ) . post ( '/proposer/de-register' ) ;
0 commit comments