Search in sources :

Example 1 with EntityRequest

use of com.radixdlt.api.core.openapitools.model.EntityRequest in project radixdlt by radixdlt.

the class EntityHandlerTest method retrieve_prepared_unstake_entity_on_genesis.

@Test
public void retrieve_prepared_unstake_entity_on_genesis() throws Exception {
    // Arrange
    start();
    // Act
    var address = REAddr.ofPubKeyAccount(selfKey());
    var request = new EntityRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).entityIdentifier(coreModelMapper.entityIdentifierPreparedUnstake(address));
    var response = handleRequestWithExpectedResponse(sut, request, EntityResponse.class);
    // Assert
    var stateAccumulator = response.getStateIdentifier().getTransactionAccumulator();
    var genesisAccumulator = genesis.getProof().getAccumulatorState().getAccumulatorHash().asBytes();
    assertThat(stateAccumulator).isEqualTo(Bytes.toHexString(genesisAccumulator));
    assertThat(response.getDataObjects()).isEmpty();
    assertThat(response.getBalances()).isEmpty();
}
Also used : EntityRequest(com.radixdlt.api.core.openapitools.model.EntityRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with EntityRequest

use of com.radixdlt.api.core.openapitools.model.EntityRequest in project radixdlt by radixdlt.

the class EntityHandlerTest method retrieve_validator_system_entity_on_genesis.

@Test
public void retrieve_validator_system_entity_on_genesis() throws Exception {
    // Arrange
    start();
    // Act
    var request = new EntityRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).entityIdentifier(coreModelMapper.entityIdentifierValidatorSystem(selfKey()));
    var response = handleRequestWithExpectedResponse(sut, request, EntityResponse.class);
    // Assert
    var stateAccumulator = response.getStateIdentifier().getTransactionAccumulator();
    var genesisAccumulator = genesis.getProof().getAccumulatorState().getAccumulatorHash().asBytes();
    assertThat(stateAccumulator).isEqualTo(Bytes.toHexString(genesisAccumulator));
    assertThat(response.getDataObjects()).hasOnlyElementsOfTypes(ValidatorBFTData.class, ValidatorData.class);
    assertThat(response.getBalances()).containsExactly(coreModelMapper.nativeTokenAmount(getStakeAmount().toSubunits()));
}
Also used : EntityRequest(com.radixdlt.api.core.openapitools.model.EntityRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 3 with EntityRequest

use of com.radixdlt.api.core.openapitools.model.EntityRequest in project radixdlt by radixdlt.

the class NodeApiClient method getUnstakes.

public List<ResourceAmount> getUnstakes(REAddr addr, ECPublicKey validatorKey) {
    var networkIdentifier = new NetworkIdentifier().network("localnet");
    var unstakingDelayEpochLength = unstakingDelayEpochLength();
    var unstakes = new ArrayList<ResourceAmount>();
    try {
        var statusResponse = engineStatusHandler.handleRequest(new EngineStatusRequest().networkIdentifier(networkIdentifier));
        var curEpoch = statusResponse.getEngineStateIdentifier().getEpoch();
        var maxEpoch = curEpoch + unstakingDelayEpochLength + 1;
        for (long epochUnstake = curEpoch; epochUnstake <= maxEpoch; epochUnstake++) {
            var response = entityHandler.handleRequest(new EntityRequest().networkIdentifier(networkIdentifier).entityIdentifier(coreModelMapper.entityIdentifierExitingStake(addr, validatorKey, epochUnstake)));
            unstakes.addAll(response.getBalances());
        }
    } catch (CoreApiException e) {
        throw new IllegalStateException(e);
    }
    return unstakes;
}
Also used : EntityRequest(com.radixdlt.api.core.openapitools.model.EntityRequest) CoreApiException(com.radixdlt.api.core.model.CoreApiException) EngineStatusRequest(com.radixdlt.api.core.openapitools.model.EngineStatusRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ArrayList(java.util.ArrayList)

Example 4 with EntityRequest

use of com.radixdlt.api.core.openapitools.model.EntityRequest in project radixdlt by radixdlt.

the class EntityHandlerTest method retrieve_validator_entity_on_genesis.

@Test
public void retrieve_validator_entity_on_genesis() throws Exception {
    // Arrange
    start();
    // Act
    var request = new EntityRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).entityIdentifier(coreModelMapper.entityIdentifier(selfKey()));
    var response = handleRequestWithExpectedResponse(sut, request, EntityResponse.class);
    // Assert
    var stateAccumulator = response.getStateIdentifier().getTransactionAccumulator();
    var genesisAccumulator = genesis.getProof().getAccumulatorState().getAccumulatorHash().asBytes();
    assertThat(stateAccumulator).isEqualTo(Bytes.toHexString(genesisAccumulator));
    assertThat(response.getDataObjects()).hasOnlyElementsOfTypes(ValidatorAllowDelegation.class, ValidatorMetadata.class, ValidatorSystemMetadata.class, PreparedValidatorOwner.class, PreparedValidatorFee.class, PreparedValidatorRegistered.class);
    assertThat(response.getBalances()).isEmpty();
}
Also used : EntityRequest(com.radixdlt.api.core.openapitools.model.EntityRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 5 with EntityRequest

use of com.radixdlt.api.core.openapitools.model.EntityRequest in project radixdlt by radixdlt.

the class EntityHandlerTest method retrieve_system_entity_on_genesis.

@Test
public void retrieve_system_entity_on_genesis() throws Exception {
    // Arrange
    start();
    // Act
    var request = new EntityRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).entityIdentifier(new EntityIdentifier().address("system"));
    var response = handleRequestWithExpectedResponse(sut, request, EntityResponse.class);
    // Assert
    var stateAccumulator = response.getStateIdentifier().getTransactionAccumulator();
    var genesisAccumulator = genesis.getProof().getAccumulatorState().getAccumulatorHash().asBytes();
    assertThat(stateAccumulator).isEqualTo(Bytes.toHexString(genesisAccumulator));
    assertThat(response.getBalances()).isEmpty();
    assertThat(response.getDataObjects()).isNotEmpty();
}
Also used : EntityRequest(com.radixdlt.api.core.openapitools.model.EntityRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) EntityIdentifier(com.radixdlt.api.core.openapitools.model.EntityIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Aggregations

EntityRequest (com.radixdlt.api.core.openapitools.model.EntityRequest)12 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)11 ApiTest (com.radixdlt.api.ApiTest)10 Test (org.junit.Test)10 CoreApiException (com.radixdlt.api.core.model.CoreApiException)2 EntityIdentifier (com.radixdlt.api.core.openapitools.model.EntityIdentifier)2 Inject (com.google.inject.Inject)1 CoreJsonRpcHandler (com.radixdlt.api.core.CoreJsonRpcHandler)1 CoreModelMapper (com.radixdlt.api.core.model.CoreModelMapper)1 EngineStatusRequest (com.radixdlt.api.core.openapitools.model.EngineStatusRequest)1 EntityResponse (com.radixdlt.api.core.openapitools.model.EntityResponse)1 SubEntity (com.radixdlt.api.core.openapitools.model.SubEntity)1 UnclaimedRadixEngineAddress (com.radixdlt.api.core.openapitools.model.UnclaimedRadixEngineAddress)1 ResourceInBucket (com.radixdlt.application.tokens.ResourceInBucket)1 TokenResourceMetadata (com.radixdlt.application.tokens.state.TokenResourceMetadata)1 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)1 SystemMapKey (com.radixdlt.constraintmachine.SystemMapKey)1 RadixEngine (com.radixdlt.engine.RadixEngine)1 REAddr (com.radixdlt.identifiers.REAddr)1 LedgerAndBFTProof (com.radixdlt.statecomputer.LedgerAndBFTProof)1