use of com.hederahashgraph.api.proto.java.ThresholdKey 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));
}
use of com.hederahashgraph.api.proto.java.ThresholdKey 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());
}
use of com.hederahashgraph.api.proto.java.ThresholdKey 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]);
}
Aggregations