Skip to content

Commit

Permalink
add test for local only
Browse files Browse the repository at this point in the history
Change-Id: I182891ef2e2250cdf07fa0cfdaf9701161f50156
  • Loading branch information
chessai committed Jul 26, 2024
1 parent 837ee50 commit ac3cf8d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/Chainweb/Test/Pact5/TransactionExecTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ tests baseRdb = testGroup "Pact5 TransactionExecTest"
, testCase "applyCmd coin.transfer" (applyCmdCoinTransfer baseRdb)
, testCase "applyCoinbase spec" (applyCoinbaseSpec baseRdb)
, testCase "test coin upgrade" (testCoinUpgrade baseRdb)
, testCase "test local only fails outside of local" (testLocalOnlyFailsOutsideOfLocal baseRdb)
]


Expand Down Expand Up @@ -848,6 +849,46 @@ testCoinUpgrade baseRdb = runResourceT $ do
pure ()
pure ()

testLocalOnlyFailsOutsideOfLocal :: RocksDb -> IO ()
testLocalOnlyFailsOutsideOfLocal baseRdb = runResourceT $ do
sql <- withTempSQLiteResource
liftIO $ do
cp <- initCheckpointer v cid sql
tdb <- mkTestBlockDb v =<< testRocksDb "testLocalOnlyFailsOutsideOfLocal" baseRdb
bhdb <- getWebBlockHeaderDb (_bdbWebBlockHeaderDb tdb) cid
T2 () _finalPactState <- withPactService v cid stdoutDummyLogger Nothing bhdb (_bdbPayloadDb tdb) sql testPactServiceConfig $ do
initialPayloadState v cid
(throwIfNoHistory =<<) $ readFrom (Just $ ParentHeader (gh v cid)) $ do
db <- view psBlockDbEnv
liftIO $ do
pactDb <- assertDynamicPact5Db (_cpPactDbEnv db)

let txCtx = TxContext {_tcParentHeader = ParentHeader (gh v cid), _tcMiner = noMiner}

let testLocalOnly txt = do
cmd <- buildCwCmd "nonce" v defaultCmd
{ _cbRPC = mkExec' txt
, _cbSigners =
[ mkEd25519Signer' sender00 [CapToken (QualifiedName "GAS" (ModuleName "coin" Nothing)) []]
]
, _cbSender = "sender00"
, _cbChainId = cid
, _cbGasPrice = GasPrice 2
, _cbGasLimit = GasLimit (Gas 200_000)
}
commandResult <- applyCmd stdoutDummyLogger Nothing pactDb txCtx noSPVSupport (_payloadObj <$> cmd) (Gas 1)
case _crResult commandResult of
PactResultErr (TxPactError (PEExecutionError (OperationIsLocalOnly _) _ _)) -> do
return ()
r -> do
assertFailure $ "Expected OperationIsLocalOnly error, but got: " ++ show r

testLocalOnly "(at 'hash (describe-module 'coin))"
--testLocalOnly "(txids \"coin.coin-table\" 0)"

pure ()
pure ()

cid = unsafeChainId 0
gh = genesisBlockHeader

Expand Down

0 comments on commit ac3cf8d

Please sign in to comment.