11package fr.acinq.secp256k1
22
33import kotlinx.serialization.json.*
4- import org.kodein.memory.file.FileSystem
5- import org.kodein.memory.file.Path
6- import org.kodein.memory.file.openReadableFile
7- import org.kodein.memory.file.resolve
8- import org.kodein.memory.system.Environment
9- import org.kodein.memory.text.readString
10- import org.kodein.memory.use
114import kotlin.test.*
125
136class Musig2Test {
14- fun resourcesDir () =
15- Environment .findVariable(" TEST_RESOURCES_PATH" )?.let { Path (it) }
16- ? : FileSystem .workingDir().resolve(" src/commonTest/resources" )
17-
18- fun readData (filename : String ): JsonElement {
19- val file = resourcesDir().resolve(filename)
20- val raw = file.openReadableFile().use { it.readString() }
21- val format = Json { ignoreUnknownKeys = true }
22- return format.parseToJsonElement(raw)
23- }
24-
257 @Test
268 fun `aggregate public keys` () {
27- val tests = readData (" musig2/key_agg_vectors.json" )
9+ val tests = TestHelpers .readResourceAsJson (" musig2/key_agg_vectors.json" )
2810 val pubkeys = tests.jsonObject[" pubkeys" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
2911 val tweaks = tests.jsonObject[" tweaks" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
3012
@@ -81,7 +63,7 @@ class Musig2Test {
8163
8264 @Test
8365 fun `generate secret nonce` () {
84- val tests = readData (" musig2/nonce_gen_vectors.json" )
66+ val tests = TestHelpers .readResourceAsJson (" musig2/nonce_gen_vectors.json" )
8567 tests.jsonObject[" test_cases" ]!! .jsonArray.forEach {
8668 val randprime = Hex .decode(it.jsonObject[" rand_" ]!! .jsonPrimitive.content)
8769 val sk = it.jsonObject[" sk" ]?.jsonPrimitive?.contentOrNull?.let { Hex .decode(it) }
@@ -110,7 +92,7 @@ class Musig2Test {
11092
11193 @Test
11294 fun `aggregate nonces` () {
113- val tests = readData (" musig2/nonce_agg_vectors.json" )
95+ val tests = TestHelpers .readResourceAsJson (" musig2/nonce_agg_vectors.json" )
11496 val nonces = tests.jsonObject[" pnonces" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
11597 tests.jsonObject[" valid_test_cases" ]!! .jsonArray.forEach {
11698 val nonceIndices = it.jsonObject[" pnonce_indices" ]!! .jsonArray.map { it.jsonPrimitive.int }
@@ -129,7 +111,7 @@ class Musig2Test {
129111
130112 @Test
131113 fun sign () {
132- val tests = readData (" musig2/sign_verify_vectors.json" )
114+ val tests = TestHelpers .readResourceAsJson (" musig2/sign_verify_vectors.json" )
133115 val sk = Hex .decode(tests.jsonObject[" sk" ]!! .jsonPrimitive.content)
134116 val pubkeys = tests.jsonObject[" pubkeys" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
135117 val secnonces = tests.jsonObject[" secnonces" ]!! .jsonArray.map { deserializeSecretNonce(it.jsonPrimitive.content) }
@@ -179,7 +161,7 @@ class Musig2Test {
179161
180162 @Test
181163 fun `aggregate signatures` () {
182- val tests = readData (" musig2/sig_agg_vectors.json" )
164+ val tests = TestHelpers .readResourceAsJson (" musig2/sig_agg_vectors.json" )
183165 val pubkeys = tests.jsonObject[" pubkeys" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
184166 val pnonces = tests.jsonObject[" pnonces" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
185167 val tweaks = tests.jsonObject[" tweaks" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
@@ -240,7 +222,7 @@ class Musig2Test {
240222
241223 @Test
242224 fun `tweak tests` () {
243- val tests = readData (" musig2/tweak_vectors.json" )
225+ val tests = TestHelpers .readResourceAsJson (" musig2/tweak_vectors.json" )
244226 val sk = Hex .decode(tests.jsonObject[" sk" ]!! .jsonPrimitive.content)
245227 val pubkeys = tests.jsonObject[" pubkeys" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
246228 val pnonces = tests.jsonObject[" pnonces" ]!! .jsonArray.map { Hex .decode(it.jsonPrimitive.content) }
0 commit comments