@Test public void getsMinTransactionGasPrice() { final Wei minGasPrice = Wei.of(10); when(ibftBlockCreatorFactory.getMinTransactionGasPrice()).thenReturn(minGasPrice); assertThat(ibftMiningCoordinator.getMinTransactionGasPrice()).isEqualTo(minGasPrice); }
@Test public void setsMinTransactionGasPrice() { final Wei minGasPrice = Wei.of(10); ibftMiningCoordinator.setMinTransactionGasPrice(minGasPrice); verify(ibftBlockCreatorFactory).setMinTransactionGasPrice(minGasPrice); }
@Test public void shouldReturnEmptyCodeHashWhenPrecompileHasBalance() { // Sending money to a precompile causes it to exist in the world state archive. worldStateUpdater.getOrCreate(Address.ECREC).setBalance(Wei.of(10)); assertThat(executeOperation(Address.ECREC)).isEqualTo(Hash.EMPTY); }
@Test public void shouldReturnExpectedValueWhenMiningCoordinatorExists() { final JsonRpcRequest request = requestWithParams(); final String expectedWei = "0x4d2"; final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getId(), expectedWei); when(miningCoordinator.getMinTransactionGasPrice()).thenReturn(Wei.of(1234)); final JsonRpcResponse actualResponse = method.response(request); assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse); verify(miningCoordinator).getMinTransactionGasPrice(); verifyNoMoreInteractions(miningCoordinator); }
@Test public void shouldNotNotifyBatchListenerWhenRemoteTransactionDoesNotReplaceExisting() { final TransactionTestFixture builder = new TransactionTestFixture(); final Transaction transaction1 = builder.nonce(1).gasPrice(Wei.of(10)).createTransaction(KEY_PAIR1); final Transaction transaction2 = builder.nonce(1).gasPrice(Wei.of(5)).createTransaction(KEY_PAIR1); when(transactionValidator.validate(any(Transaction.class))).thenReturn(valid()); when(transactionValidator.validateForSender( eq(transaction1), nullable(Account.class), eq(OptionalLong.empty()))) .thenReturn(valid()); when(transactionValidator.validateForSender( eq(transaction2), nullable(Account.class), eq(OptionalLong.of(2)))) .thenReturn(valid()); transactionPool.addRemoteTransactions(singletonList(transaction1)); transactionPool.addRemoteTransactions(singletonList(transaction2)); assertTransactionPending(transaction1); verify(batchAddedListener).onTransactionsAdded(singleton(transaction1)); verify(batchAddedListener, never()).onTransactionsAdded(singleton(transaction2)); }
@Test public void shouldNotNotifyBatchListenerWhenLocalTransactionDoesNotReplaceExisting() { final TransactionTestFixture builder = new TransactionTestFixture(); final Transaction transaction1 = builder.nonce(1).gasPrice(Wei.of(10)).createTransaction(KEY_PAIR1); final Transaction transaction2 = builder.nonce(1).gasPrice(Wei.of(5)).createTransaction(KEY_PAIR1); when(transactionValidator.validate(any(Transaction.class))).thenReturn(valid()); when(transactionValidator.validateForSender( eq(transaction1), nullable(Account.class), eq(OptionalLong.empty()))) .thenReturn(valid()); when(transactionValidator.validateForSender( eq(transaction2), nullable(Account.class), eq(OptionalLong.of(2)))) .thenReturn(valid()); transactionPool.addLocalTransaction(transaction1); transactionPool.addLocalTransaction(transaction2); assertTransactionPending(transaction1); verify(batchAddedListener).onTransactionsAdded(singletonList(transaction1)); verify(batchAddedListener, never()).onTransactionsAdded(singletonList(transaction2)); }
private Transaction transactionWithNonceSenderAndGasPrice( final int nonce, final KeyPair keyPair, final long gasPrice) { return new TransactionTestFixture() .nonce(nonce) .gasPrice(Wei.of(gasPrice)) .createTransaction(keyPair); }
private Transaction createTransaction(final int transactionNumber) { return new TransactionTestFixture() .value(Wei.of(transactionNumber)) .nonce(transactionNumber) .createTransaction(KEYS1); } }
@Test public void replaceAccountBalance() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setBalance(Wei.of(200000)); updater.commit(); assertEquals(Wei.of(200000), worldState.get(ADDRESS).getBalance()); assertEquals( Hash.fromHexString("0xbfa4e0598cc2b810a8ccc4a2d9a4c575574d05c9c4a7f915e6b8545953a5051e"), worldState.rootHash()); }
@Test public void getAccountBalance_AccountExists() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); assertEquals(Wei.of(100000), worldState.get(ADDRESS).getBalance()); }
@Test public void containsAccount_AccountExists() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); assertNotNull(worldState.get(ADDRESS)); assertEquals( Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"), worldState.rootHash()); }
private MessageFrameTestFixture validMessageFrameBuilder() { final BlockHeader blockHeader = new BlockHeaderTestFixture().number(1).buildHeader(); final TestBlockchain blockchain = new TestBlockchain(blockHeader.getNumber()); return new MessageFrameTestFixture() .initialGas(INITIAL_GAS) .worldState(worldUpdater) .gasPrice(Wei.of(25)) .blockHeader(blockHeader) .blockchain(blockchain) .depth(DEPTH); }
@Test public void removeAccount_UpdatedAccount() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.deleteAccount(ADDRESS); updater.commit(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); worldState.persist(); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }
@Test public void replaceStorageValue_ZeroValue() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setStorageValue(UInt256.ONE, UInt256.of(2)); account.setStorageValue(UInt256.ONE, UInt256.ZERO); updater.commit(); assertEquals( Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"), worldState.rootHash()); }
@Test public void setStorageValue_ZeroValue() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setStorageValue(UInt256.ZERO, UInt256.ZERO); updater.commit(); assertEquals(UInt256.ZERO, worldState.get(ADDRESS).getStorageValue(UInt256.ZERO)); assertEquals( Hash.fromHexString("0xa3e1c133a5a51b03399ed9ad0380f3182e9e18322f232b816dd4b9094f871e1b"), worldState.rootHash()); }
@Test public void setStorageValue_NonzeroValue() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setStorageValue(UInt256.ONE, UInt256.of(2)); updater.commit(); assertEquals(UInt256.of(2), worldState.get(ADDRESS).getStorageValue(UInt256.ONE)); assertEquals( Hash.fromHexString("0xd31ce0bf3bf8790083a8ebde418244fda3b1cca952d7119ed244f86d03044656"), worldState.rootHash()); }
@Test public void replaceStorageValue_NonzeroValue() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setStorageValue(UInt256.ONE, UInt256.of(2)); account.setStorageValue(UInt256.ONE, UInt256.of(3)); updater.commit(); assertEquals(UInt256.of(3), worldState.get(ADDRESS).getStorageValue(UInt256.ONE)); assertEquals( Hash.fromHexString("0x1d0ddb5079fe5b8689124b68c9e5bb3f4d8e13c2f7489d24f088c78fd45e058d"), worldState.rootHash()); }
@Test public void replaceAccountCode() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setCode(BytesValue.of(1, 2, 3)); account.setCode(BytesValue.of(3, 2, 1)); updater.commit(); assertEquals(BytesValue.of(3, 2, 1), worldState.get(ADDRESS).getCode()); assertEquals( Hash.fromHexString("0xc14f5e30581de9155ea092affa665fad83bcd9f98e45c4a42885b9b36d939702"), worldState.rootHash()); }
@Test public void removeAccount_AccountExists() { // Create a world state with one account final MutableWorldState worldState = createEmpty(); WorldUpdater updater = worldState.updater(); updater.createAccount(ADDRESS).setBalance(Wei.of(100000)); updater.commit(); assertNotNull(worldState.get(ADDRESS)); assertNotEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); // Delete account updater = worldState.updater(); updater.deleteAccount(ADDRESS); assertNull(updater.get(ADDRESS)); assertNull(updater.getMutable(ADDRESS)); updater.commit(); assertNull(updater.get(ADDRESS)); assertEquals(MerklePatriciaTrie.EMPTY_TRIE_NODE_HASH, worldState.rootHash()); }