Skip to content

Commit

Permalink
test: did-cheqd-registrar (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean authored Oct 29, 2023
1 parent 362140e commit a1634ca
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions waltid-did/src/jvmTest/kotlin/registrars/DidCheqdRegistrarTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package registrars

import id.walt.crypto.keys.Key
import id.walt.crypto.keys.KeyType
import id.walt.crypto.keys.LocalKey
import id.walt.did.dids.registrar.dids.DidCheqdCreateOptions
import id.walt.did.dids.registrar.dids.DidCreateOptions
import id.walt.did.dids.registrar.local.cheqd.DidCheqdRegistrar
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.Arguments.arguments
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream

class DidCheqdRegistrarTest : DidRegistrarTestBase(DidCheqdRegistrar()) {

@ParameterizedTest
@MethodSource
override fun `given did options with no key when register then returns a valid did result`(
options: DidCreateOptions,
assert: registrarDidAssertion
) {
super.`given did options with no key when register then returns a valid did result`(options, assert)
}

@ParameterizedTest
@MethodSource
override fun `given did options and key when register with key then returns a valid did result`(
key: Key,
options: DidCreateOptions,
assert: registrarKeyAssertion
) {
super.`given did options and key when register with key then returns a valid did result`(key, options, assert)
}

companion object {

@JvmStatic
fun `given did options with no key when register then returns a valid did result`(): Stream<Arguments> =
Stream.of(
arguments(DidCheqdCreateOptions(network = "testnet"), ed25519DidAssertions),
)

@JvmStatic
fun `given did options and key when register with key then returns a valid did result`(): Stream<Arguments> =
keyTestData(ed25519KeyAssertions)

private fun keyTestData(
ed25519Assertions: registrarKeyAssertion,
) = Stream.of(
//ed25519
arguments(
runBlocking { LocalKey.generate(KeyType.Ed25519) },
DidCheqdCreateOptions(network = "testnet"),
ed25519Assertions
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class DidRegistrarTestBase(private val registrar: LocalRegistrarMethod)
assert(doc["id"]!!.jsonPrimitive.content == did)
// assert [verificationMethod id] and [did] are identical
assert(doc["verificationMethod"]!!.jsonArray.any {
it.jsonObject["id"]!!.jsonPrimitive.content == did
it.jsonObject["id"]!!.jsonPrimitive.content.substringBefore("#") == did
})
// assert [verificationMethod controller] and [did] are identical
assert(doc["verificationMethod"]!!.jsonArray.any {
Expand Down

0 comments on commit a1634ca

Please sign in to comment.