Search in sources :

Example 1 with KeyList

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

the class CryptoCreateSuite method createAnAccountInvalidThresholdKey.

// One of element in threshold key is not valid
private HapiApiSpec createAnAccountInvalidThresholdKey() {
    KeyShape emptyListShape = listOf(0);
    KeyShape thresholdShape = threshOf(1, SIMPLE, SIMPLE, emptyListShape);
    long initialBalance = 10_000L;
    // build a threshold key with one of key is invalid
    Key randomKey1 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key randomKey2 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key shortKey = Key.newBuilder().setEd25519(ByteString.copyFrom(new byte[10])).build();
    KeyList invalidKeyList = KeyList.newBuilder().addKeys(randomKey1).addKeys(randomKey2).addKeys(shortKey).build();
    ThresholdKey invalidThresholdKey = ThresholdKey.newBuilder().setThreshold(2).setKeys(invalidKeyList).build();
    Key regKey1 = Key.newBuilder().setThresholdKey(invalidThresholdKey).build();
    Key regKey2 = Key.newBuilder().setKeyList(invalidKeyList).build();
    return defaultHapiSpec("createAnAccountInvalidThresholdKey").given().when().then(withOpContext((spec, opLog) -> {
        spec.registry().saveKey("regKey1", regKey1);
        spec.registry().saveKey("regKey2", regKey2);
    }), cryptoCreate("badThresholdKeyAccount").keyShape(thresholdShape).balance(initialBalance).logged().hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount2").key("regKey1").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount3").key("regKey2").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KEY_REQUIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_REQUIRED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) KeyList(com.hederahashgraph.api.proto.java.KeyList) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) UtilVerbs.validateChargedUsd(com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd) REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) KeyList(com.hederahashgraph.api.proto.java.KeyList) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey)

Example 2 with KeyList

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

the class FileOpsUsageTest method estimatesEmptyUpdateAsExpected.

@Test
void estimatesEmptyUpdateAsExpected() {
    // setup:
    long oldExpiry = expiry - 1_234L;
    byte[] oldContents = "Archiac".getBytes();
    KeyList oldWacl = KeyUtils.A_KEY_LIST.getKeyList();
    String oldMemo = "Lettuce";
    givenEmptyUpdateOp();
    // 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(BASIC_ENTITY_ID_SIZE + LONG_SIZE);
    verify(base, never()).addSbs(0L);
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test)

Example 3 with KeyList

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

the class JThresholdKeyTest method JThresholdKeyWithVariousThresholdTest.

@Test
void JThresholdKeyWithVariousThresholdTest() throws Exception {
    Key validContractIDKey = Key.newBuilder().setContractID(ContractID.newBuilder().setContractNum(1L).build()).build();
    Key validRSA3072Key = Key.newBuilder().setRSA3072(TxnUtils.randomUtf8ByteString(16)).build();
    KeyList validKeyList = KeyList.newBuilder().addKeys(validContractIDKey).addKeys(validRSA3072Key).build();
    assertFalse(jThresholdKey(validKeyList, 0).isValid());
    assertTrue(jThresholdKey(validKeyList, 1).isValid());
    assertTrue(jThresholdKey(validKeyList, 2).isValid());
    assertFalse(jThresholdKey(validKeyList, 3).isValid());
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) JKeyListTest.randomValidECDSASecp256K1Key(com.hedera.services.legacy.core.jproto.JKeyListTest.randomValidECDSASecp256K1Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) Test(org.junit.jupiter.api.Test)

Example 4 with KeyList

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

the class JThresholdKeyTest method invalidJThresholdKeyTest.

@Test
void invalidJThresholdKeyTest() throws Exception {
    Key validED25519Key = Key.newBuilder().setEd25519(TxnUtils.randomUtf8ByteString(JEd25519Key.ED25519_BYTE_LENGTH)).build();
    Key validECDSA384Key = Key.newBuilder().setECDSA384(TxnUtils.randomUtf8ByteString(24)).build();
    Key validECDSASecp256Key = randomValidECDSASecp256K1Key();
    KeyList invalidKeyList1 = KeyList.newBuilder().build();
    Key invalidKey1 = thresholdKey(invalidKeyList1, 1);
    KeyList invalidKeyList2 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(invalidKey1).build();
    Key invalidKey2 = thresholdKey(invalidKeyList2, 2);
    KeyList invalidKeyList3 = KeyList.newBuilder().addKeys(validECDSA384Key).addKeys(invalidKey2).build();
    Key invalidKey3 = thresholdKey(invalidKeyList2, 2);
    KeyList invalidKeyList4 = KeyList.newBuilder().addKeys(validECDSASecp256Key).addKeys(invalidKey3).build();
    JKey jThresholdKey1 = JKey.convertKey(invalidKey1, 1);
    assertFalse(jThresholdKey1.isValid());
    JKey jThresholdKey2 = JKey.convertKey(invalidKey2, 1);
    assertFalse(jThresholdKey2.isValid());
    assertFalse(jThresholdKey(invalidKeyList3, 1).isValid());
    assertFalse(jThresholdKey(invalidKeyList4, 1).isValid());
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) JKeyListTest.randomValidECDSASecp256K1Key(com.hedera.services.legacy.core.jproto.JKeyListTest.randomValidECDSASecp256K1Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) Test(org.junit.jupiter.api.Test)

Example 5 with KeyList

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

the class JKeyListTest method invalidJKeyListTest.

@Test
void invalidJKeyListTest() throws Exception {
    Key validED25519Key = Key.newBuilder().setEd25519(TxnUtils.randomUtf8ByteString(JEd25519Key.ED25519_BYTE_LENGTH)).build();
    Key invalidECDSAsecp256k1Key = randomInvalidECDSASecp256K1Key();
    KeyList invalidKeyList1 = KeyList.newBuilder().build();
    Key invalidKey1 = Key.newBuilder().setKeyList(invalidKeyList1).build();
    KeyList invalidKeyList2 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(invalidKey1).build();
    Key invalidKey2 = Key.newBuilder().setKeyList(invalidKeyList2).build();
    KeyList invalidKeyList3 = KeyList.newBuilder().addKeys(validED25519Key).addKeys(invalidKey2).build();
    Key invalidKey3 = Key.newBuilder().setKeyList(invalidKeyList3).build();
    KeyList invalidKeyList4 = KeyList.newBuilder().addKeys(invalidECDSAsecp256k1Key).addKeys(invalidKey3).build();
    Key invalidKey4 = Key.newBuilder().setKeyList(invalidKeyList4).build();
    JKey jKeyList1 = JKey.convertKey(invalidKey1, 1);
    assertFalse(jKeyList1.isValid());
    JKey jKeyList2 = JKey.convertKey(invalidKey2, 1);
    assertFalse(jKeyList2.isValid());
    JKey jKeyList3 = JKey.convertKey(invalidKey3, 1);
    assertFalse(jKeyList3.isValid());
    JKey jKeyList4 = JKey.convertKey(invalidKey4, 1);
    assertFalse(jKeyList4.isValid());
}
Also used : KeyList(com.hederahashgraph.api.proto.java.KeyList) Key(com.hederahashgraph.api.proto.java.Key) 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