/** * Public constructor. * * @param value The value the AccountAddress represents. */ @JsonCreator public AddressMock(final String value) { super(Address.fromHexString(value)); } }
private FilterParameter filterParamWithAddressAndTopics( final Address address, final List<List<String>> topics) { final List<String> addresses = address != null ? Arrays.asList(address.toString()) : null; return new FilterParameter("latest", "latest", addresses, topics, null); }
@Test public void accountAddresHashCode() { final Address addr = Address.wrap(BytesValue.fromHexString("0x0000000000000000000000000000000000101010")); final Address addr2 = Address.wrap(BytesValue.fromHexString("0x0000000000000000000000000000000000101010")); Assert.assertEquals(addr.hashCode(), addr2.hashCode()); }
@Test public void miningOptionsRequiresServiceToBeEnabled() { final Address requestedCoinbase = Address.fromHexString("0000011111222223333344444"); parseCommand( "--miner-coinbase", requestedCoinbase.toString(), "--min-gas-price", "42", "--miner-extra-data", "0x1122334455667788990011223344556677889900112233445566778899001122"); verifyOptionsConstraintLoggerCall( "--miner-coinbase, --min-gas-price and --miner-extra-data", "--miner-enabled"); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); }
final Address localAddr = Address.extract(Hash.hash(nodeKeys.getPublicKey().getEncodedBytes())); final List<Address> initialValidatorList = Arrays.asList( Address.fromHexString(String.format("%020d", 1)), Address.fromHexString(String.format("%020d", 2)), Address.fromHexString(String.format("%020d", 3)), Address.fromHexString(String.format("%020d", 4)), localAddr); Address.fromHexString(String.format("%020d", 0)), parent -> new IbftExtraData(
@Test public void insufficientCommitSealsFailsValidation() { final KeyPair committerKeyPair = KeyPair.generate(); final Address committerAddress = Address.extract(Hash.hash(committerKeyPair.getPublicKey().getEncodedBytes())); final List<Address> validators = singletonList(committerAddress); final VoteTally voteTally = new VoteTally(validators); final ProtocolContext<IbftContext> context = new ProtocolContext<>(null, null, new IbftContext(voteTally, null)); final BlockHeader header = createProposedBlockHeader(validators, emptyList(), false); // Note that no committer seals are in the header's IBFT extra data. final IbftExtraData headerExtraData = IbftExtraData.decode(header.getExtraData()); assertThat(headerExtraData.getSeals().size()).isEqualTo(0); assertThat(commitSealsValidationRule.validate(header, null, context)).isFalse(); }
@Test(expected = IllegalArgumentException.class) public void invalidAccountAddress() { Address.wrap(BytesValue.fromHexString("0x00101010")); } }
@Test public void miningParametersAreCaptured() throws Exception { final Address requestedCoinbase = Address.fromHexString("0000011111222223333344444"); final String extraDataString = "0x1122334455667788990011223344556677889900112233445566778899001122"; parseCommand( "--miner-enabled", "--miner-coinbase=" + requestedCoinbase.toString(), "--min-gas-price=15", "--miner-extra-data=" + extraDataString); final ArgumentCaptor<MiningParameters> miningArg = ArgumentCaptor.forClass(MiningParameters.class); verify(mockControllerBuilder).miningParameters(miningArg.capture()); verify(mockControllerBuilder).build(); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.of(requestedCoinbase)); assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(15)); assertThat(miningArg.getValue().getExtraData()) .isEqualTo(BytesValue.fromHexString(extraDataString)); }
private boolean subExecution( final int validatorCount, final int committerCount, final boolean useDifferentRoundNumbersForCommittedSeals) { final List<Address> validators = Lists.newArrayList(); final List<KeyPair> committerKeys = Lists.newArrayList(); for (int i = 0; i < validatorCount; i++) { // need -1 to account for proposer final KeyPair committerKeyPair = KeyPair.generate(); committerKeys.add(committerKeyPair); validators.add(Address.extract(Hash.hash(committerKeyPair.getPublicKey().getEncodedBytes()))); } Collections.sort(validators); final VoteTally voteTally = new VoteTally(validators); BlockHeader header = createProposedBlockHeader( validators, committerKeys.subList(0, committerCount), useDifferentRoundNumbersForCommittedSeals); final ProtocolContext<IbftContext> context = new ProtocolContext<>(null, null, new IbftContext(voteTally, null)); return commitSealsValidationRule.validate(header, null, context); } }
Expectation( @JsonProperty("hash") final String hash, @JsonProperty("sender") final String sender) { this.succeeds = hash != null && sender != null; if (succeeds) { this.hash = Hash.fromHexString(hash); this.sender = Address.fromHexString(sender); } else { this.hash = null; this.sender = null; } }
public ExpectBeneficiary(final EthTransactions eth, final PantheonNode node) { this.eth = eth; this.beneficiary = node.getAddress().toString(); }
@Test public void proposerInValidatorListPassesValidation() { final KeyPair proposerKeyPair = KeyPair.generate(); final Address proposerAddress = Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes())); final List<Address> validators = Lists.newArrayList(proposerAddress); final List<KeyPair> committers = Lists.newArrayList(proposerKeyPair); final VoteTally voteTally = new VoteTally(validators); final ProtocolContext<IbftContext> context = new ProtocolContext<>(null, null, new IbftContext(voteTally, null)); final IbftCoinbaseValidationRule coinbaseValidationRule = new IbftCoinbaseValidationRule(); BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators, committers); assertThat(coinbaseValidationRule.validate(header, null, context)).isTrue(); }
private LogWithMetadata logWithMetadata() { return LogWithMetadata.create( 0, 100L, Hash.ZERO, Hash.ZERO, 0, Address.fromHexString("0x0"), BytesValue.EMPTY, Lists.newArrayList(), false); }
private List<LogsSubscription> createSubscriptions(final Address address) { final List<LogsSubscription> subscriptions = new ArrayList<>(); for (int i = 0; i < 3; i++) { final FilterParameter filterParameter = new FilterParameter(null, null, Lists.newArrayList(address.toString()), null, null); subscriptions.add(new LogsSubscription((long) i, filterParameter)); } when(subscriptionManager.subscriptionsOfType(any(), any())) .thenReturn(Lists.newArrayList(subscriptions)); return subscriptions; }
@Test public void ibftValidateHeaderFails() { final KeyPair proposerKeyPair = KeyPair.generate(); final Address proposerAddress = Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes())); final List<Address> validators = singletonList(proposerAddress); final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null); final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, null); final BlockHeaderValidator<IbftContext> validator = IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5); assertThat( validator.validateHeader( blockHeader, parentHeader, IbftProtocolContextFixture.protocolContext(validators), HeaderValidationMode.FULL)) .isFalse(); }
private LogWithMetadata logWithMetadata() { return LogWithMetadata.create( 0, 100L, Hash.ZERO, Hash.ZERO, 0, Address.fromHexString("0x0"), BytesValue.EMPTY, Lists.newArrayList(), false); } }
private LogsSubscription createSubscription(final Address address) { final FilterParameter filterParameter = new FilterParameter(null, null, Lists.newArrayList(address.toString()), null, null); final LogsSubscription logsSubscription = new LogsSubscription(1L, filterParameter); when(subscriptionManager.subscriptionsOfType(any(), any())) .thenReturn(Lists.newArrayList(logsSubscription)); return logsSubscription; }