Search in sources :

Example 1 with NetworkIdentifier

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

the class ConstructionDeriveHandlerTest method invalid_public_key_should_throw_exception.

@Test
public void invalid_public_key_should_throw_exception() {
    // Arrange
    start();
    // Act
    // Assert
    var request = new ConstructionDeriveRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).publicKey(new PublicKey().hex("deadbeaddeadbead")).metadata(new ConstructionDeriveRequestMetadataToken().symbol("test").type("Token"));
    assertThatThrownBy(() -> sut.handleRequest(request)).isInstanceOfSatisfying(CoreApiException.class, e -> {
        var error = e.toError();
        assertThat(error.getDetails()).isInstanceOf(InvalidPublicKeyError.class);
        assertThat(error.getCode()).isEqualTo(CoreApiErrorCode.BAD_REQUEST.getErrorCode());
    });
}
Also used : PublicKey(com.radixdlt.api.core.openapitools.model.PublicKey) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ConstructionDeriveRequest(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequest) ConstructionDeriveRequestMetadataToken(com.radixdlt.api.core.openapitools.model.ConstructionDeriveRequestMetadataToken) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 2 with NetworkIdentifier

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

the class ConstructionFinalizeTest method finalizing_a_transaction_with_signature_should_return_back_signed_tranaction.

@Test
public void finalizing_a_transaction_with_signature_should_return_back_signed_tranaction() throws Exception {
    // Arrange
    start();
    // Act
    var accountAddress = REAddr.ofPubKeyAccount(self);
    var otherAddress = REAddr.ofPubKeyAccount(PrivateKeys.ofNumeric(2).getPublicKey());
    var unsignedTxn = buildUnsignedTransferTxn(accountAddress, otherAddress);
    var sig = hashSigner.sign(unsignedTxn.hashToSign());
    var os = new ByteArrayOutputStream();
    var asn1OutputStream = ASN1OutputStream.create(os);
    asn1OutputStream.writeObject(new DLSequence(new ASN1Encodable[] { new ASN1Integer(sig.getR()), new ASN1Integer(sig.getS()) }));
    var derSignature = os.toByteArray();
    var request = new ConstructionFinalizeRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).unsignedTransaction(Bytes.toHexString(unsignedTxn.blob())).signature(new Signature().bytes(Bytes.toHexString(derSignature)).publicKey(coreModelMapper.publicKey(self)));
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionFinalizeResponse.class);
    // Assert
    var bytes = Bytes.fromHexString(response.getSignedTransaction());
    assertThat(bytes).isNotNull();
}
Also used : ConstructionFinalizeRequest(com.radixdlt.api.core.openapitools.model.ConstructionFinalizeRequest) DLSequence(org.bouncycastle.asn1.DLSequence) Signature(com.radixdlt.api.core.openapitools.model.Signature) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 3 with NetworkIdentifier

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

the class ConstructionHashHandlerTest method handling_construction_hash_should_return_hash.

@Test
public void handling_construction_hash_should_return_hash() throws Exception {
    // Arrange
    start();
    // Act
    var txn = Txn.create(Bytes.fromHexString("deadbeef"));
    var request = new ConstructionHashRequest().networkIdentifier(new NetworkIdentifier().network("localnet")).signedTransaction("deadbeef");
    var response = handleRequestWithExpectedResponse(sut, request, ConstructionHashResponse.class);
    // Assert
    assertThat(response.getTransactionIdentifier()).isEqualTo(coreModelMapper.transactionIdentifier(txn.getId()));
}
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 4 with NetworkIdentifier

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

the class EngineStatusHandlerTest method engine_configuration_should_return_correct_data.

@Test
public void engine_configuration_should_return_correct_data() throws Exception {
    // Arrange
    start();
    // Act
    var request = new EngineStatusRequest().networkIdentifier(new NetworkIdentifier().network("localnet"));
    var response = handleRequestWithExpectedResponse(sut, request, EngineStatusResponse.class);
    // Assert
    assertThat(response.getValidatorSet()).containsExactly(new Validator().validatorAddress(addressing.forValidators().of(selfKey())).stake(getStakeAmount().toSubunits().toString()));
}
Also used : EngineStatusRequest(com.radixdlt.api.core.openapitools.model.EngineStatusRequest) NetworkIdentifier(com.radixdlt.api.core.openapitools.model.NetworkIdentifier) Validator(com.radixdlt.api.core.openapitools.model.Validator) ApiTest(com.radixdlt.api.ApiTest) Test(org.junit.Test)

Example 5 with NetworkIdentifier

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

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