From 50f158b544432ddec647b871eb73b9bbf70b5bf2 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Fri, 9 Feb 2024 17:49:42 +0100 Subject: [PATCH 1/8] Support querying contract modules. --- concordium-base | 2 +- .../src/Concordium/Scheduler.hs | 81 +++++++++++++++++++ .../Scheduler/WasmIntegration/V1.hs | 10 +++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/concordium-base b/concordium-base index ff9f17ab70..5fedf0f4e4 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit ff9f17ab704a3fe2b24ab11ae5e7993b8a2cc720 +Subproject commit 5fedf0f4e4576dbf0ded68c1c559fc20d6d6be17 diff --git a/concordium-consensus/src/Concordium/Scheduler.hs b/concordium-consensus/src/Concordium/Scheduler.hs index 34cc653cfd..296127e199 100644 --- a/concordium-consensus/src/Concordium/Scheduler.hs +++ b/concordium-consensus/src/Concordium/Scheduler.hs @@ -1563,6 +1563,87 @@ handleContractUpdateV1 originAddr istance checkAndGetSender transferAmount recei WasmV1.SignatureCheckFailed Nothing ) + WasmV1.QueryContractModuleReference{..} -> do + -- Charge for querying the balance of a contract. + tickEnergy Cost.contractInstanceQueryContractBalanceCost + -- Lookup contract balances. + maybeInstanceInfo <- getCurrentContractInstance imqcmrAddress + case maybeInstanceInfo of + Nothing -> + -- The Wasm execution does not reset contract events for queries, hence we do not have to + -- add them here via an interrupt. They will be retained until the next interrupt. + go events + =<< runInterpreter + ( return + . WasmV1.resumeReceiveFun + rrdInterruptedConfig + rrdCurrentState + False + entryBalance + (WasmV1.Error $ WasmV1.EnvFailure $ WasmV1.MissingContract imqcmrAddress) + Nothing + ) + Just instanceInfo -> do + let modRef = case instanceInfo of + InstanceInfoV0 ii -> GSWasm.miModuleRef $ instanceModuleInterface $ iiParameters ii + InstanceInfoV1 ii -> GSWasm.miModuleRef $ instanceModuleInterface $ iiParameters ii + -- Construct the return value. + let returnValue = WasmV1.byteStringToReturnValue $ S.encode modRef + -- The Wasm execution does not reset contract events for queries, hence we do not have to + -- add them here via an interrupt. They will be retained until the next interrupt. + go events + =<< runInterpreter + ( return + . WasmV1.resumeReceiveFun + rrdInterruptedConfig + rrdCurrentState + False + entryBalance + WasmV1.Success + (Just returnValue) + ) + WasmV1.QueryContractName{..} -> do + -- Charge for querying the balance of a contract. + tickEnergy Cost.contractInstanceQueryContractBalanceCost + -- Lookup contract balances. + maybeInstanceInfo <- getCurrentContractInstance imqcnAddress + case maybeInstanceInfo of + Nothing -> + -- The Wasm execution does not reset contract events for queries, hence we do not have to + -- add them here via an interrupt. They will be retained until the next interrupt. + go events + =<< runInterpreter + ( return + . WasmV1.resumeReceiveFun + rrdInterruptedConfig + rrdCurrentState + False + entryBalance + (WasmV1.Error $ WasmV1.EnvFailure $ WasmV1.MissingContract imqcnAddress) + Nothing + ) + Just instanceInfo -> do + let name = case instanceInfo of + InstanceInfoV0 ii -> instanceInitName $ iiParameters ii + InstanceInfoV1 ii -> instanceInitName $ iiParameters ii + -- Construct the return value. + let returnValue = + WasmV1.byteStringToReturnValue $ + GSWasm.initNameBytes name + -- The Wasm execution does not reset contract events for queries, hence we do not have to + -- add them here via an interrupt. They will be retained until the next interrupt. + go events + =<< runInterpreter + ( return + . WasmV1.resumeReceiveFun + rrdInterruptedConfig + rrdCurrentState + False + entryBalance + WasmV1.Success + (Just returnValue) + ) + -- start contract execution. -- transfer the amount from the sender to the contract at the start. This is so that the contract may immediately use it -- for, e.g., forwarding. diff --git a/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs b/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs index b3082830c7..68f4f3cb38 100644 --- a/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs +++ b/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs @@ -424,6 +424,14 @@ data InvokeMethod QueryAccountKeys { imqakAddress :: !AccountAddress } + | -- | Query the module reference of a contract. + QueryContractModuleReference + { imqcmrAddress :: !ContractAddress + } + | -- | Query the constructor name of a contract. + QueryContractName + { imqcnAddress :: !ContractAddress + } getInvokeMethod :: Get InvokeMethod getInvokeMethod = @@ -436,6 +444,8 @@ getInvokeMethod = 5 -> return QueryExchangeRates 6 -> CheckAccountSignature <$> get <*> getByteStringLen 7 -> QueryAccountKeys <$> get + 8 -> QueryContractModuleReference <$> get + 9 -> QueryContractName <$> get n -> fail $ "Unsupported invoke method tag: " ++ show n -- | Data return from the contract in case of successful initialization. From 39213e143acd9a745ef2bdc4f76ab0cfaf212a7b Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Mon, 12 Feb 2024 15:28:44 +0100 Subject: [PATCH 2/8] Fix call to receive function to pass in whether module inspection endpoints are available. --- concordium-base | 2 +- concordium-consensus/src/Concordium/Scheduler.hs | 3 ++- .../src/Concordium/Scheduler/WasmIntegration/V1.hs | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/concordium-base b/concordium-base index 5fedf0f4e4..e3081f7014 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit 5fedf0f4e4576dbf0ded68c1c559fc20d6d6be17 +Subproject commit e3081f7014e383d1476edd12914a12926f4689ba diff --git a/concordium-consensus/src/Concordium/Scheduler.hs b/concordium-consensus/src/Concordium/Scheduler.hs index 296127e199..8623dcd2fb 100644 --- a/concordium-consensus/src/Concordium/Scheduler.hs +++ b/concordium-consensus/src/Concordium/Scheduler.hs @@ -1659,7 +1659,8 @@ handleContractUpdateV1 originAddr istance checkAndGetSender transferAmount recei -- Check whether the number of logs and the size of return values are limited in the current protocol version. rcLimitLogsAndRvs = Wasm.limitLogsAndReturnValues $ protocolVersion @(MPV m), rcFixRollbacks = demoteProtocolVersion (protocolVersion @(MPV m)) >= P6, - rcSupportAccountSignatureChecks = supportsAccountSignatureChecks $ protocolVersion @(MPV m) + rcSupportAccountSignatureChecks = supportsAccountSignatureChecks $ protocolVersion @(MPV m), + rcSupportContractInspectionQueries = supportsContractInspectionQueries $ protocolVersion @(MPV m) } transferAccountSync :: AccountAddress -> -- The target account address. diff --git a/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs b/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs index 68f4f3cb38..8783f496e8 100644 --- a/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs +++ b/concordium-consensus/src/Concordium/Scheduler/WasmIntegration/V1.hs @@ -287,6 +287,8 @@ foreign import ccall "call_receive_v1" Word8 -> -- | Non-zero to enable support for account keys query and signature checks. Word8 -> + -- | Non-zero to enable support for contract module reference and name queries. + Word8 -> -- | New state, logs, and actions, if applicable, or null, signalling out-of-energy. IO (Ptr Word8) @@ -678,7 +680,9 @@ data RuntimeConfig = RuntimeConfig rcLimitLogsAndRvs :: Bool, -- | Whether to support account key queries and account signature checks. -- Supported in P6 onward. - rcSupportAccountSignatureChecks :: Bool + rcSupportAccountSignatureChecks :: Bool, + -- | Whether to support querying smart contract module reference and name. + rcSupportContractInspectionQueries :: Bool } -- | Apply a receive function which is assumed to be part of the given module. @@ -738,6 +742,7 @@ applyReceiveFun miface cm receiveCtx rName useFallback param amnt initialState R stateWrittenToPtr (if rcSupportChainQueries then 1 else 0) (if rcSupportAccountSignatureChecks then 1 else 0) + (if rcSupportContractInspectionQueries then 1 else 0) if outPtr == nullPtr then return (Just (Left Trap, 0)) -- this case should not happen else do From 6f5b3c42ac48a282684aed57d8f44d4e6e843d35 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Mon, 12 Feb 2024 16:50:33 +0100 Subject: [PATCH 3/8] Separate costs for new invoke operations --- concordium-base | 2 +- concordium-consensus/src/Concordium/Scheduler.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/concordium-base b/concordium-base index e3081f7014..85a8e4318e 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit e3081f7014e383d1476edd12914a12926f4689ba +Subproject commit 85a8e4318e462441ad518e66d1e36b24b6eb00f8 diff --git a/concordium-consensus/src/Concordium/Scheduler.hs b/concordium-consensus/src/Concordium/Scheduler.hs index 8623dcd2fb..83549979d7 100644 --- a/concordium-consensus/src/Concordium/Scheduler.hs +++ b/concordium-consensus/src/Concordium/Scheduler.hs @@ -1565,7 +1565,7 @@ handleContractUpdateV1 originAddr istance checkAndGetSender transferAmount recei ) WasmV1.QueryContractModuleReference{..} -> do -- Charge for querying the balance of a contract. - tickEnergy Cost.contractInstanceQueryContractBalanceCost + tickEnergy Cost.contractInstanceQueryContractModuleReferenceCost -- Lookup contract balances. maybeInstanceInfo <- getCurrentContractInstance imqcmrAddress case maybeInstanceInfo of @@ -1604,7 +1604,7 @@ handleContractUpdateV1 originAddr istance checkAndGetSender transferAmount recei ) WasmV1.QueryContractName{..} -> do -- Charge for querying the balance of a contract. - tickEnergy Cost.contractInstanceQueryContractBalanceCost + tickEnergy Cost.contractInstanceQueryContractNameCost -- Lookup contract balances. maybeInstanceInfo <- getCurrentContractInstance imqcnAddress case maybeInstanceInfo of From b74fd49755811e573dbd941adbf1be4f7d54e3a3 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Wed, 14 Feb 2024 17:50:47 +0100 Subject: [PATCH 4/8] Add scheduler test for contract inspection queries. --- concordium-base | 2 +- .../tests/scheduler/SchedulerTests/Helpers.hs | 1 + .../SmartContracts/V1/ContractInspection.hs | 225 ++++++++++++++++++ concordium-consensus/tests/scheduler/Spec.hs | 2 + 4 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs diff --git a/concordium-base b/concordium-base index 85a8e4318e..de5498201b 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit 85a8e4318e462441ad518e66d1e36b24b6eb00f8 +Subproject commit de5498201b387d7e902ff373c463b3fc7fe1ff5c diff --git a/concordium-consensus/tests/scheduler/SchedulerTests/Helpers.hs b/concordium-consensus/tests/scheduler/SchedulerTests/Helpers.hs index 8e7dca1f7a..99be70727f 100644 --- a/concordium-consensus/tests/scheduler/SchedulerTests/Helpers.hs +++ b/concordium-consensus/tests/scheduler/SchedulerTests/Helpers.hs @@ -229,6 +229,7 @@ data SchedulerResult = SchedulerResult -- | The total execution energy of the block. srUsedEnergy :: Types.Energy } + deriving (Show) -- | Run the scheduler on transactions in a test environment. runScheduler :: diff --git a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs new file mode 100644 index 0000000000..0c32d16980 --- /dev/null +++ b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs @@ -0,0 +1,225 @@ +{-# LANGUAGE MonoLocalBinds #-} +{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} + +-- | This module tests the contract inspection functionality of the invoke host function. +module SchedulerTests.SmartContracts.V1.ContractInspection where + +import Control.Monad +import qualified Data.ByteString.Short as BSS +import Data.Serialize (Serialize (put), putByteString, putWord64le, runPut) +import Lens.Micro.Platform +import Test.Hspec + +import qualified Concordium.Crypto.SignatureScheme as SigScheme +import Concordium.GlobalState.DummyData +import qualified Concordium.GlobalState.Persistent.Account as BS +import Concordium.GlobalState.Persistent.BlobStore +import qualified Concordium.GlobalState.Persistent.BlockState as BS +import qualified Concordium.ID.Types as ID +import Concordium.Scheduler.DummyData +import Concordium.Scheduler.Runner +import qualified Concordium.Scheduler.Types as Types +import Concordium.Types.Accounts +import Concordium.Types.DummyData +import Concordium.Wasm +import qualified Concordium.Wasm as Wasm +import SchedulerTests.Helpers () +import qualified SchedulerTests.Helpers as Helpers +import System.IO.Unsafe (unsafePerformIO) +import Test.HUnit + +initialBlockState :: + (Types.IsProtocolVersion pv) => + Helpers.PersistentBSM pv (BS.HashedPersistentBlockState pv) +initialBlockState = + Helpers.createTestBlockStateWithAccountsM + [ Helpers.makeTestAccountFromSeed 100_000_000 0, + Helpers.makeTestAccountFromSeed 100_000_000 1 + ] + +accountAddress0 :: ID.AccountAddress +accountAddress0 = Helpers.accountAddressFromSeed 0 + +accountAddress1 :: ID.AccountAddress +accountAddress1 = Helpers.accountAddressFromSeed 1 + +keyPair0 :: SigScheme.KeyPair +keyPair0 = Helpers.keyPairFromSeed 0 + +keyPair1 :: SigScheme.KeyPair +keyPair1 = Helpers.keyPairFromSeed 1 + +-- | Source file for contracts that invoke the contract inspection queries. +srcQueriesContractInspection :: FilePath +srcQueriesContractInspection = "../concordium-base/smart-contracts/testdata/contracts/v1/queries-contract-inspection.wasm" + +-- | Another smart contract module that is used for deploying a contract that has a different +-- module reference. +srcQueriesAccountBalance :: FilePath +srcQueriesAccountBalance = "../concordium-base/smart-contracts/testdata/contracts/v1/queries-account-balance.wasm" + +-- | Compute the module reference of a module at a given source path. +modRefOf :: FilePath -> IO Types.ModuleRef +modRefOf modSrc = do + modl <- Helpers.readV1ModuleFile modSrc + return $! case modl of + WasmModuleV0 m -> getModuleRef m + WasmModuleV1 m -> getModuleRef m + +-- | Module reference of 'srcQueriesContractInspection'. +modRefQueriesContractInspection :: Types.ModuleRef +{-# NOINLINE modRefQueriesContractInspection #-} +modRefQueriesContractInspection = unsafePerformIO $ modRefOf srcQueriesContractInspection + +-- | Module reference of 'srcQueriesAccountBalance'. +modRefQueriesAccountBalance :: Types.ModuleRef +{-# NOINLINE modRefQueriesAccountBalance #-} +modRefQueriesAccountBalance = unsafePerformIO $ modRefOf srcQueriesAccountBalance + +-- | This test deploys three different smart contracts, from two different modules. +-- One of these contracts <0,0> has a function for checking if the module reference matches an +-- expected value. Another <2,0> has a function for checking if the contract name matches an +-- expected value. Both functions are invoked for each instance, and for non-existant contract +-- addresses, ensuring the values are as expected. +-- +-- The entrypoints are designed to succeed in the case of a match, fail with code -1 if there is +-- a mismatch, and fail with code -2 if the contract address does not exist. If the protocol +-- version does not support the contract inspection functionality, then the call should fail with +-- a runtime exception. +testModuleRefAndName :: forall pv. (Types.IsProtocolVersion pv) => Types.SProtocolVersion pv -> [Char] -> SpecWith () +testModuleRefAndName spv pvString + | Types.supportsV1Contracts spv = + specify (pvString ++ ": inspect contract module reference and contract name") $ + Helpers.runSchedulerTestAssertIntermediateStates + @pv + Helpers.defaultTestConfig + initialBlockState + transactionsAndAssertions + | otherwise = return () + where + transactionsAndAssertions :: [Helpers.TransactionAndAssertion pv] + transactionsAndAssertions = + [ deployModHelper 1 srcQueriesContractInspection, + deployModHelper 2 srcQueriesAccountBalance, + initContractHelper 3 srcQueriesContractInspection "init_contract", + initContractHelper 4 srcQueriesAccountBalance "init_contract", + initContractHelper 5 srcQueriesContractInspection "init_contract2", + checkModRefHelper 6 (Types.ContractAddress 0 0) modRefQueriesContractInspection Nothing, + checkModRefHelper 7 (Types.ContractAddress 1 0) modRefQueriesContractInspection (Just (-1)), + checkModRefHelper 8 (Types.ContractAddress 2 0) modRefQueriesContractInspection Nothing, + checkModRefHelper 9 (Types.ContractAddress 3 0) modRefQueriesContractInspection (Just (-2)), + checkModRefHelper 10 (Types.ContractAddress 0 1) modRefQueriesContractInspection (Just (-2)), + checkModRefHelper 11 (Types.ContractAddress 1 0) modRefQueriesAccountBalance Nothing, + checkNameHelper 12 (Types.ContractAddress 0 0) "init_contract" Nothing, + checkNameHelper 13 (Types.ContractAddress 1 0) "init_contract" Nothing, + checkNameHelper 14 (Types.ContractAddress 2 0) "init_contract" (Just (-1)), + checkNameHelper 15 (Types.ContractAddress 2 0) "init_contract2" Nothing, + checkNameHelper 16 (Types.ContractAddress 3 0) "init_contract" (Just (-2)), + checkNameHelper 17 (Types.ContractAddress 0 0) "init_contract2" (Just (-1)), + checkNameHelper 18 (Types.ContractAddress 0 1) "init_contract2" (Just (-2)) + ] + deployModHelper nce src = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = DeployModule V1 src, + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ do + Helpers.assertSuccess result + Helpers.assertUsedEnergyDeploymentV1 src result + } + initContractHelper nce src constructor = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = InitContract 0 V1 src constructor "", + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ do + Helpers.assertSuccess result + Helpers.assertUsedEnergyInitialization + src + (InitName constructor) + (Parameter mempty) + Nothing + result + } + checkModRefHelper nce scAddr expectModRef mreject = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = + Update + 0 + (Types.ContractAddress 0 0) + "contract.check_module_reference" + (params scAddr expectModRef), + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ + if Types.supportsContractInspectionQueries spv + then case mreject of + Nothing -> Helpers.assertSuccess result + Just reject -> + Helpers.assertRejectWhere + ( \case + Types.RejectedReceive{..} + | rejectReason == reject -> return () + _ -> assertFailure "Rejected for incorrect reason" + ) + result + else Helpers.assertRejectWithReason Types.RuntimeFailure result + } + where + params (Types.ContractAddress i si) modRef = BSS.toShort $ runPut $ do + putWord64le $ fromIntegral i + putWord64le $ fromIntegral si + put modRef + checkNameHelper nce scAddr expectName mreject = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = + Update + 0 + (Types.ContractAddress 2 0) + "contract2.check_name" + (params scAddr expectName), + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ + if Types.supportsContractInspectionQueries spv + then case mreject of + Nothing -> Helpers.assertSuccess result + Just reject -> + Helpers.assertRejectWhere + ( \case + Types.RejectedReceive{..} + | rejectReason == reject -> return () + _ -> assertFailure "Rejected for incorrect reason" + ) + result + else Helpers.assertRejectWithReason Types.RuntimeFailure result + } + where + params (Types.ContractAddress i si) name = BSS.toShort $ runPut $ do + putWord64le $ fromIntegral i + putWord64le $ fromIntegral si + putByteString name + +tests :: Spec +tests = describe "V1: Contract inspection queries" . sequence_ $ + Helpers.forEveryProtocolVersion $ \spv pvString -> do + testModuleRefAndName spv pvString diff --git a/concordium-consensus/tests/scheduler/Spec.hs b/concordium-consensus/tests/scheduler/Spec.hs index 268f5c788b..0789e87bee 100644 --- a/concordium-consensus/tests/scheduler/Spec.hs +++ b/concordium-consensus/tests/scheduler/Spec.hs @@ -33,6 +33,7 @@ import qualified SchedulerTests.SmartContracts.Invoke (tests) import qualified SchedulerTests.SmartContracts.V1.AccountSignatureChecks (tests) import qualified SchedulerTests.SmartContracts.V1.AllNewHostFunctions (tests) import qualified SchedulerTests.SmartContracts.V1.Checkpointing (tests) +import qualified SchedulerTests.SmartContracts.V1.ContractInspection (tests) import qualified SchedulerTests.SmartContracts.V1.Counter (tests) import qualified SchedulerTests.SmartContracts.V1.CrossMessaging (tests) import qualified SchedulerTests.SmartContracts.V1.CustomSectionSize (tests) @@ -103,3 +104,4 @@ main = hspec $ do SchedulerTests.SmartContracts.V1.P6WasmFeatures.tests SchedulerTests.SmartContracts.V1.CustomSectionSize.tests SchedulerTests.SmartContracts.V1.AccountSignatureChecks.tests + SchedulerTests.SmartContracts.V1.ContractInspection.tests From ad1d34660ef01582f9b582dab9bbdbf52e6c4ec0 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Mon, 19 Feb 2024 15:15:50 +0100 Subject: [PATCH 5/8] Test interaction of upgrading and inspecting smart contract module reference. --- concordium-base | 2 +- .../SmartContracts/V1/ContractInspection.hs | 149 ++++++++++++++++-- 2 files changed, 133 insertions(+), 18 deletions(-) diff --git a/concordium-base b/concordium-base index de5498201b..5a964c8fc7 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit de5498201b387d7e902ff373c463b3fc7fe1ff5c +Subproject commit 5a964c8fc73ec5d872bf82eb95b5d26808a691cc diff --git a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs index 0c32d16980..99369c9070 100644 --- a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs +++ b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs @@ -7,25 +7,17 @@ -- | This module tests the contract inspection functionality of the invoke host function. module SchedulerTests.SmartContracts.V1.ContractInspection where -import Control.Monad import qualified Data.ByteString.Short as BSS -import Data.Serialize (Serialize (put), putByteString, putWord64le, runPut) -import Lens.Micro.Platform +import Data.Serialize (Serialize (put), encode, putByteString, putWord64le, runPut) import Test.Hspec import qualified Concordium.Crypto.SignatureScheme as SigScheme -import Concordium.GlobalState.DummyData -import qualified Concordium.GlobalState.Persistent.Account as BS -import Concordium.GlobalState.Persistent.BlobStore import qualified Concordium.GlobalState.Persistent.BlockState as BS import qualified Concordium.ID.Types as ID import Concordium.Scheduler.DummyData import Concordium.Scheduler.Runner import qualified Concordium.Scheduler.Types as Types -import Concordium.Types.Accounts -import Concordium.Types.DummyData import Concordium.Wasm -import qualified Concordium.Wasm as Wasm import SchedulerTests.Helpers () import qualified SchedulerTests.Helpers as Helpers import System.IO.Unsafe (unsafePerformIO) @@ -36,22 +28,15 @@ initialBlockState :: Helpers.PersistentBSM pv (BS.HashedPersistentBlockState pv) initialBlockState = Helpers.createTestBlockStateWithAccountsM - [ Helpers.makeTestAccountFromSeed 100_000_000 0, - Helpers.makeTestAccountFromSeed 100_000_000 1 + [ Helpers.makeTestAccountFromSeed 100_000_000 0 ] accountAddress0 :: ID.AccountAddress accountAddress0 = Helpers.accountAddressFromSeed 0 -accountAddress1 :: ID.AccountAddress -accountAddress1 = Helpers.accountAddressFromSeed 1 - keyPair0 :: SigScheme.KeyPair keyPair0 = Helpers.keyPairFromSeed 0 -keyPair1 :: SigScheme.KeyPair -keyPair1 = Helpers.keyPairFromSeed 1 - -- | Source file for contracts that invoke the contract inspection queries. srcQueriesContractInspection :: FilePath srcQueriesContractInspection = "../concordium-base/smart-contracts/testdata/contracts/v1/queries-contract-inspection.wasm" @@ -219,7 +204,137 @@ testModuleRefAndName spv pvString putWord64le $ fromIntegral si putByteString name +-- | First source file for contract upgrade and query module reference interaction test. +srcUpgrade0 :: FilePath +srcUpgrade0 = "../concordium-base/smart-contracts/testdata/contracts/v1/upgrading-inspect-module0.wasm" + +-- | Second source file for contract upgrade and query module reference interaction test. +srcUpgrade1 :: FilePath +srcUpgrade1 = "../concordium-base/smart-contracts/testdata/contracts/v1/upgrading-inspect-module1.wasm" + +-- | Module reference of 'srcUpgrade0'. +modUpgrade0 :: Types.ModuleRef +{-# NOINLINE modUpgrade0 #-} +modUpgrade0 = unsafePerformIO $ modRefOf srcUpgrade0 + +-- | Module reference of 'srcUpgrade1'. +modUpgrade1 :: Types.ModuleRef +{-# NOINLINE modUpgrade1 #-} +modUpgrade1 = unsafePerformIO $ modRefOf srcUpgrade1 + +testUpgradeModuleRef :: forall pv. (Types.IsProtocolVersion pv) => Types.SProtocolVersion pv -> [Char] -> SpecWith () +testUpgradeModuleRef spv pvString + | Types.supportsV1Contracts spv && Types.supportsUpgradableContracts spv = + specify (pvString ++ ": upgrade contract and inspect module reference") $ + Helpers.runSchedulerTestAssertIntermediateStates + @pv + Helpers.defaultTestConfig + initialBlockState + transactionsAndAssertions + | otherwise = return () + where + addr0 = Types.ContractAddress 0 0 + transactionsAndAssertions :: [Helpers.TransactionAndAssertion pv] + transactionsAndAssertions = + [ deployModHelper 1 srcUpgrade0, + deployModHelper 2 srcUpgrade1, + initContractHelper 3 srcUpgrade0 "init_contract", + checkModRefHelper 4 addr0 modUpgrade0 Nothing, + checkModRefHelper 5 addr0 modUpgrade1 (Just (-1)), + upgradeHelper 6 addr0 modUpgrade1 Nothing, + checkModRefHelper 7 addr0 modUpgrade0 (Just (-1)), + checkModRefHelper 8 addr0 modUpgrade1 Nothing + ] + deployModHelper nce src = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = DeployModule V1 src, + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ do + Helpers.assertSuccess result + Helpers.assertUsedEnergyDeploymentV1 src result + } + initContractHelper nce src constructor = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = InitContract 0 V1 src constructor "", + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ do + Helpers.assertSuccess result + Helpers.assertUsedEnergyInitialization + src + (InitName constructor) + (Parameter mempty) + Nothing + result + } + checkModRefHelper nce scAddr expectModRef mreject = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = + Update + 0 + (Types.ContractAddress 0 0) + "contract.check_module_reference" + (params scAddr expectModRef), + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ + if Types.supportsContractInspectionQueries spv + then case mreject of + Nothing -> Helpers.assertSuccess result + Just reject -> + Helpers.assertRejectWhere + ( \case + Types.RejectedReceive{..} + | rejectReason == reject -> return () + _ -> assertFailure "Rejected for incorrect reason" + ) + result + else Helpers.assertRejectWithReason Types.RuntimeFailure result + } + where + params (Types.ContractAddress i si) modRef = BSS.toShort $ runPut $ do + putWord64le $ fromIntegral i + putWord64le $ fromIntegral si + put modRef + upgradeHelper nce scAddr toModRef mreject = + Helpers.TransactionAndAssertion + { taaTransaction = + TJSON + { payload = Update 0 scAddr "contract.upgrade" (BSS.toShort $ encode toModRef), + metadata = makeDummyHeader accountAddress0 nce 100_000, + keys = [(0, [(0, keyPair0)])] + }, + taaAssertion = \result _ -> + return $ + if Types.supportsContractInspectionQueries spv + then case mreject of + Nothing -> Helpers.assertSuccess result + Just reject -> + Helpers.assertRejectWhere + ( \case + Types.RejectedReceive{..} + | rejectReason == reject -> return () + _ -> assertFailure "Rejected for incorrect reason" + ) + result + else Helpers.assertRejectWithReason Types.RuntimeFailure result + } + tests :: Spec tests = describe "V1: Contract inspection queries" . sequence_ $ Helpers.forEveryProtocolVersion $ \spv pvString -> do testModuleRefAndName spv pvString + testUpgradeModuleRef spv pvString From 63319d54f5fa44d8c0cfc925997b6aa1d9670959 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Wed, 21 Feb 2024 15:01:47 +0100 Subject: [PATCH 6/8] Update changelog, bump base. --- CHANGELOG.md | 4 ++++ concordium-base | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db73654f95..2bcbd3db9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased changes +- Add support for new `invoke` calls from smart contracts in protocol version 7: + - query the contract module reference for a given contract address + - query the contract name for a given contract address + ## 6.3.0 - Fix a bug where `GetBlockPendingUpdates` fails to report pending updates to the finalization diff --git a/concordium-base b/concordium-base index 5a964c8fc7..d4f13c2bb4 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit 5a964c8fc73ec5d872bf82eb95b5d26808a691cc +Subproject commit d4f13c2bb4e2cc74a31675c5bf38f023b7719c20 From 772e99571769dc92d6c0480c58c5a671a41e829f Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Fri, 23 Feb 2024 13:48:46 +0100 Subject: [PATCH 7/8] Address review comments. --- concordium-base | 2 +- ... InspectModuleReferenceAndContractName.hs} | 147 +++++++++++------- concordium-consensus/tests/scheduler/Spec.hs | 4 +- 3 files changed, 94 insertions(+), 59 deletions(-) rename concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/{ContractInspection.hs => InspectModuleReferenceAndContractName.hs} (68%) diff --git a/concordium-base b/concordium-base index d4f13c2bb4..2ab3a68997 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit d4f13c2bb4e2cc74a31675c5bf38f023b7719c20 +Subproject commit 2ab3a689977c9abf9693d814afaf7d38e2b9448e diff --git a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs similarity index 68% rename from concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs rename to concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs index 99369c9070..9d00216a8d 100644 --- a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/ContractInspection.hs +++ b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs @@ -4,11 +4,12 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} --- | This module tests the contract inspection functionality of the invoke host function. -module SchedulerTests.SmartContracts.V1.ContractInspection where +-- | This module tests the contract inspection functionality of the invoke host function for +-- getting the module reference and contract name of an instance. +module SchedulerTests.SmartContracts.V1.InspectModuleReferenceAndContractName where import qualified Data.ByteString.Short as BSS -import Data.Serialize (Serialize (put), encode, putByteString, putWord64le, runPut) +import Data.Serialize (Serialize (put), encode, putWord64le, runPut) import Test.Hspec import qualified Concordium.Crypto.SignatureScheme as SigScheme @@ -92,19 +93,29 @@ testModuleRefAndName spv pvString initContractHelper 3 srcQueriesContractInspection "init_contract", initContractHelper 4 srcQueriesAccountBalance "init_contract", initContractHelper 5 srcQueriesContractInspection "init_contract2", - checkModRefHelper 6 (Types.ContractAddress 0 0) modRefQueriesContractInspection Nothing, - checkModRefHelper 7 (Types.ContractAddress 1 0) modRefQueriesContractInspection (Just (-1)), - checkModRefHelper 8 (Types.ContractAddress 2 0) modRefQueriesContractInspection Nothing, - checkModRefHelper 9 (Types.ContractAddress 3 0) modRefQueriesContractInspection (Just (-2)), - checkModRefHelper 10 (Types.ContractAddress 0 1) modRefQueriesContractInspection (Just (-2)), - checkModRefHelper 11 (Types.ContractAddress 1 0) modRefQueriesAccountBalance Nothing, - checkNameHelper 12 (Types.ContractAddress 0 0) "init_contract" Nothing, - checkNameHelper 13 (Types.ContractAddress 1 0) "init_contract" Nothing, - checkNameHelper 14 (Types.ContractAddress 2 0) "init_contract" (Just (-1)), - checkNameHelper 15 (Types.ContractAddress 2 0) "init_contract2" Nothing, - checkNameHelper 16 (Types.ContractAddress 3 0) "init_contract" (Just (-2)), - checkNameHelper 17 (Types.ContractAddress 0 0) "init_contract2" (Just (-1)), - checkNameHelper 18 (Types.ContractAddress 0 1) "init_contract2" (Just (-2)) + getModRefHelper 6 (Types.ContractAddress 0 0) (Just modRefQueriesContractInspection), + getModRefHelper 7 (Types.ContractAddress 1 0) (Just modRefQueriesAccountBalance), + getModRefHelper 8 (Types.ContractAddress 2 0) (Just modRefQueriesContractInspection), + getModRefHelper 9 (Types.ContractAddress 3 0) Nothing, + getModRefHelper 10 (Types.ContractAddress 0 1) Nothing, + -- checkModRefHelper 6 (Types.ContractAddress 0 0) modRefQueriesContractInspection Nothing, + -- checkModRefHelper 7 (Types.ContractAddress 1 0) modRefQueriesContractInspection (Just (-1)), + -- checkModRefHelper 8 (Types.ContractAddress 2 0) modRefQueriesContractInspection Nothing, + -- checkModRefHelper 9 (Types.ContractAddress 3 0) modRefQueriesContractInspection (Just (-2)), + -- checkModRefHelper 10 (Types.ContractAddress 0 1) modRefQueriesContractInspection (Just (-2)), + -- checkModRefHelper 11 (Types.ContractAddress 1 0) modRefQueriesAccountBalance Nothing, + getNameHelper 11 (Types.ContractAddress 0 0) (Just "init_contract") 755, + getNameHelper 12 (Types.ContractAddress 1 0) (Just "init_contract") 755, + getNameHelper 13 (Types.ContractAddress 2 0) (Just "init_contract2") 756, + getNameHelper 14 (Types.ContractAddress 3 0) Nothing 742, + getNameHelper 15 (Types.ContractAddress 0 1) Nothing 742 + -- checkNameHelper 12 (Types.ContractAddress 0 0) "init_contract" Nothing, + -- checkNameHelper 13 (Types.ContractAddress 1 0) "init_contract" Nothing, + -- checkNameHelper 14 (Types.ContractAddress 2 0) "init_contract" (Just (-1)), + -- checkNameHelper 15 (Types.ContractAddress 2 0) "init_contract2" Nothing, + -- checkNameHelper 16 (Types.ContractAddress 3 0) "init_contract" (Just (-2)), + -- checkNameHelper 17 (Types.ContractAddress 0 0) "init_contract2" (Just (-1)), + -- checkNameHelper 18 (Types.ContractAddress 0 1) "init_contract2" (Just (-2)) ] deployModHelper nce src = Helpers.TransactionAndAssertion @@ -137,72 +148,96 @@ testModuleRefAndName spv pvString Nothing result } - checkModRefHelper nce scAddr expectModRef mreject = + getModRefHelper :: + Types.Nonce -> + Types.ContractAddress -> + Maybe Types.ModuleRef -> + Helpers.TransactionAndAssertion pv + getModRefHelper nce scAddr mExpectModRef = Helpers.TransactionAndAssertion { taaTransaction = TJSON - { payload = - Update - 0 - (Types.ContractAddress 0 0) - "contract.check_module_reference" - (params scAddr expectModRef), + { payload = Update 0 (Types.ContractAddress 0 0) "contract.get_module_reference" params, metadata = makeDummyHeader accountAddress0 nce 100_000, keys = [(0, [(0, keyPair0)])] }, taaAssertion = \result _ -> return $ if Types.supportsContractInspectionQueries spv - then case mreject of - Nothing -> Helpers.assertSuccess result - Just reject -> + then case mExpectModRef of + Nothing -> do Helpers.assertRejectWhere ( \case - Types.RejectedReceive{..} - | rejectReason == reject -> return () + Types.RejectedReceive{rejectReason = -1} -> return () _ -> assertFailure "Rejected for incorrect reason" ) result - else Helpers.assertRejectWithReason Types.RuntimeFailure result + assertEqual + "Energy usage (non-existing instance)" + 744 + (Helpers.srUsedEnergy result) + Just modRef -> do + Helpers.assertSuccessWhere (checkEvents modRef) result + assertEqual + "Energy usage (existing instance)" + 776 + (Helpers.srUsedEnergy result) + else do + Helpers.assertRejectWithReason Types.RuntimeFailure result + assertEqual + "Energy usage (unsupported protocol version)" + 544 + (Helpers.srUsedEnergy result) } where - params (Types.ContractAddress i si) modRef = BSS.toShort $ runPut $ do - putWord64le $ fromIntegral i - putWord64le $ fromIntegral si - put modRef - checkNameHelper nce scAddr expectName mreject = + params = case scAddr of + (Types.ContractAddress i si) -> BSS.toShort $ runPut $ do + putWord64le $ fromIntegral i + putWord64le $ fromIntegral si + checkEvents modRef [Types.Updated{euEvents = [ContractEvent ce]}] = + assertEqual "Module reference" (BSS.toShort $ encode modRef) ce + checkEvents _ _ = assertFailure "Expected exactly one event" + getNameHelper :: + Types.Nonce -> + Types.ContractAddress -> + Maybe BSS.ShortByteString -> + Types.Energy -> + Helpers.TransactionAndAssertion pv + getNameHelper nce scAddr mExpectName expectEnergy = Helpers.TransactionAndAssertion { taaTransaction = TJSON - { payload = - Update - 0 - (Types.ContractAddress 2 0) - "contract2.check_name" - (params scAddr expectName), + { payload = Update 0 (Types.ContractAddress 2 0) "contract2.get_contract_name" params, metadata = makeDummyHeader accountAddress0 nce 100_000, keys = [(0, [(0, keyPair0)])] }, taaAssertion = \result _ -> - return $ + return $ do if Types.supportsContractInspectionQueries spv - then case mreject of - Nothing -> Helpers.assertSuccess result - Just reject -> - Helpers.assertRejectWhere - ( \case - Types.RejectedReceive{..} - | rejectReason == reject -> return () - _ -> assertFailure "Rejected for incorrect reason" - ) - result - else Helpers.assertRejectWithReason Types.RuntimeFailure result + then do + case mExpectName of + Nothing -> do + Helpers.assertRejectWhere + ( \case + Types.RejectedReceive{rejectReason = -1} -> return () + _ -> assertFailure "Rejected for incorrect reason" + ) + result + Just name -> do + Helpers.assertSuccessWhere (checkEvents name) result + assertEqual "Energy usage" expectEnergy (Helpers.srUsedEnergy result) + else do + Helpers.assertRejectWithReason Types.RuntimeFailure result + assertEqual "Energy usage" 542 (Helpers.srUsedEnergy result) } where - params (Types.ContractAddress i si) name = BSS.toShort $ runPut $ do - putWord64le $ fromIntegral i - putWord64le $ fromIntegral si - putByteString name + params = case scAddr of + (Types.ContractAddress i si) -> BSS.toShort $ runPut $ do + putWord64le $ fromIntegral i + putWord64le $ fromIntegral si + checkEvents name [Types.Updated{euEvents = [ContractEvent ce]}] = + assertEqual "Contract name" name ce + checkEvents _ _ = assertFailure "Expected exactly one event" -- | First source file for contract upgrade and query module reference interaction test. srcUpgrade0 :: FilePath diff --git a/concordium-consensus/tests/scheduler/Spec.hs b/concordium-consensus/tests/scheduler/Spec.hs index 0789e87bee..54c8d97c08 100644 --- a/concordium-consensus/tests/scheduler/Spec.hs +++ b/concordium-consensus/tests/scheduler/Spec.hs @@ -33,12 +33,12 @@ import qualified SchedulerTests.SmartContracts.Invoke (tests) import qualified SchedulerTests.SmartContracts.V1.AccountSignatureChecks (tests) import qualified SchedulerTests.SmartContracts.V1.AllNewHostFunctions (tests) import qualified SchedulerTests.SmartContracts.V1.Checkpointing (tests) -import qualified SchedulerTests.SmartContracts.V1.ContractInspection (tests) import qualified SchedulerTests.SmartContracts.V1.Counter (tests) import qualified SchedulerTests.SmartContracts.V1.CrossMessaging (tests) import qualified SchedulerTests.SmartContracts.V1.CustomSectionSize (tests) import qualified SchedulerTests.SmartContracts.V1.ErrorCodes (tests) import qualified SchedulerTests.SmartContracts.V1.Fallback (tests) +import qualified SchedulerTests.SmartContracts.V1.InspectModuleReferenceAndContractName (tests) import qualified SchedulerTests.SmartContracts.V1.Iterator (tests) import qualified SchedulerTests.SmartContracts.V1.P6WasmFeatures (tests) import qualified SchedulerTests.SmartContracts.V1.Queries (tests) @@ -104,4 +104,4 @@ main = hspec $ do SchedulerTests.SmartContracts.V1.P6WasmFeatures.tests SchedulerTests.SmartContracts.V1.CustomSectionSize.tests SchedulerTests.SmartContracts.V1.AccountSignatureChecks.tests - SchedulerTests.SmartContracts.V1.ContractInspection.tests + SchedulerTests.SmartContracts.V1.InspectModuleReferenceAndContractName.tests From 22e86625bac2a3c15d1da544563665857e51808d Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Tue, 27 Feb 2024 15:56:06 +0100 Subject: [PATCH 8/8] Update base. Correct energy costs. --- concordium-base | 2 +- .../InspectModuleReferenceAndContractName.hs | 40 +++++++------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/concordium-base b/concordium-base index 2ab3a68997..e68e3c7766 160000 --- a/concordium-base +++ b/concordium-base @@ -1 +1 @@ -Subproject commit 2ab3a689977c9abf9693d814afaf7d38e2b9448e +Subproject commit e68e3c7766eef62fd8d00e4627d9ed1e4ba5b06a diff --git a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs index 9d00216a8d..06f81c8b49 100644 --- a/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs +++ b/concordium-consensus/tests/scheduler/SchedulerTests/SmartContracts/V1/InspectModuleReferenceAndContractName.hs @@ -66,15 +66,18 @@ modRefQueriesAccountBalance :: Types.ModuleRef modRefQueriesAccountBalance = unsafePerformIO $ modRefOf srcQueriesAccountBalance -- | This test deploys three different smart contracts, from two different modules. --- One of these contracts <0,0> has a function for checking if the module reference matches an --- expected value. Another <2,0> has a function for checking if the contract name matches an --- expected value. Both functions are invoked for each instance, and for non-existant contract +-- One of these contracts <0,0> has a function that queries and logs the module reference of a +-- specified contract address. Another <2,0> queries and logs the contract name of a specified +-- contract. Both functions are invoked for each instance, and for non-existant contract -- addresses, ensuring the values are as expected. -- -- The entrypoints are designed to succeed in the case of a match, fail with code -1 if there is -- a mismatch, and fail with code -2 if the contract address does not exist. If the protocol -- version does not support the contract inspection functionality, then the call should fail with -- a runtime exception. +-- +-- As well as testing the result of the queries, this also tests that the costs of the operations +-- are as expected. testModuleRefAndName :: forall pv. (Types.IsProtocolVersion pv) => Types.SProtocolVersion pv -> [Char] -> SpecWith () testModuleRefAndName spv pvString | Types.supportsV1Contracts spv = @@ -98,24 +101,11 @@ testModuleRefAndName spv pvString getModRefHelper 8 (Types.ContractAddress 2 0) (Just modRefQueriesContractInspection), getModRefHelper 9 (Types.ContractAddress 3 0) Nothing, getModRefHelper 10 (Types.ContractAddress 0 1) Nothing, - -- checkModRefHelper 6 (Types.ContractAddress 0 0) modRefQueriesContractInspection Nothing, - -- checkModRefHelper 7 (Types.ContractAddress 1 0) modRefQueriesContractInspection (Just (-1)), - -- checkModRefHelper 8 (Types.ContractAddress 2 0) modRefQueriesContractInspection Nothing, - -- checkModRefHelper 9 (Types.ContractAddress 3 0) modRefQueriesContractInspection (Just (-2)), - -- checkModRefHelper 10 (Types.ContractAddress 0 1) modRefQueriesContractInspection (Just (-2)), - -- checkModRefHelper 11 (Types.ContractAddress 1 0) modRefQueriesAccountBalance Nothing, - getNameHelper 11 (Types.ContractAddress 0 0) (Just "init_contract") 755, - getNameHelper 12 (Types.ContractAddress 1 0) (Just "init_contract") 755, - getNameHelper 13 (Types.ContractAddress 2 0) (Just "init_contract2") 756, - getNameHelper 14 (Types.ContractAddress 3 0) Nothing 742, - getNameHelper 15 (Types.ContractAddress 0 1) Nothing 742 - -- checkNameHelper 12 (Types.ContractAddress 0 0) "init_contract" Nothing, - -- checkNameHelper 13 (Types.ContractAddress 1 0) "init_contract" Nothing, - -- checkNameHelper 14 (Types.ContractAddress 2 0) "init_contract" (Just (-1)), - -- checkNameHelper 15 (Types.ContractAddress 2 0) "init_contract2" Nothing, - -- checkNameHelper 16 (Types.ContractAddress 3 0) "init_contract" (Just (-2)), - -- checkNameHelper 17 (Types.ContractAddress 0 0) "init_contract2" (Just (-1)), - -- checkNameHelper 18 (Types.ContractAddress 0 1) "init_contract2" (Just (-2)) + getNameHelper 11 (Types.ContractAddress 0 0) (Just "init_contract") 754, + getNameHelper 12 (Types.ContractAddress 1 0) (Just "init_contract") 754, + getNameHelper 13 (Types.ContractAddress 2 0) (Just "init_contract2") 755, + getNameHelper 14 (Types.ContractAddress 3 0) Nothing 741, + getNameHelper 15 (Types.ContractAddress 0 1) Nothing 741 ] deployModHelper nce src = Helpers.TransactionAndAssertion @@ -174,19 +164,19 @@ testModuleRefAndName spv pvString result assertEqual "Energy usage (non-existing instance)" - 744 + 743 (Helpers.srUsedEnergy result) Just modRef -> do Helpers.assertSuccessWhere (checkEvents modRef) result assertEqual "Energy usage (existing instance)" - 776 + 775 (Helpers.srUsedEnergy result) else do Helpers.assertRejectWithReason Types.RuntimeFailure result assertEqual "Energy usage (unsupported protocol version)" - 544 + 543 (Helpers.srUsedEnergy result) } where @@ -228,7 +218,7 @@ testModuleRefAndName spv pvString assertEqual "Energy usage" expectEnergy (Helpers.srUsedEnergy result) else do Helpers.assertRejectWithReason Types.RuntimeFailure result - assertEqual "Energy usage" 542 (Helpers.srUsedEnergy result) + assertEqual "Energy usage" 541 (Helpers.srUsedEnergy result) } where params = case scAddr of