Search in sources :

Example 1 with EmptyAccountAdapter

use of org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.EmptyAccountAdapter in project besu by hyperledger.

the class BlockDataFetcherTest method ibftMiner.

@Test
public void ibftMiner() throws Exception {
    // IBFT can mine blocks with a coinbase that is an empty account, hence not stored and returned
    // as null. The compromise is to report zeros and empty on query from a block.
    final Address testAddress = Address.fromHexString("0xdeadbeef");
    when(environment.getArgument(ArgumentMatchers.eq("number"))).thenReturn(1L);
    when(environment.getArgument(ArgumentMatchers.eq("hash"))).thenReturn(null);
    when(environment.getGraphQlContext()).thenReturn(graphQLContext);
    when(graphQLContext.get(GraphQLContextType.BLOCKCHAIN_QUERIES)).thenReturn(query);
    when(query.blockByNumber(ArgumentMatchers.anyLong())).thenReturn(Optional.of(new BlockWithMetadata<>(header, null, null, null, 0)));
    when(header.getCoinbase()).thenReturn(testAddress);
    when(query.getWorldState(anyLong())).thenReturn(Optional.of(mutableWorldState));
    final Optional<NormalBlockAdapter> maybeBlock = fetcher.get(environment);
    assertThat(maybeBlock).isPresent();
    assertThat(maybeBlock.get().getMiner(environment)).isPresent();
    assertThat(((EmptyAccountAdapter) maybeBlock.get().getMiner(environment).get()).getBalance()).isPresent();
    assertThat(((EmptyAccountAdapter) maybeBlock.get().getMiner(environment).get()).getAddress()).contains(testAddress);
}
Also used : Address(org.hyperledger.besu.datatypes.Address) EmptyAccountAdapter(org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.EmptyAccountAdapter) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) NormalBlockAdapter(org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.NormalBlockAdapter) Test(org.junit.Test)

Aggregations

Address (org.hyperledger.besu.datatypes.Address)1 EmptyAccountAdapter (org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.EmptyAccountAdapter)1 NormalBlockAdapter (org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter.NormalBlockAdapter)1 BlockWithMetadata (org.hyperledger.besu.ethereum.api.query.BlockWithMetadata)1 Test (org.junit.Test)1