Search in sources :

Example 1 with ConstructionParseRequest

use of com.radixdlt.api.core.openapitools.model.ConstructionParseRequest 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 2 with ConstructionParseRequest

use of com.radixdlt.api.core.openapitools.model.ConstructionParseRequest 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)

Aggregations

ApiTest (com.radixdlt.api.ApiTest)2 ConstructionParseRequest (com.radixdlt.api.core.openapitools.model.ConstructionParseRequest)2 NetworkIdentifier (com.radixdlt.api.core.openapitools.model.NetworkIdentifier)2 Test (org.junit.Test)2 Inject (com.google.inject.Inject)1 ConstructionParseHandler (com.radixdlt.api.core.handlers.ConstructionParseHandler)1 CoreModelMapper (com.radixdlt.api.core.model.CoreModelMapper)1 EntityOperation (com.radixdlt.api.core.model.EntityOperation)1 NotEnoughNativeTokensForFeesException (com.radixdlt.api.core.model.NotEnoughNativeTokensForFeesException)1 OperationTxBuilder (com.radixdlt.api.core.model.OperationTxBuilder)1 ResourceOperation (com.radixdlt.api.core.model.ResourceOperation)1 TokenResource (com.radixdlt.api.core.model.TokenResource)1 AccountVaultEntity (com.radixdlt.api.core.model.entities.AccountVaultEntity)1 ConstructionParseResponse (com.radixdlt.api.core.openapitools.model.ConstructionParseResponse)1 Operation (com.radixdlt.api.core.openapitools.model.Operation)1 Amount (com.radixdlt.application.tokens.Amount)1 ECPublicKey (com.radixdlt.crypto.ECPublicKey)1 RadixEngine (com.radixdlt.engine.RadixEngine)1 Self (com.radixdlt.hotstuff.bft.Self)1 REAddr (com.radixdlt.identifiers.REAddr)1