Search in sources :

Example 26 with NetworkIdentifier

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

the class ConstructionHashHandlerTest method invalid_hex_should_throw.

@Test
public void invalid_hex_should_throw() throws Exception {
    // Arrange
    start();
    // Act
    var request = new ConstructionHashRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).signedTransaction("this_is_not_hex");
    var response = handleRequestWithExpectedResponse(sut, request, UnexpectedError.class);
    // Assert
    assertThat(response.getDetails()).isInstanceOf(InvalidHexError.class);
}
Also used : ConstructionHashRequest(com.radixdlt.api.core.openapitools.model.ConstructionHashRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 27 with NetworkIdentifier

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

the class ConstructionParseMessageTest method parsing_transaction_with_message_should_show_message.

@Test
public void parsing_transaction_with_message_should_show_message() throws Exception {
    // Arrange
    start();
    // Act
    var hex = "deadbeefdeadbeef";
    var unsignedTxn = buildUnsignedTxnWithMessage(hex);
    var request = new ConstructionParseRequest().signed(false).networkIdentifier(new NetworkIdentifier().network("localnet")).transaction(Bytes.toHexString(unsignedTxn));
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionParseResponse.class);
    // Assert
    assertThat(response.getMetadata()).isNotNull();
    assertThat(response.getMetadata().getMessage()).isEqualTo(hex);
}
Also used : NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ConstructionParseRequest(com.radixdlt.api.core.openapitools.model.ConstructionParseRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 28 with NetworkIdentifier

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

the class ConstructionParseTransferTest method parsing_transaction_with_transfer_should_have_proper_substates.

@Test
public void parsing_transaction_with_transfer_should_have_proper_substates() throws Exception {
    // Arrange
    start();
    // Act
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherAddress = REAddr.ofPubKeyAccount(PrivateKeys.ofNumeric(2).getPublicKey());
    var unsignedTxn = buildUnsignedTransferTxn(accountAddress, otherAddress);
    var request = new ConstructionParseRequest().signed(false).networkIdentifier(new NetworkIdentifier().network("localnet")).transaction(Bytes.toHexString(unsignedTxn));
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionParseResponse.class);
    // Assert
    assertThat(response.getMetadata()).isNotNull();
    assertThat(response.getMetadata().getMessage()).isNull();
    var feeValue = new BigInteger(response.getMetadata().getFee().getValue());
    assertThat(feeValue).isGreaterThan(BigInteger.ZERO);
    var entityHoldings = response.getOperationGroups().stream().flatMap(g -> g.getOperations().stream()).peek(op -> {
        assertThat(op.getSubstate()).isNotNull();
        assertThat(op.getSubstate().getSubstateIdentifier()).isNotNull();
        assertThat(op.getAmount()).isNotNull();
        assertThat(op.getAmount().getResourceIdentifier()).isEqualTo(coreModelMapper.nativeToken());
    }).collect(Collectors.groupingBy(Operation::getEntityIdentifier, Collectors.mapping(op -> new BigInteger(op.getAmount().getValue()), Collectors.reducing(BigInteger.ZERO, BigInteger::add))));
    var accountEntityIdentifier = coreModelMapper.entityIdentifier(accountAddress);
    var otherEntityIdentifier = coreModelMapper.entityIdentifier(otherAddress);
    var transferAmount = new BigInteger(transferAmount().toString());
    var expectedChange = transferAmount.negate().subtract(feeValue);
    assertThat(entityHoldings).containsExactlyInAnyOrderEntriesOf(Map.of(accountEntityIdentifier, expectedChange, otherEntityIdentifier, transferAmount));
}
Also used : NotEnoughNativeTokensForFeesException(com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException) OperationTxBuilder(com.radixdlt.api.core.model.OperationTxBuilder) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) ResourceOperation(com.radixdlt.api.core.model.ResourceOperation) ApiTest(com.radixdlt.api.ApiTest) ECPublicKey(com.radixdlt.crypto.ECPublicKey) ConstructionParseRequest(com.radixdlt.api.core.openapitools.model.ConstructionParseRequest) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) Operation(com.radixdlt.api.core.openapitools.model.Operation) Map(java.util.Map) AccountVaultEntity(com.radixdlt.api.core.model.entities.AccountVaultEntity) BigInteger(java.math.BigInteger) UInt256(com.radixdlt.utils.UInt256) CoreModelMapper(com.radixdlt.api.core.model.CoreModelMapper) PrivateKeys(com.radixdlt.utils.PrivateKeys) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) TokenResource(com.radixdlt.api.core.model.TokenResource) REAddr(com.radixdlt.identifiers.REAddr) Collectors(java.util.stream.Collectors) List(java.util.List) Bytes(com.radixdlt.utils.Bytes) ConstructionParseResponse(com.radixdlt.api.core.openapitools.model.ConstructionParseResponse) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ConstructionParseHandler(com.radixdlt.api.core.handlers.ConstructionParseHandler) Self(com.radixdlt.hotstuff.bft.Self) Amount(com.radixdlt.application.tokens.Amount) EntityOperation(com.radixdlt.api.core.model.EntityOperation) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) BigInteger(java.math.BigInteger) ConstructionParseRequest(com.radixdlt.api.core.openapitools.model.ConstructionParseRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 29 with NetworkIdentifier

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

the class TransactionsHandlerTest method retrieve_genesis_in_transaction_stream.

@Test
public void retrieve_genesis_in_transaction_stream() throws Exception {
    // Arrange
    start();
    // Act
    var request = new CommittedTransactionsRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).limit(1L).stateIdentifier(new PartialStateIdentifier().stateVersion(0L));
    var response = handleRequestWithExpectedResponse(sut, request, CommittedTransactionsResponse.class);
    // Assert
    assertThat(response.getTransactions()).hasSize(1);
    var hex = response.getTransactions().get(0).getMetadata().getHex();
    assertThat(hex).isEqualTo(Bytes.toHexString(genesis.getTxns().get(0).getPayload()));
}
Also used : PartialStateIdentifier(com.radixdlt.api.core.openapitools.model.PartialStateIdentifier) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) CommittedTransactionsRequest(com.radixdlt.api.core.openapitools.model.CommittedTransactionsRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 30 with NetworkIdentifier

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

the class TransactionsHandlerTest method retrieving_past_last_state_version_should_throw_exception.

@Test
public void retrieving_past_last_state_version_should_throw_exception() throws Exception {
    // Arrange
    start();
    // Act
    var request = new CommittedTransactionsRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).limit(1L).stateIdentifier(new PartialStateIdentifier().stateVersion(2L));
    var response = handleRequestWithExpectedResponse(sut, request, UnexpectedError.class);
    // Assert
    assertThat(response.getDetails()).isInstanceOf(StateIdentifierNotFoundError.class);
}
Also used : PartialStateIdentifier(com.radixdlt.api.core.openapitools.model.PartialStateIdentifier) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) CommittedTransactionsRequest(com.radixdlt.api.core.openapitools.model.CommittedTransactionsRequest) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Aggregations

NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)32 ApiTest (com.radixdlt.api.ApiTest)29 Test (org.junit.Test)29 EntityRequest (com.radixdlt.api.core.openapitools.model.EntityRequest)11 CommittedTransactionsRequest (com.radixdlt.api.core.openapitools.model.CommittedTransactionsRequest)4 PartialStateIdentifier (com.radixdlt.api.core.openapitools.model.PartialStateIdentifier)4 KeySignRequest (com.radixdlt.api.core.openapitools.model.KeySignRequest)3 Operation (com.radixdlt.api.core.openapitools.model.Operation)3 ConstructionBuildRequest (com.radixdlt.api.core.openapitools.model.ConstructionBuildRequest)2 ConstructionDeriveRequest (com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest)2 ConstructionFinalizeRequest (com.radixdlt.api.core.openapitools.model.ConstructionFinalizeRequest)2 ConstructionHashRequest (com.radixdlt.api.core.openapitools.model.ConstructionHashRequest)2 ConstructionParseRequest (com.radixdlt.api.core.openapitools.model.ConstructionParseRequest)2 EngineStatusRequest (com.radixdlt.api.core.openapitools.model.EngineStatusRequest)2 EntityIdentifier (com.radixdlt.api.core.openapitools.model.EntityIdentifier)2 MempoolTransactionRequest (com.radixdlt.api.core.openapitools.model.MempoolTransactionRequest)2 OperationGroup (com.radixdlt.api.core.openapitools.model.OperationGroup)2 Signature (com.radixdlt.api.core.openapitools.model.Signature)2 Inject (com.google.inject.Inject)1 ConstructionParseHandler (com.radixdlt.api.core.handlers.ConstructionParseHandler)1