Search in sources :

Example 6 with KeyList

use of com.hederahashgraph.api.proto.java.KeyList in project hedera-services by hashgraph.

the class JKeyListTest method validJKeyListTest.

@Test
void validJKeyListTest() throws Exception {
    Key validED25519Key = Key.newBuilder().setEd25519(TxnUtils.randomUtf8ByteString(JEd25519Key.ED25519_BYTE_LENGTH)).build();
    Key validECDSAsecp256k1Key = randomValidECDSASecp256K1Key();
    Key validECDSA384Key = Key.newBuilder().setECDSA384(TxnUtils.randomUtf8ByteString(24)).build();
    KeyList validKeyList1 = KeyList.newBuilder().addKeys(validECDSA384Key).addKeys(validED25519Key).build();
    Key validKey1 = Key.newBuilder().setKeyList(validKeyList1).build();
    KeyList validKeyList2 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(validKey1).build();
    Key validKey2 = Key.newBuilder().setKeyList(validKeyList2).build();
    KeyList validKeyList3 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(validKey2).build();
    Key validKey3 = Key.newBuilder().setKeyList(validKeyList3).build();
    KeyList validKeyList4 = KeyList.newBuilder().addKeys(validECDSAsecp256k1Key).addKeys(validKey3).build();
    Key validKey4 = Key.newBuilder().setKeyList(validKeyList4).build();
    JKey jKeyList1 = JKey.convertKey(validKey1, 1);
    assertTrue(jKeyList1.isValid());
    JKey jKeyList2 = JKey.convertKey(validKey2, 1);
    assertTrue(jKeyList2.isValid());
    JKey jKeyList3 = JKey.convertKey(validKey3, 1);
    assertTrue(jKeyList3.isValid());
    JKey jKeyList4 = JKey.convertKey(validKey4, 1);
    assertTrue(jKeyList4.isValid());
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Example 7 with KeyList

use of com.hederahashgraph.api.proto.java.KeyList in project hedera-services by hashgraph.

the class FileOpsUsageTest method estimatesUpdateAsExpected.

@Test
void estimatesUpdateAsExpected() {
    // setup:
    long oldExpiry = expiry - 1_234L;
    byte[] oldContents = "Archiac".getBytes();
    KeyList oldWacl = KeyUtils.A_KEY_LIST.getKeyList();
    String oldMemo = "Lettuce";
    // and:
    long bytesUsed = reprSize() - FileOpsUsage.bytesInBaseRepr();
    // and:
    long oldSbs = (oldExpiry - now) * (oldContents.length + oldMemo.length() + getAccountKeyStorageSize(Key.newBuilder().setKeyList(oldWacl).build()));
    // and:
    long newSbs = (expiry - now) * bytesUsed;
    givenUpdateOp();
    // and:
    var ctx = ExtantFileContext.newBuilder().setCurrentExpiry(oldExpiry).setCurrentMemo(oldMemo).setCurrentWacl(oldWacl).setCurrentSize(oldContents.length).build();
    // when:
    var estimate = subject.fileUpdateUsage(txn, sigUsage, ctx);
    // then:
    assertEquals(A_USAGES_MATRIX, estimate);
    // and:
    verify(base).addBpt(bytesUsed + BASIC_ENTITY_ID_SIZE + LONG_SIZE);
    verify(base).addSbs(newSbs - oldSbs);
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test)

Example 8 with KeyList

use of com.hederahashgraph.api.proto.java.KeyList in project hedera-services by hashgraph.

the class FeeBuilderTest method assertCalculateKeysMetadataThresholdKey.

@Test
void assertCalculateKeysMetadataThresholdKey() {
    int[] countKeyMetatData = { 0, 0 };
    KeyList thresholdKeyList = KeyList.newBuilder().addKeys(Key.newBuilder().setEd25519(ByteString.copyFromUtf8("aaaaaaaa")).build()).addKeys(Key.newBuilder().setEd25519(ByteString.copyFromUtf8("bbbbbbbbbbbbbbbbbbbbb")).build()).build();
    ThresholdKey thresholdKey = ThresholdKey.newBuilder().setKeys(thresholdKeyList).setThreshold(2).build();
    Key validED25519Keys = Key.newBuilder().setThresholdKey(thresholdKey).build();
    assertEquals(countKeyMetatData.length, FeeBuilder.calculateKeysMetadata(validED25519Keys, countKeyMetatData).length);
    assertEquals(2, FeeBuilder.calculateKeysMetadata(validED25519Keys, countKeyMetatData)[1]);
}
Also used : ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) Test(org.junit.jupiter.api.Test)

Aggregations

KeyList (com.hederahashgraph.api.proto.java.KeyList)8 Test (org.junit.jupiter.api.Test)7 Key (com.hederahashgraph.api.proto.java.Key)6 ThresholdKey (com.hederahashgraph.api.proto.java.ThresholdKey)4 ByteString (com.google.protobuf.ByteString)3 JKeyListTest.randomValidECDSASecp256K1Key (com.hedera.services.legacy.core.jproto.JKeyListTest.randomValidECDSASecp256K1Key)2 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)1 KeyShape (com.hedera.services.bdd.spec.keys.KeyShape)1 SIMPLE (com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE)1 KeyShape.listOf (com.hedera.services.bdd.spec.keys.KeyShape.listOf)1 KeyShape.threshOf (com.hedera.services.bdd.spec.keys.KeyShape.threshOf)1 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)1 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)1 TxnUtils.randomUtf8Bytes (com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes)1 TxnVerbs.contractCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate)1 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)1 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)1 TxnVerbs.fileUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate)1 TxnVerbs.tokenCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate)1