|
8 | 8 | import static org.mockito.Mockito.doThrow; |
9 | 9 | import static org.mockito.Mockito.mock; |
10 | 10 | import static org.mockito.Mockito.spy; |
| 11 | +import static org.mockito.Mockito.times; |
11 | 12 | import static org.mockito.Mockito.verify; |
12 | 13 | import static org.mockito.Mockito.when; |
13 | 14 | import static org.tron.common.utils.Commons.adjustAssetBalanceV2; |
14 | 15 | import static org.tron.common.utils.Commons.adjustTotalShieldedPoolValue; |
15 | 16 | import static org.tron.common.utils.Commons.getExchangeStoreFinal; |
16 | 17 | import static org.tron.common.utils.StringUtil.encode58Check; |
17 | | -import static org.tron.core.exception.BadBlockException.TypeEnum.CALC_MERKLE_ROOT_FAILED; |
18 | 18 | import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS; |
19 | 19 |
|
20 | 20 | import com.beust.jcommander.internal.Lists; |
|
106 | 106 | import org.tron.core.exception.ValidateScheduleException; |
107 | 107 | import org.tron.core.exception.ValidateSignatureException; |
108 | 108 | import org.tron.core.exception.ZksnarkException; |
| 109 | +import org.tron.core.net.TronNetDelegate; |
109 | 110 | import org.tron.core.store.AccountStore; |
110 | 111 | import org.tron.core.store.CodeStore; |
111 | 112 | import org.tron.core.store.DynamicPropertiesStore; |
@@ -506,23 +507,21 @@ public void adjustAssetBalanceV2Test() { |
506 | 507 | } |
507 | 508 |
|
508 | 509 | @Test |
509 | | - public void pushBlockInvalidMerkelRoot() { |
510 | | - Transaction trx = Transaction.newBuilder().build(); |
511 | | - TransactionCapsule moreTrans = new TransactionCapsule(trx); |
512 | | - blockCapsule2.addTransaction(moreTrans); // add one more transaction will change merkroot |
513 | | - blockCapsule2.sign(ByteArray.fromHexString(Args.getLocalWitnesses() |
514 | | - .getPrivateKey())); |
515 | | - try { |
516 | | - dbManager.pushBlock(blockCapsule2); |
517 | | - Assert.assertTrue(false); |
518 | | - } catch (BadBlockException e) { |
519 | | - Assert.assertTrue(e instanceof BadBlockException); |
520 | | - Assert.assertTrue(e.getType().equals(CALC_MERKLE_ROOT_FAILED)); |
521 | | - Assert.assertTrue(e.getMessage().startsWith( |
522 | | - "merkle root mismatch for block " + blockCapsule2.getNum() + ":")); |
523 | | - } catch (Exception e) { |
524 | | - Assert.assertFalse(e instanceof Exception); |
525 | | - } |
| 510 | + public void pushPrevalidatedBlockDoesNotRepeatMerkleValidation() throws Exception { |
| 511 | + byte[] witnessKey = ByteArray.fromHexString(Args.getLocalWitnesses().getPrivateKey()); |
| 512 | + BlockCapsule block = new BlockCapsule(1, chainManager.getGenesisBlockId(), 1, |
| 513 | + ByteString.copyFrom(ECKey.fromPrivate(witnessKey).getAddress())); |
| 514 | + block.setMerkleRoot(); |
| 515 | + block.sign(witnessKey); |
| 516 | + BlockCapsule received = spy(block); |
| 517 | + |
| 518 | + context.getBean(TronNetDelegate.class).validBlock(received); |
| 519 | + dbManager.pushBlock(received); |
| 520 | + |
| 521 | + Assert.assertEquals(received.getBlockId(), chainManager.getHeadBlockId()); |
| 522 | + Assert.assertEquals(received.getInstance(), |
| 523 | + chainManager.getBlockStore().get(received.getBlockId().getBytes()).getInstance()); |
| 524 | + verify(received, times(1)).validateMerkleRoot(); |
526 | 525 | } |
527 | 526 |
|
528 | 527 | @Test |
|
0 commit comments