From 7bdde975cffbaafe6f576c9fb71eb54d5cf4222f Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Wed, 15 Nov 2023 19:16:05 +0400 Subject: [PATCH] One more test --- src/Chainweb/Utils/Serialization.hs | 2 +- test/Chainweb/Test/Pact/SPV/Hyperlane.hs | 34 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Chainweb/Utils/Serialization.hs b/src/Chainweb/Utils/Serialization.hs index 4f3dd37f47..4ffb0269d0 100644 --- a/src/Chainweb/Utils/Serialization.hs +++ b/src/Chainweb/Utils/Serialization.hs @@ -171,7 +171,7 @@ putRawByteString :: B.ByteString -> Put putRawByteString = coerce (Binary.putBuilder . Builder.fromByteString) getRemainingLazyByteString :: Get BL.ByteString -getRemainingLazyByteString = coerce ( Binary.getRemainingLazyByteString) +getRemainingLazyByteString = coerce Binary.getRemainingLazyByteString -------------------- -- Abstract encoders/decoders diff --git a/test/Chainweb/Test/Pact/SPV/Hyperlane.hs b/test/Chainweb/Test/Pact/SPV/Hyperlane.hs index 9ac0766cfb..33c3b85bf8 100644 --- a/test/Chainweb/Test/Pact/SPV/Hyperlane.hs +++ b/test/Chainweb/Test/Pact/SPV/Hyperlane.hs @@ -10,6 +10,8 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + module Chainweb.Test.Pact.SPV.Hyperlane ( -- * test suite tests @@ -24,7 +26,6 @@ import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck -import Test.QuickCheck import Test.QuickCheck.Instances () import Chainweb.Test.Utils (prop_iso) @@ -68,7 +69,8 @@ tests = testGroup "hyperlane" , testCase "verifyFailure" hyperlaneVerifyFailure , testCase "verifyFailureIncorrectValidator" hyperlaneVerifyFailureIncorrectValidator - , testCase "verifyFailureNotEnoughSignatures" hyperlaneVerifyFailureNotEnoughSignatures + , testCase "verifyFailureNotEnoughRecoveredSignatures" hyperlaneVerifyFailureNotEnoughRecoveredSignatures + , testCase "verifyFailureNotEnoughSignaturesToPassThreshold" hyperlaneVerifyFailureNotEnoughSignaturesToPassThreshold ] hyperlaneEmptyObject :: Assertion @@ -239,7 +241,7 @@ hyperlaneVerifyFailure = do let obj' = mkObject [ ("message", tStr $ asString ("0x01000001450000027200000000000000000000000000000000006b622d746f6b656e2d726f757465720000000100000000000000000000000071c7656ec7ab88b098defb751b7401b5f6d8976f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000002a30783731433736353645433761623838623039386465664237353142373430314235663664383937364600000000000000000000000000000000000000000000" :: Text)) - -- different validator + -- validators: incorrect , ("validators", toTList tTyString def $ map (tStr . asString) [("0x5DD34992E0994E9d3c53c1CCfe5C2e38d907338e" :: Text)]) , ("metadata", tStr $ asString ("0x0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b00000000000000000000000000000000000000000000000000000000000000ad0000000f0e1c8be19e9e2bd14665599b8e8ed1f3dbca562788e5844975770eb31380b3ae5de03487e89a1d3c42fad8aac486a06e1af6b3478ec0d148c0c8566c404537291b" :: Text)) , ("threshold", tLit $ LInteger 1) @@ -255,6 +257,7 @@ hyperlaneVerifyFailureIncorrectValidator = do let obj' = mkObject [ ("message", tStr $ asString ("0x01000001450000027200000000000000000000000000000000006b622d746f6b656e2d726f757465720000000100000000000000000000000071c7656ec7ab88b098defb751b7401b5f6d8976f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000002a30783731433736353645433761623838623039386465664237353142373430314235663664383937364600000000000000000000000000000000000000000000" :: Text)) + -- validators: badly formatted , ("validators", toTList tTyString def $ map (tStr . asString) [("badValidator" :: Text)]) , ("metadata", tStr $ asString ("0x0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b00000000000000000000000000000000000000000000000000000000000000ad0000000f0e1c8be19e9e2bd14665599b8e8ed1f3dbca562788e5844975770eb31380b3ae5de03487e89a1d3c42fad8aac486a06e1af6b3478ec0d148c0c8566c404537291b" :: Text)) , ("threshold", tLit $ LInteger 1) @@ -265,11 +268,12 @@ hyperlaneVerifyFailureIncorrectValidator = do Left err -> assertEqual "Verification should fail" "Failed to decode a validator (badValidator):decodeHex: does not start with 0x" err Right _ -> assertFailure "Should fail" -hyperlaneVerifyFailureNotEnoughSignatures :: Assertion -hyperlaneVerifyFailureNotEnoughSignatures = do +hyperlaneVerifyFailureNotEnoughRecoveredSignatures :: Assertion +hyperlaneVerifyFailureNotEnoughRecoveredSignatures = do let obj' = mkObject [ ("message", tStr $ asString ("0x01000001450000027200000000000000000000000000000000006b622d746f6b656e2d726f757465720000000100000000000000000000000071c7656ec7ab88b098defb751b7401b5f6d8976f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000002a30783731433736353645433761623838623039386465664237353142373430314235663664383937364600000000000000000000000000000000000000000000" :: Text)) + -- validators: incorrect , ("validators", toTList tTyString def $ map (tStr . asString) [("0x5DD34992E0994E9d3c53c1CCfe5C2e38d907338e" :: Text)]) -- metadata without signatures , ("metadata", tStr $ asString ("0x0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b00000000000000000000000000000000000000000000000000000000000000ad0000000f" :: Text)) @@ -280,3 +284,23 @@ hyperlaneVerifyFailureNotEnoughSignatures = do case res of Left err -> assertEqual "Verification should fail" "The number of recovered addresses from the signatures is less than threshold: 1" err Right _ -> assertFailure "Should fail" + +-- | We pass 2 signatures, 1st one matches to the correct validator, +-- but there is no second valid validator for the 2nd signature, and the verification fails. +hyperlaneVerifyFailureNotEnoughSignaturesToPassThreshold :: Assertion +hyperlaneVerifyFailureNotEnoughSignaturesToPassThreshold = do + let + obj' = mkObject + [ ("message", tStr $ asString ("0x01000001450000027200000000000000000000000000000000006b622d746f6b656e2d726f757465720000000100000000000000000000000071c7656ec7ab88b098defb751b7401b5f6d8976f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000002a30783731433736353645433761623838623039386465664237353142373430314235663664383937364600000000000000000000000000000000000000000000" :: Text)) + , ("validators", toTList tTyString def $ map (tStr . asString) + -- validators: incorrect, correct, incorrect + ["0x5DD34992E0994E9d3c53c1CCfe5C2e38d907338e" :: Text, "0x4BD34992E0994E9d3c53c1CCfe5C2e38d907338e", "0x55D34992E0994E9d3c53c1CCfe5C2e38d907338e"]) + -- metadata with the 2 same signatures + , ("metadata", tStr $ asString ("0x0000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b00000000000000000000000000000000000000000000000000000000000000ad0000000f0e1c8be19e9e2bd14665599b8e8ed1f3dbca562788e5844975770eb31380b3ae5de03487e89a1d3c42fad8aac486a06e1af6b3478ec0d148c0c8566c404537291b0e1c8be19e9e2bd14665599b8e8ed1f3dbca562788e5844975770eb31380b3ae5de03487e89a1d3c42fad8aac486a06e1af6b3478ec0d148c0c8566c404537291b" :: Text)) + , ("threshold", tLit $ LInteger 2) + ] + res <- runExceptT $ evalHyperlaneCommand obj' + + case res of + Left err -> assertEqual "Verification should fail" "Verification failed" err + Right _ -> assertFailure "Should fail"