Skip to content

Commit

Permalink
chore: use WASM chunk store in spec compliance tests (#2251)
Browse files Browse the repository at this point in the history
This PR uses the WASM chunk store to deploy the universal canister in
spec compliance tests so that the universal canister WASM blob is not
sent raw every time we deploy the universal canister. This optimization
is supposed to save ingress message bandwidth and thereby optimize the
spec compliance test runtime.
  • Loading branch information
mraszyk authored and nmattia committed Oct 25, 2024
1 parent 07e3b5b commit 5f94155
Show file tree
Hide file tree
Showing 10 changed files with 2,812 additions and 2,727 deletions.
3 changes: 2 additions & 1 deletion hs/spec_compliance/bin/ic-ref-test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ main = do
ac <- preFlight os
let TestSubnet my_sub = lookupOption os
let PeerSubnet other_sub = lookupOption os
defaultMainWithIngredients ingredients (icTests my_sub other_sub ac)
tests <- icTests my_sub other_sub ac
defaultMainWithIngredients ingredients tests
where
ingredients =
[ rerunningTests
Expand Down
8 changes: 8 additions & 0 deletions hs/spec_compliance/src/IC/Management.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ type InstallMode = V.Var ("install" R..== () R..+ "reinstall" R..== () R..+ "upg

type InstallCodeArgs = R.Rec ("mode" R..== InstallMode R..+ "canister_id" R..== Principal R..+ "wasm_module" R..== Blob R..+ "arg" R..== Blob R..+ "sender_canister_version" R..== Maybe W.Word64)

-- Canister installation using WASM chunks

type ChunkHash = R.Rec ("hash" R..== Blob)

type InstallChunkedCodeArgs = R.Rec ("mode" R..== InstallMode R..+ "target_canister" R..== Principal R..+ "store_canister" R..== Principal R..+ "chunk_hashes_list" R..== Vec.Vector ChunkHash R..+ "wasm_module_hash" R..== Blob R..+ "arg" R..== Blob R..+ "sender_canister_version" R..== Maybe W.Word64)

type UploadChunkArgs = R.Rec ("canister_id" R..== Principal R..+ "chunk" R..== Blob)

-- Canister history

type CandidChangeFromUser = R.Rec ("user_id" R..== Principal)
Expand Down
12 changes: 8 additions & 4 deletions hs/spec_compliance/src/IC/Test/Agent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ data AgentConfig = AgentConfig
tc_subnets :: [AgentSubnetConfig],
tc_httpbin_proto :: String,
tc_httpbin :: String,
tc_timeout :: Int
tc_timeout :: Int,
tc_ucan_chunk_hash :: Maybe Blob,
tc_store_canister_id :: Maybe Blob
}

makeAgentConfig :: Bool -> String -> [AgentSubnetConfig] -> String -> String -> Int -> IO AgentConfig
Expand Down Expand Up @@ -258,7 +260,9 @@ makeAgentConfig allow_self_signed_certs ep' subnets httpbin_proto httpbin' to =
tc_subnets = subnets,
tc_httpbin_proto = httpbin_proto,
tc_httpbin = httpbin,
tc_timeout = to
tc_timeout = to,
tc_ucan_chunk_hash = Nothing,
tc_store_canister_id = Nothing
}
where
-- strip trailing slash
Expand Down Expand Up @@ -288,8 +292,8 @@ preFlight os = do

type HasAgentConfig = (?agentConfig :: AgentConfig)

withAgentConfig :: (forall. (HasAgentConfig) => a) -> AgentConfig -> a
withAgentConfig act tc = let ?agentConfig = tc in act
withAgentConfig :: AgentConfig -> (forall. (HasAgentConfig) => a) -> a
withAgentConfig tc act = let ?agentConfig = tc in act

agentConfig :: (HasAgentConfig) => AgentConfig
agentConfig = ?agentConfig
Expand Down
20 changes: 20 additions & 0 deletions hs/spec_compliance/src/IC/Test/Agent/SafeCalls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module IC.Test.Agent.SafeCalls
ic_http_head_request',
ic_long_url_http_request',
ic_install',
ic_install_single_chunk',
ic_install_with_sender_canister_version',
ic_provisional_create',
ic_provisional_create_with_sender_canister_version',
Expand Down Expand Up @@ -159,6 +160,25 @@ ic_install_with_sender_canister_version' ic00 mode canister_id wasm_module arg s
ic_install' :: (HasAgentConfig) => IC00 -> InstallMode -> Blob -> Blob -> Blob -> IO ReqResponse
ic_install' ic00 mode canister_id wasm_module arg = ic_install_with_sender_canister_version' ic00 mode canister_id wasm_module arg Nothing

ic_install_single_chunk' :: (HasCallStack, HasAgentConfig) => IC00 -> InstallMode -> Blob -> Blob -> Blob -> Blob -> IO ReqResponse
ic_install_single_chunk' ic00 mode target_canister store_canister chunk_hash arg = do
callIC' ic00 target_canister #install_chunked_code $
empty
.+ #mode
.== mode
.+ #target_canister
.== Principal target_canister
.+ #store_canister
.== Principal store_canister
.+ #chunk_hashes_list
.== Vec.fromList [empty .+ #hash .== chunk_hash]
.+ #wasm_module_hash
.== chunk_hash
.+ #arg
.== arg
.+ #sender_canister_version
.== (Nothing :: Maybe W.Word64)

ic_update_settings_with_sender_canister_version' :: (HasAgentConfig) => IC00 -> Blob -> Maybe W.Word64 -> CanisterSettings -> IO ReqResponse
ic_update_settings_with_sender_canister_version' ic00 canister_id sender_canister_version r = do
callIC' ic00 canister_id #update_settings arg
Expand Down
32 changes: 32 additions & 0 deletions hs/spec_compliance/src/IC/Test/Agent/UnsafeCalls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module IC.Test.Agent.UnsafeCalls
ic_http_head_request,
ic_long_url_http_request,
ic_install,
ic_install_single_chunk,
ic_install_with_sender_canister_version,
ic_provisional_create,
ic_provisional_create_with_sender_canister_version,
Expand All @@ -38,6 +39,7 @@ module IC.Test.Agent.UnsafeCalls
ic_top_up,
ic_uninstall,
ic_uninstall_with_sender_canister_version,
ic_upload_chunk,
ic_update_settings,
ic_update_settings_with_sender_canister_version,
)
Expand Down Expand Up @@ -145,6 +147,36 @@ ic_install_with_sender_canister_version ic00 mode canister_id wasm_module arg se
ic_install :: (HasCallStack, HasAgentConfig) => IC00 -> InstallMode -> Blob -> Blob -> Blob -> IO ()
ic_install ic00 mode canister_id wasm_module arg = ic_install_with_sender_canister_version ic00 mode canister_id wasm_module arg Nothing

ic_install_single_chunk :: (HasCallStack, HasAgentConfig) => IC00 -> InstallMode -> Blob -> Blob -> Blob -> Blob -> IO ()
ic_install_single_chunk ic00 mode target_canister store_canister chunk_hash arg = do
callIC ic00 target_canister #install_chunked_code $
empty
.+ #mode
.== mode
.+ #target_canister
.== Principal target_canister
.+ #store_canister
.== Principal store_canister
.+ #chunk_hashes_list
.== Vec.fromList [empty .+ #hash .== chunk_hash]
.+ #wasm_module_hash
.== chunk_hash
.+ #arg
.== arg
.+ #sender_canister_version
.== (Nothing :: Maybe W.Word64)

ic_upload_chunk :: (HasCallStack, HasAgentConfig) => IC00 -> Blob -> Blob -> IO Blob
ic_upload_chunk ic00 canister_id chunk = do
chunk_hash :: ChunkHash <-
callIC ic00 canister_id #upload_chunk $
empty
.+ #canister_id
.== Principal canister_id
.+ #chunk
.== chunk
return $ chunk_hash .! #hash

ic_uninstall_with_sender_canister_version :: (HasCallStack, HasAgentConfig) => IC00 -> Blob -> Maybe W.Word64 -> IO ()
ic_uninstall_with_sender_canister_version ic00 canister_id sender_canister_version = do
callIC ic00 canister_id #uninstall_code $
Expand Down
Loading

0 comments on commit 5f94155

Please sign in to comment.