Skip to content

Commit

Permalink
Port hyperlane validator announcement verifier tests
Browse files Browse the repository at this point in the history
From Chainweb.Test.Pact4.VerifierPluginTest.Transaction

Change-Id: Id0000000b79f525cc85a25ebc52e7553a381ac2a
  • Loading branch information
edmundnoble committed Jan 10, 2025
1 parent ba71162 commit f471451
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions test/unit/Chainweb/Test/Pact5/RemotePactTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ import Pact.Core.Guards (Guard(GKeySetRef), KeySetName (..))
import Pact.Core.Hash qualified as Pact5
import Pact.Core.Names
import Pact.Core.PactValue
import Pact.Core.Signer (SigCapability(SigCapability))
import Pact.Core.SPV
import Pact.Core.Verifiers
import Pact.JSON.Encode qualified as J
import Pact.Types.Command qualified as Pact4
import Pact.Types.API qualified as Pact4
Expand Down Expand Up @@ -143,6 +145,8 @@ tests rdb = withResource' (evaluate httpManager >> evaluate cert) $ \_ ->
, testCaseSteps "pollingMetadataTest" (pollingMetadataTest rdb)
, testCaseSteps "allocationTest" (allocationTest rdb)
, testCaseSteps "webAuthnSignatureTest" (webAuthnSignatureTest rdb)
, testCaseSteps "hyperlaneValidatorAnnouncementTest" (hyperlaneValidatorAnnouncementTest rdb)

, localTests rdb
]

Expand Down Expand Up @@ -903,6 +907,142 @@ pollingMetadataTest baseRdb _step = runResourceT $ do
]
]

hyperlaneValidatorAnnouncementTest :: RocksDb -> Step -> IO ()
hyperlaneValidatorAnnouncementTest baseRdb step = runResourceT $ do
let v = pact5InstantCpmTestVersion petersonChainGraph
fx <- mkFixture v baseRdb
cid <- mkChainId v maxBound 0
liftIO $ do
let verifierName = "hyperlane_v3_announcement"

step "deploy"

deploy <- buildTextCmd v
$ set cbGasLimit (GasLimit (Gas 100000))
$ set cbRPC (mkExec' $ mconcat
[ "(namespace 'free)"
, "(module m G"
, "(defcap G () true)"
, "(defcap K (location:string signer:string mailbox:string) (enforce-verifier '" <> verifierName <> "))"
, "(defun x () (with-capability (K \"storagelocation\" \"0x6c414e7a15088023e28af44ad0e1d593671e4b15\" \"kb-mailbox\") 1)))"
])
$ defaultCmd cid
send fx v cid [deploy]
advanceAllChains_ fx
poll fx v cid [cmdToRequestKey deploy]
>>= P.list [P.match _Just successfulTx]

