Search in sources :

Example 1 with JEd25519Key

use of com.hedera.services.legacy.core.jproto.JEd25519Key in project hedera-services by hashgraph.

the class PlatformSigOpsTest method ignoresAmbiguousScheduledSig.

@Test
void ignoresAmbiguousScheduledSig() throws Throwable {
    final JKey scheduledKey = new JEd25519Key("01234578901234578901234578901".getBytes());
    scheduledKey.setForScheduledTxn(true);
    given(sigBytes.sigBytesFor(any())).willThrow(KeyPrefixMismatchException.class);
    final var result = createCryptoSigsFrom(List.of(scheduledKey), sigBytes, sigFactory);
    assertFalse(result.hasFailed());
    assertTrue(result.getPlatformSigs().isEmpty());
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 2 with JEd25519Key

use of com.hedera.services.legacy.core.jproto.JEd25519Key in project hedera-services by hashgraph.

the class RationalizationTest method resetWorks.

@Test
void resetWorks() {
    given(txnAccessor.getPlatformTxn()).willReturn(swirldsTxn);
    final List<TransactionSignature> mockSigs = new ArrayList<>();
    final JKey fake = new JEd25519Key("FAKE".getBytes(StandardCharsets.UTF_8));
    subject = new Rationalization(syncVerifier, keyOrderer, sigFactory);
    given(txnAccessor.getPkToSigsFn()).willReturn(pkToSigFn);
    given(swirldsTxn.getSignatures()).willReturn(mockSigs);
    // and:
    subject.getRealPayerSigs().add(null);
    subject.getRealOtherPartySigs().add(null);
    subject.setReqPayerSig(fake);
    subject.setReqOthersSigs(List.of(fake));
    subject.setLastOrderResult(CODE_ORDER_RESULT_FACTORY.forGeneralError());
    subject.setFinalStatus(INVALID_ACCOUNT_ID);
    subject.setVerifiedSync(true);
    // when:
    subject.resetFor(txnAccessor);
    // then:
    assertSame(txnAccessor, subject.getTxnAccessor());
    assertSame(syncVerifier, subject.getSyncVerifier());
    assertSame(keyOrderer, subject.getSigReqs());
    assertSame(pkToSigFn, subject.getPkToSigFn());
    assertSame(mockSigs, subject.getTxnSigs());
    // and:
    assertTrue(subject.getRealPayerSigs().isEmpty());
    assertTrue(subject.getRealOtherPartySigs().isEmpty());
    // and:
    assertFalse(subject.usedSyncVerification());
    assertNull(subject.finalStatus());
    assertNull(subject.getReqPayerSig());
    assertNull(subject.getReqOthersSigs());
    assertNull(subject.getLastOrderResult());
    // and:
    verify(sigFactory).resetFor(txnAccessor);
    verify(pkToSigFn).resetAllSigsToUnused();
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) ArrayList(java.util.ArrayList) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 3 with JEd25519Key

use of com.hedera.services.legacy.core.jproto.JEd25519Key in project hedera-services by hashgraph.

the class PrecheckKeyReqsTest method usesBothOrderForQueryPayments.

@Test
void usesBothOrderForQueryPayments() throws Exception {
    final JKey key1 = new JEd25519Key("firstKey".getBytes());
    final JKey key2 = new JEd25519Key("secondKey".getBytes());
    final JKey key3 = new JEd25519Key("thirdKey".getBytes());
    final JKey key4 = new JEd25519Key("firstKey".getBytes());
    given(keyOrder.keysForPayer(txn, CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(List.of(key1)));
    given(keyOrder.keysForOtherParties(txn, CODE_ORDER_RESULT_FACTORY)).willReturn(new SigningOrderResult<>(List.of(key2, key3, key4)));
    givenImpliedSubject(FOR_QUERY_PAYMENT);
    // when:
    keys = subject.getRequiredKeys(txn);
    // then:
    verify(keyOrder).keysForPayer(txn, CODE_ORDER_RESULT_FACTORY);
    verify(keyOrder).keysForOtherParties(txn, CODE_ORDER_RESULT_FACTORY);
    verifyNoMoreInteractions(keyOrder);
    assertEquals(3, keys.size());
    assertTrue(keys.contains(key1));
    assertTrue(keys.contains(key2));
    assertTrue(keys.contains(key3));
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 4 with JEd25519Key

use of com.hedera.services.legacy.core.jproto.JEd25519Key in project hedera-services by hashgraph.

the class CodeOrderResultFactoryTest method createsNewResultForValidOrder.

@Test
void createsNewResultForValidOrder() {
    // given:
    final List<JKey> pretendKeys = List.of(new JEd25519Key("IMAGINARY".getBytes(StandardCharsets.UTF_8)));
    // when:
    final var ans = subject.forValidOrder(pretendKeys);
    // then:
    assertSame(pretendKeys, ans.getOrderedKeys());
}
Also used : JKey(com.hedera.services.legacy.core.jproto.JKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Test(org.junit.jupiter.api.Test)

Example 5 with JEd25519Key

use of com.hedera.services.legacy.core.jproto.JEd25519Key in project hedera-services by hashgraph.

the class CommonTestUtils method createRandomMerkleAccountState.

public static MerkleAccountState createRandomMerkleAccountState(int iteration, Random random) {
    byte[] key = new byte[JEd25519Key.ED25519_BYTE_LENGTH];
    random.nextBytes(key);
    JEd25519Key ed25519Key = new JEd25519Key(key);
    return new MerkleAccountState(ed25519Key, iteration, iteration, iteration, randomString(256, random), false, false, false, new EntityId(iteration, iteration, iteration), 1001, 0);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState)

Aggregations

JEd25519Key (com.hedera.services.legacy.core.jproto.JEd25519Key)6 JKey (com.hedera.services.legacy.core.jproto.JKey)5 Test (org.junit.jupiter.api.Test)5 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)1 EntityId (com.hedera.services.state.submerkle.EntityId)1 TransactionSignature (com.swirlds.common.crypto.TransactionSignature)1 ArrayList (java.util.ArrayList)1