Skip to main content

sui_cluster_test/test_case/
grpc_publish_transaction_test.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{TestCaseImpl, TestContext};
5use async_trait::async_trait;
6use sui_move_build::test_utils::compile_basics_package;
7use sui_types::effects::TransactionEffectsAPI;
8use sui_types::object::Owner;
9
10pub struct GrpcPublishTransactionTest;
11
12#[async_trait]
13impl TestCaseImpl for GrpcPublishTransactionTest {
14    fn name(&self) -> &'static str {
15        "GrpcPublishTransaction"
16    }
17
18    fn description(&self) -> &'static str {
19        "Test building and executing a publish transaction via the gRPC transaction builder"
20    }
21
22    async fn run(&self, ctx: &mut TestContext) -> Result<(), anyhow::Error> {
23        let signer = ctx.get_wallet_address();
24        // Fund a gas coin and supply it explicitly so the gRPC publish builder
25        // stays on `LedgerService`.
26        let gas = ctx.get_sui_from_faucet(Some(1)).await.swap_remove(0);
27        let gas_ref = ctx.current_object_ref(*gas.id()).await;
28
29        // Compile the package and pass its module bytes + dependencies to the
30        // gRPC-backed publish builder.
31        let compiled_package = compile_basics_package().await;
32        let compiled_modules =
33            compiled_package.get_package_bytes(/* with_unpublished_deps */ false);
34        let dependencies = compiled_package.get_dependency_storage_package_ids();
35
36        let builder = ctx.get_grpc_client().transaction_builder();
37        let data = builder
38            .publish(
39                signer,
40                compiled_modules,
41                dependencies,
42                Some(gas_ref.0),
43                // Doesn't need to be scaled by RGP since most of the cost is storage
44                500_000_000,
45            )
46            .await?;
47
48        let response = ctx.sign_and_execute(data, "publish basics package").await;
49        // Publishing must create an immutable package object.
50        response
51            .effects
52            .created()
53            .iter()
54            .find(|(_obj_ref, owner)| *owner == Owner::Immutable)
55            .expect("Publish should create an immutable package object");
56
57        Ok(())
58    }
59}