From d3a24e1c80f0c52c9505b5361d28a58333e78529 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Fri, 6 Oct 2023 13:50:14 +0300 Subject: [PATCH] Update tests for Crypto contract to the latest testing framework API --- runtime/stdlib/contracts/crypto_test.cdc | 318 +++++++++++++++--- runtime/stdlib/contracts/flow.json | 8 +- .../scripts/crypto_get_key_from_list.cdc | 21 -- .../stdlib/contracts/scripts/crypto_hash.cdc | 6 - .../scripts/crypto_hash_with_tag.cdc | 10 - .../contracts/scripts/crypto_key_list_add.cdc | 18 - .../scripts/crypto_key_list_verify.cdc | 51 --- ...to_key_list_verify_duplicate_signature.cdc | 39 --- ...o_key_list_verify_insufficient_weights.cdc | 51 --- ...ypto_key_list_verify_invalid_signature.cdc | 34 -- ...ypto_key_list_verify_missing_signature.cdc | 34 -- .../crypto_key_list_verify_revoked.cdc | 36 -- .../scripts/crypto_revoke_key_from_list.cdc | 24 -- 13 files changed, 285 insertions(+), 365 deletions(-) delete mode 100644 runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_hash.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc delete mode 100644 runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc diff --git a/runtime/stdlib/contracts/crypto_test.cdc b/runtime/stdlib/contracts/crypto_test.cdc index b4ce834ff7..051f1ffef0 100644 --- a/runtime/stdlib/contracts/crypto_test.cdc +++ b/runtime/stdlib/contracts/crypto_test.cdc @@ -1,19 +1,11 @@ import Test - -access(all) let blockchain = Test.newEmulatorBlockchain() -access(all) let account = blockchain.createAccount() +import Crypto from "crypto.cdc" access(all) fun setup() { - blockchain.useConfiguration(Test.Configuration({ - "Crypto": account.address - })) - - let crypto = Test.readFile("crypto.cdc") - let err = blockchain.deployContract( + let err = Test.deployContract( name: "Crypto", - code: crypto, - account: account, + path: "crypto.cdc", arguments: [] ) @@ -22,76 +14,322 @@ fun setup() { access(all) fun testCryptoHash() { - let returnedValue = executeScript("./scripts/crypto_hash.cdc") - Test.assertEqual(true, returnedValue) + let hash = Crypto.hash([1, 2, 3], algorithm: HashAlgorithm.SHA3_256) + Test.assertEqual(32, hash.length) } access(all) fun testCryptoHashWithTag() { - let returnedValue = executeScript("./scripts/crypto_hash_with_tag.cdc") - Test.assertEqual(true, returnedValue) + let hash = Crypto.hashWithTag( + [1, 2, 3], + tag: "v0.1.tag", + algorithm: HashAlgorithm.SHA3_256 + ) + Test.assertEqual(32, hash.length) } access(all) fun testAddKeyToKeyList() { - let returnedValue = executeScript("./scripts/crypto_key_list_add.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 1.0 + ) + + Test.assert(keyList.get(keyIndex: 0) != nil) } access(all) fun testGetKeyFromList() { - let returnedValue = executeScript("./scripts/crypto_get_key_from_list.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 1.0 + ) + + Test.assert(keyList.get(keyIndex: 0) != nil) + Test.assert(keyList.get(keyIndex: 2) == nil) } access(all) fun testRevokeKeyFromList() { - let returnedValue = executeScript("./scripts/crypto_revoke_key_from_list.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + keyList.revoke(keyIndex: 0) + keyList.revoke(keyIndex: 2) + + Test.assert(keyList.get(keyIndex: 0)!.isRevoked) + Test.assert(keyList.get(keyIndex: 2) == nil) } access(all) fun testKeyListVerify() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKeyA = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + + keyList.add( + publicKeyA, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let publicKeyB = PublicKey( + publicKey: + "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + + keyList.add( + publicKeyB, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ), + Crypto.KeyListSignature( + keyIndex: 1, + signature: + "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex() + ) + ] + + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) + + Test.assert(isValid) } access(all) fun testKeyListVerifyInsufficientWeights() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify_insufficient_weights.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKeyA = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + + keyList.add( + publicKeyA, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.4 + ) + + let publicKeyB = PublicKey( + publicKey: + "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + + keyList.add( + publicKeyB, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ), + Crypto.KeyListSignature( + keyIndex: 1, + signature: + "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex() + ) + ] + + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) + + Test.assert(!isValid) } access(all) fun testKeyListVerifyWithRevokedKey() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify_revoked.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ) + ] + + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + keyList.revoke(keyIndex: 0) + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) + + Test.assert(!isValid) } access(all) fun testKeyListVerifyWithMissingSignature() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify_missing_signature.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 1, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ) + ] + + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) + + Test.assert(!isValid) } access(all) fun testKeyListVerifyDuplicateSignature() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify_duplicate_signature.cdc") - Test.assertEqual(true, returnedValue) + let keyList = Crypto.KeyList() + + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ), + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ) + ] + + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) + + Test.assert(!isValid) } access(all) fun testKeyListVerifyInvalidSignature() { - let returnedValue = executeScript("./scripts/crypto_key_list_verify_invalid_signature.cdc") - Test.assertEqual(true, returnedValue) -} + let keyList = Crypto.KeyList() -access(self) -fun executeScript(_ scriptPath: String): Bool { - let script = Test.readFile(scriptPath) - let scriptResult = blockchain.executeScript(script, []) + let publicKey = PublicKey( + publicKey: + "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), + signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 + ) + keyList.add( + publicKey, + hashAlgorithm: HashAlgorithm.SHA3_256, + weight: 0.5 + ) + + let signatureSet = [ + Crypto.KeyListSignature( + keyIndex: 0, + signature: + "db70a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() + ) + ] - Test.expect(scriptResult, Test.beSucceeded()) + // "foo", encoded as UTF-8, in hex representation + let signedData = "666f6f".decodeHex() + + let isValid = keyList.verify( + signatureSet: signatureSet, + signedData: signedData + ) - return scriptResult.returnValue! as! Bool + Test.assert(!isValid) } diff --git a/runtime/stdlib/contracts/flow.json b/runtime/stdlib/contracts/flow.json index 5ac314e31f..7604b6c306 100644 --- a/runtime/stdlib/contracts/flow.json +++ b/runtime/stdlib/contracts/flow.json @@ -1,12 +1,18 @@ { "networks": { "emulator": "127.0.0.1:3569", + "testing": "127.0.0.1:3569", "mainnet": "access.mainnet.nodes.onflow.org:9000", "sandboxnet": "access.sandboxnet.nodes.onflow.org:9000", "testnet": "access.devnet.nodes.onflow.org:9000" }, "contracts": { - "Crypto": "crypto.cdc" + "Crypto": { + "source": "crypto.cdc", + "aliases": { + "testing": "0x0000000000000007" + } + } }, "deployments": { "emulator": { diff --git a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc deleted file mode 100644 index e3996d5559..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc +++ /dev/null @@ -1,21 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 1.0 - ) - - assert(keyList.get(keyIndex: 0) != nil) - assert(keyList.get(keyIndex: 2) == nil) - - return true -} diff --git a/runtime/stdlib/contracts/scripts/crypto_hash.cdc b/runtime/stdlib/contracts/scripts/crypto_hash.cdc deleted file mode 100644 index ec32b00faf..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_hash.cdc +++ /dev/null @@ -1,6 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let hash = Crypto.hash([1, 2, 3], algorithm: HashAlgorithm.SHA3_256) - return hash.length == 32 -} diff --git a/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc b/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc deleted file mode 100644 index 984d4eff26..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc +++ /dev/null @@ -1,10 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let hash = Crypto.hashWithTag( - [1, 2, 3], - tag: "v0.1.tag", - algorithm: HashAlgorithm.SHA3_256 - ) - return hash.length == 32 -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc deleted file mode 100644 index a336c04715..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc +++ /dev/null @@ -1,18 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 1.0 - ) - - return keyList.get(keyIndex: 0) != nil -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc deleted file mode 100644 index 72d39b4052..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc +++ /dev/null @@ -1,51 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKeyA = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - - keyList.add( - publicKeyA, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let publicKeyB = PublicKey( - publicKey: - "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - - keyList.add( - publicKeyB, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ), - Crypto.KeyListSignature( - keyIndex: 1, - signature: - "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - let isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - return isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc deleted file mode 100644 index fd68e13687..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc +++ /dev/null @@ -1,39 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ), - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - var isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - - return !isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc deleted file mode 100644 index 4c17b52ac4..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc +++ /dev/null @@ -1,51 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKeyA = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - - keyList.add( - publicKeyA, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.4 - ) - - let publicKeyB = PublicKey( - publicKey: - "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - - keyList.add( - publicKeyB, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ), - Crypto.KeyListSignature( - keyIndex: 1, - signature: - "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - let isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - return !isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc deleted file mode 100644 index 8e3eb19c86..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc +++ /dev/null @@ -1,34 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "db70a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - var isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - - return !isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc deleted file mode 100644 index bdbf23653a..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc +++ /dev/null @@ -1,34 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 1, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - var isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - - return !isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc deleted file mode 100644 index 84af7e5063..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc +++ /dev/null @@ -1,36 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - let signatureSet = [ - Crypto.KeyListSignature( - keyIndex: 0, - signature: - "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex() - ) - ] - - // "foo", encoded as UTF-8, in hex representation - let signedData = "666f6f".decodeHex() - - keyList.revoke(keyIndex: 0) - - var isValid = keyList.verify( - signatureSet: signatureSet, - signedData: signedData - ) - - return !isValid -} diff --git a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc deleted file mode 100644 index 998d8530a4..0000000000 --- a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc +++ /dev/null @@ -1,24 +0,0 @@ -import "Crypto" - -pub fun main(): Bool { - let keyList = Crypto.KeyList() - - let publicKey = PublicKey( - publicKey: - "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(), - signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 - ) - keyList.add( - publicKey, - hashAlgorithm: HashAlgorithm.SHA3_256, - weight: 0.5 - ) - - keyList.revoke(keyIndex: 0) - keyList.revoke(keyIndex: 2) - - assert(keyList.get(keyIndex: 0)!.isRevoked) - assert(keyList.get(keyIndex: 2) == nil) - - return true -}