step "use successfully"
let cap =
CapToken (QualifiedName "K" (ModuleName "m" (Just (NamespaceName "free"))) )
[PString "storagelocation", PString "0x6c414e7a15088023e28af44ad0e1d593671e4b15", PString "kb-mailbox"]
use <- buildTextCmd v
$ set cbRPC (mkExec' "(free.m.x)")
$ set cbVerifiers
[Verifier
(VerifierName verifierName)
(ParsedVerifierProof $
PList $ V.fromList
[ PString "storagelocation"
-- TODO: generate instead of using the precomputed value
, PString "U7oftiGhn7rpWJydP6t0FKStdcRd223a8uSTqKjs8K8nJW7U84tzBOgPZTtGKnncwiu8l1185vB38c7-Ov7avBw"
, PString "kb-mailbox"
]
)
[SigCapability cap]]
$ set cbGasLimit (GasLimit (Gas 100000))
$ defaultCmd cid
send fx v cid [use]
advanceAllChains_ fx
poll fx v cid [cmdToRequestKey use]
>>= P.list
[P.match _Just ? P.checkAll
[ successfulTx
, P.fun _crGas ? P.equals (Gas 16342)
]
]

step "use with bad signature"
useBadSignature <- buildTextCmd v
$ set cbRPC (mkExec' "(free.m.x)")
$ set cbVerifiers
[Verifier
(VerifierName verifierName)
(ParsedVerifierProof $
PList $ V.fromList
[ PString "storagelocation"
-- bad signature (same as from the previous test but the different first symbol)
, PString "Q7oftiGhn7rpWJydP6t0FKStdcRd223a8uSTqKjs8K8nJW7U84tzBOgPZTtGKnncwiu8l1185vB38c7-Ov7avBw"
, PString "kb-mailbox"
]
)
[SigCapability cap]]
$ set cbGasLimit (GasLimit (Gas 100000))
$ defaultCmd cid
send fx v cid [useBadSignature]
advanceAllChains_ fx
poll fx v cid [cmdToRequestKey useBadSignature]
>>= P.list
[ P.match _Just ? P.checkAll
[ P.fun _crResult ? P.match (_PactResultErr . _PEPact5Error) ? P.checkAll
[ P.fun _peCode ? P.equals (ErrorCode 1407374883553280)
, P.fun _peMsg ? P.equals "Failed to recover the address from the signature"
]
, P.fun _crGas ? P.equals (Gas 100000)
]
]

step "deploy with different signer"
deployDifferentSigner <- buildTextCmd v
$ set cbGasLimit (GasLimit (Gas 100000))
$ set cbRPC (mkExec' $ mconcat
[ "(namespace 'free)"
, "(module m G"
, "(defcap G () true)"
, "(defcap K (location:string signer:string mailbox:string) (enforce-verifier '" <> verifierName <> "))"
, "(defun x () (with-capability (K \"storagelocation\" \"0x5c414e7a15088023e28af44ad0e1d593671e4b15\" \"kb-mailbox\") 1)))"
])
$ defaultCmd cid
send fx v cid [deployDifferentSigner]
advanceAllChains_ fx
poll fx v cid [cmdToRequestKey deployDifferentSigner]
>>= P.list [P.match _Just successfulTx]

let capWrongSigner =
CapToken (QualifiedName "K" (ModuleName "m" (Just (NamespaceName "free"))) )
[PString "storagelocation", PString "0x5c414e7a15088023e28af44ad0e1d593671e4b15", PString "kb-mailbox"]
-- bad signer (same as from the previous test but the different first symbol)

step "use with wrong signer"
useWrongSigner <- buildTextCmd v
$ set cbRPC (mkExec' "(free.m.x)")
$ set cbVerifiers
[Verifier
(VerifierName verifierName)
(ParsedVerifierProof $
PList $ V.fromList
[ PString "storagelocation"
-- TODO: generate instead of using the precomputed value
, PString "U7oftiGhn7rpWJydP6t0FKStdcRd223a8uSTqKjs8K8nJW7U84tzBOgPZTtGKnncwiu8l1185vB38c7-Ov7avBw"
, PString "kb-mailbox"
]
)
[SigCapability capWrongSigner]]
$ set cbGasLimit (GasLimit (Gas 100000))
$ defaultCmd cid
send fx v cid [useWrongSigner]
advanceAllChains_ fx
poll fx v cid [cmdToRequestKey useWrongSigner]
>>= P.list
[ P.match _Just ? P.checkAll
[ P.fun _crResult ? P.match (_PactResultErr . _PEPact5Error) ? P.checkAll
[ P.fun _peCode ? P.equals (ErrorCode 1407374883553280)
, P.fun _peMsg ? P.equals "Incorrect signer. Expected: PLiteral (LString {_lString = \"0x6c414e7a15088023e28af44ad0e1d593671e4b15\"}) but got PLiteral (LString {_lString = \"0x5c414e7a15088023e28af44ad0e1d593671e4b15\"})"
]
, P.fun _crGas ? P.equals (Gas 100000)
]
]

----------------------------------------------------

data Fixture = Fixture
Expand Down

0 comments on commit f471451

Please sign in to comment.