From 11cedee211a7af0cbc21df0bb6f5b57c419f8ae5 Mon Sep 17 00:00:00 2001 From: kasiastreich Date: Fri, 24 Mar 2017 15:14:02 +0000 Subject: [PATCH] Size of notary key in vault schema fix. (#414) Fix in vault schema so notary_key can have more key entries in CompositeKey, as it's kept as Base58 string. Change default varchar field with size 255 to varchar with size 65535. Add test to VaultSchemaTest. --- .../vault/schemas/VaultStatesEntity.java | 1 + .../services/vault/schemas/VaultSchema.kt | 2 +- .../services/vault/schemas/VaultSchemaTest.kt | 22 +++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/node-schemas/generated/source/kapt/main/net/corda/node/services/vault/schemas/VaultStatesEntity.java b/node-schemas/generated/source/kapt/main/net/corda/node/services/vault/schemas/VaultStatesEntity.java index def225c344..348b8af323 100644 --- a/node-schemas/generated/source/kapt/main/net/corda/node/services/vault/schemas/VaultStatesEntity.java +++ b/node-schemas/generated/source/kapt/main/net/corda/node/services/vault/schemas/VaultStatesEntity.java @@ -82,6 +82,7 @@ public class VaultStatesEntity implements VaultSchema.VaultStates, Persistable { .setLazy(false) .setNullable(true) .setUnique(false) + .setLength(65535) .build()); public static final AttributeDelegate CONTRACT_STATE_CLASS_NAME = new AttributeDelegate( diff --git a/node-schemas/src/main/kotlin/net/corda/node/services/vault/schemas/VaultSchema.kt b/node-schemas/src/main/kotlin/net/corda/node/services/vault/schemas/VaultSchema.kt index e1a0dafff5..6100f27a33 100644 --- a/node-schemas/src/main/kotlin/net/corda/node/services/vault/schemas/VaultSchema.kt +++ b/node-schemas/src/main/kotlin/net/corda/node/services/vault/schemas/VaultSchema.kt @@ -40,7 +40,7 @@ object VaultSchema { @get:Column(name = "notary_name") var notaryName: String - @get:Column(name = "notary_key") + @get:Column(name = "notary_key", length = 65535) // TODO What is the upper limit on size of CompositeKey? var notaryKey: String /** references a concrete ContractState that is [QueryableState] and has a [MappedSchema] */ diff --git a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt index c2f9023081..bc89b95eda 100644 --- a/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt +++ b/node-schemas/src/test/kotlin/net/corda/node/services/vault/schemas/VaultSchemaTest.kt @@ -8,10 +8,7 @@ import io.requery.rx.KotlinRxEntityStore import io.requery.sql.* import io.requery.sql.platform.Generic import net.corda.core.contracts.* -import net.corda.core.crypto.CompositeKey -import net.corda.core.crypto.Party -import net.corda.core.crypto.SecureHash -import net.corda.core.crypto.composite +import net.corda.core.crypto.* import net.corda.core.node.services.Vault import net.corda.core.schemas.requery.converters.InstantConverter import net.corda.core.schemas.requery.converters.VaultStateStatusConverter @@ -527,4 +524,21 @@ class VaultSchemaTest { assertEquals(3, count) } } + + @Test + fun insertWithBigCompositeKey() { + val keys = (1..314).map { generateKeyPair().public.composite } + val bigNotaryKey = CompositeKey.Builder().addKeys(keys).build() + val vaultStEntity = VaultStatesEntity().apply { + txId = SecureHash.randomSHA256().toString() + index = 314 + stateStatus = Vault.StateStatus.UNCONSUMED + contractStateClassName = VaultNoopContract.VaultNoopState::class.java.name + notaryName = "Huge distributed notary" + notaryKey = bigNotaryKey.toBase58String() + recordedTime = Instant.now() + } + data.insert(vaultStEntity) + assertEquals(1, data.select(VaultSchema.VaultStates::class).get().count()) + } } \ No newline at end of file