From 08b20f60d3686c535a6828a7216e529f5bdede75 Mon Sep 17 00:00:00 2001 From: Steve <1848680+misko9@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:14:55 -0600 Subject: [PATCH] feat: cosmwasm contract build flow during e2e test execution (#782) * Initial cosmwasm build flow * Add example cosmwasm test * Add comment * Move cosmwasm.go to interchaintest package * Rename intro to rust-optimizer * Allow cw contract to compile with custom docker image and version * Scaffold workspace-optimizer and move cosmwasm to own package * workspace-optimizer working, updated comments * Return channels when compiling contracts so that chain setup can proceed in parallel. * Cleanup waiting for compilation * fix lint errors * Add example cosmwasm tests to ci * Revert "Add example cosmwasm tests to ci" This reverts commit ecd6e6233fd4ff89f92c0e02a85fde344370ff22. * Check for rust/workspace-optimizer version and set the cache directory appropriately * Fix comment Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> --------- Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> --- chain/cosmos/wasm/wasm.go | 2 +- contract/cosmwasm/compile.go | 134 ++++ contract/cosmwasm/rust_optimizer.go | 86 +++ contract/cosmwasm/workspace_optimizer.go | 98 +++ examples/cosmwasm/rust-optimizer/README | 3 + .../rust-optimizer/contract/.cargo/config | 2 + .../rust-optimizer/contract/.gitignore | 2 + .../rust-optimizer/contract/Cargo.lock | 696 ++++++++++++++++++ .../rust-optimizer/contract/Cargo.toml | 14 + .../rust-optimizer/contract/src/contract.rs | 87 +++ .../rust-optimizer/contract/src/error.rs | 11 + .../rust-optimizer/contract/src/lib.rs | 4 + .../rust-optimizer/contract/src/msg.rs | 27 + .../rust-optimizer/contract/src/state.rs | 4 + .../rust-optimizer/rust_optimizer_test.go | 144 ++++ examples/cosmwasm/workspace-optimizer/README | 3 + .../workspace-optimizer/workspace/.gitignore | 2 + .../workspace-optimizer/workspace/Cargo.lock | 692 +++++++++++++++++ .../workspace-optimizer/workspace/Cargo.toml | 11 + .../contracts/contract1/.cargo/config | 2 + .../workspace/contracts/contract1/.gitignore | 2 + .../workspace/contracts/contract1/Cargo.lock | 696 ++++++++++++++++++ .../workspace/contracts/contract1/Cargo.toml | 14 + .../contracts/contract1/src/contract.rs | 87 +++ .../contracts/contract1/src/error.rs | 11 + .../workspace/contracts/contract1/src/lib.rs | 4 + .../workspace/contracts/contract1/src/msg.rs | 27 + .../contracts/contract1/src/state.rs | 4 + .../contracts/contract2/.cargo/config | 2 + .../workspace/contracts/contract2/.gitignore | 2 + .../workspace/contracts/contract2/Cargo.lock | 696 ++++++++++++++++++ .../workspace/contracts/contract2/Cargo.toml | 14 + .../contracts/contract2/src/contract.rs | 87 +++ .../contracts/contract2/src/error.rs | 11 + .../workspace/contracts/contract2/src/lib.rs | 4 + .../workspace/contracts/contract2/src/msg.rs | 27 + .../contracts/contract2/src/state.rs | 4 + .../workspace_optimizer_test.go | 144 ++++ 38 files changed, 3859 insertions(+), 1 deletion(-) create mode 100644 contract/cosmwasm/compile.go create mode 100644 contract/cosmwasm/rust_optimizer.go create mode 100644 contract/cosmwasm/workspace_optimizer.go create mode 100644 examples/cosmwasm/rust-optimizer/README create mode 100644 examples/cosmwasm/rust-optimizer/contract/.cargo/config create mode 100644 examples/cosmwasm/rust-optimizer/contract/.gitignore create mode 100644 examples/cosmwasm/rust-optimizer/contract/Cargo.lock create mode 100644 examples/cosmwasm/rust-optimizer/contract/Cargo.toml create mode 100644 examples/cosmwasm/rust-optimizer/contract/src/contract.rs create mode 100644 examples/cosmwasm/rust-optimizer/contract/src/error.rs create mode 100644 examples/cosmwasm/rust-optimizer/contract/src/lib.rs create mode 100644 examples/cosmwasm/rust-optimizer/contract/src/msg.rs create mode 100644 examples/cosmwasm/rust-optimizer/contract/src/state.rs create mode 100644 examples/cosmwasm/rust-optimizer/rust_optimizer_test.go create mode 100644 examples/cosmwasm/workspace-optimizer/README create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/.gitignore create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/Cargo.lock create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/Cargo.toml create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.cargo/config create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.gitignore create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.lock create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.toml create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/contract.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/error.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/lib.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/msg.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/state.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.cargo/config create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.gitignore create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.lock create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.toml create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/contract.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/error.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/lib.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/msg.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/state.rs create mode 100644 examples/cosmwasm/workspace-optimizer/workspace_optimizer_test.go diff --git a/chain/cosmos/wasm/wasm.go b/chain/cosmos/wasm/wasm.go index 46886314a..abbfd7c52 100644 --- a/chain/cosmos/wasm/wasm.go +++ b/chain/cosmos/wasm/wasm.go @@ -14,4 +14,4 @@ func WasmEncoding() *testutil.TestEncodingConfig { wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry) return &cfg -} +} \ No newline at end of file diff --git a/contract/cosmwasm/compile.go b/contract/cosmwasm/compile.go new file mode 100644 index 000000000..e83e72e65 --- /dev/null +++ b/contract/cosmwasm/compile.go @@ -0,0 +1,134 @@ +package cosmwasm + +import ( + "context" + "path/filepath" + "fmt" + "runtime" + "io" + "os" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/client" + "github.com/docker/docker/errdefs" + "github.com/docker/docker/pkg/stdcopy" + "github.com/hashicorp/go-version" +) + +// compile will compile the specified repo using the specified docker image and version +func compile(image string, optVersion string, repoPath string) (string, error) { + // Set the image to pull/use + arch := "" + if runtime.GOARCH == "arm64" { + arch = "-arm64" + } + imageFull := image + arch + ":" + optVersion + + // Check if version is less than 0.13.0, if so, use old cache directory + cacheDir := "/target" + versionThresh, err := version.NewVersion("0.13.0") + if err != nil { + return "", fmt.Errorf("version threshold 0.13.0: %w", err) + } + myVersion, err := version.NewVersion(optVersion) + if err != nil { + return "", fmt.Errorf("version %s: %w", optVersion, err) + } + if myVersion.LessThan(versionThresh) { + cacheDir = "/code/target" + } + + // Get absolute path of contract project + pwd, err := os.Getwd() + if err != nil { + return "", fmt.Errorf("getwd: %w", err) + } + repoPathFull := filepath.Join(pwd, repoPath) + + ctx := context.Background() + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + return "", fmt.Errorf("new client with opts: %w", err) + } + defer cli.Close() + + reader, err := cli.ImagePull(ctx, imageFull, types.ImagePullOptions{}) + if err != nil { + return "", fmt.Errorf("pull image %s: %w", imageFull, err) + } + + defer reader.Close() + _, err = io.Copy(os.Stdout, reader) + if err != nil { + return "", fmt.Errorf("io copy %s: %w", imageFull, err) + } + + resp, err := cli.ContainerCreate(ctx, &container.Config{ + Image: imageFull, + Tty: false, + }, &container.HostConfig{ + Mounts: []mount.Mount{ + { + Type: mount.TypeBind, + Source: repoPathFull, + Target: "/code", + }, + { + Type: mount.TypeVolume, + Source: filepath.Base(repoPathFull)+"_cache", + Target: cacheDir, + }, + { + Type: mount.TypeVolume, + Source: "registry_cache", + Target: "/usr/local/cargo/registry", + }, + }, + }, nil, nil, "") + if err != nil { + return "", fmt.Errorf("create container %s: %w", imageFull, err) + } + + if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { + return "", fmt.Errorf("start container %s: %w", imageFull, err) + } + + statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning) + select { + case err := <-errCh: + if err != nil { + return "", fmt.Errorf("wait container %s: %w", imageFull, err) + } + case <-statusCh: + } + + out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true}) + if err != nil { + return "", fmt.Errorf("logs container %s: %w", imageFull, err) + } + + _, err = stdcopy.StdCopy(os.Stdout, os.Stderr, out) + if err != nil { + return "", fmt.Errorf("std copy %s: %w", imageFull, err) + } + + err = cli.ContainerStop(ctx, resp.ID, container.StopOptions{}) + if err != nil { + // Only return the error if it didn't match an already stopped, or a missing container. + if !(errdefs.IsNotModified(err) || errdefs.IsNotFound(err)) { + return "", fmt.Errorf("stop container %s: %w", imageFull, err) + } + } + + err = cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{ + Force: true, + RemoveVolumes: true, + }) + if err != nil && !errdefs.IsNotFound(err) { + return "", fmt.Errorf("remove container %s: %w", imageFull, err) + } + + return repoPathFull, nil +} \ No newline at end of file diff --git a/contract/cosmwasm/rust_optimizer.go b/contract/cosmwasm/rust_optimizer.go new file mode 100644 index 000000000..ae5e880ff --- /dev/null +++ b/contract/cosmwasm/rust_optimizer.go @@ -0,0 +1,86 @@ +package cosmwasm + +import ( + "path/filepath" + "fmt" + "os" + "strings" +) + +type Contract struct { + DockerImage string + Version string + RelativePath string + wasmBinPathChan chan string + errChan chan error +} + +// NewContract return a contract struct, populated with defaults and its relative path +// relativePath is the relative path to the contract on local machine +func NewContract(relativePath string) *Contract { + return &Contract{ + DockerImage: "cosmwasm/rust-optimizer", + Version: "0.14.0", + RelativePath: relativePath, + } +} + +// WithDockerImage sets a custom docker image to use +func (c *Contract) WithDockerImage(image string) *Contract { + c.DockerImage = image + return c +} + +// WithVersion sets a custom version to use +func (c *Contract) WithVersion(version string) *Contract { + c.Version = version + return c +} + +// Compile will compile the contract +// cosmwasm/rust-optimizer is the expected docker image +func (c *Contract) Compile() *Contract { + c.wasmBinPathChan = make(chan string) + c.errChan = make(chan error, 1) + + go func() { + repoPathFull, err := compile(c.DockerImage, c.Version, c.RelativePath) + if err != nil { + c.errChan <- err + return + } + + // Form the path to the artifacts directory, used for checksum.txt and package.wasm + artifactsPath := filepath.Join(repoPathFull, "artifacts") + + // Parse the checksums.txt for the crate/wasm binary name + checksumsPath := filepath.Join(artifactsPath, "checksums.txt") + checksumsBz, err := os.ReadFile(checksumsPath) + if err != nil { + c.errChan <- fmt.Errorf("checksums read: %w", err) + return + } + _, wasmBin, found := strings.Cut(string(checksumsBz), " ") + if !found { + c.errChan <- fmt.Errorf("wasm binary name not found") + return + } + + // Form the path to the wasm binary + c.wasmBinPathChan <- filepath.Join(artifactsPath, strings.TrimSpace(wasmBin)) + }() + + return c +} + +// WaitForCompile will wait until compilation is complete, this can be called after chain setup +// Successful compilation will return the binary location in a channel +func (c *Contract) WaitForCompile() (string, error) { + contractBinary := "" + select { + case err := <-c.errChan: + return "", err + case contractBinary = <-c.wasmBinPathChan: + } + return contractBinary, nil +} \ No newline at end of file diff --git a/contract/cosmwasm/workspace_optimizer.go b/contract/cosmwasm/workspace_optimizer.go new file mode 100644 index 000000000..b42bfbb00 --- /dev/null +++ b/contract/cosmwasm/workspace_optimizer.go @@ -0,0 +1,98 @@ +package cosmwasm + +import ( + "bufio" + "path/filepath" + "fmt" + "os" + "strings" +) + +type Workspace struct { + DockerImage string + Version string + RelativePath string + wasmBinariesChan chan map[string]string + errChan chan error +} + +// NewWorkspace returns a workspace struct, populated with defaults and its relative path +// relativePath is the relative path to the workspace on local machine +func NewWorkspace(relativePath string) *Workspace { + return &Workspace{ + DockerImage: "cosmwasm/workspace-optimizer", + Version: "0.14.0", + RelativePath: relativePath, + } +} + +// WithDockerImage sets a custom docker image to use +func (w *Workspace) WithDockerImage(image string) *Workspace { + w.DockerImage = image + return w +} + +// WithVersion sets a custom version to use +func (w *Workspace) WithVersion(version string) *Workspace { + w.Version = version + return w +} + +// Compile will compile the workspace's contracts +// cosmwasm/workspace-optimizer is the expected docker image +// The workspace object is returned, call WaitForCompile() to get results +func (w *Workspace) Compile() *Workspace { + w.wasmBinariesChan = make(chan map[string]string) + w.errChan = make(chan error, 1) + + go func() { + repoPathFull, err := compile(w.DockerImage, w.Version, w.RelativePath) + if err != nil { + w.errChan <- err + return + } + + // Form the path to the artifacts directory, used for checksum.txt and package.wasm + artifactsPath := filepath.Join(repoPathFull, "artifacts") + + // Parse the checksums.txt for the crate/wasm binary names + wasmBinaries := make(map[string]string) + checksumsPath := filepath.Join(artifactsPath, "checksums.txt") + file, err := os.Open(checksumsPath) + if err != nil { + w.errChan <- fmt.Errorf("checksums open: %w", err) + return + } + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + _, wasmBin, found := strings.Cut(line, " ") + if !found { + w.errChan <- fmt.Errorf("wasm binary name not found") + return + } + wasmBin = strings.TrimSpace(wasmBin) + crateName, _, found := strings.Cut(wasmBin, ".") + if !found { + w.errChan <- fmt.Errorf("wasm binary name invalid") + return + } + wasmBinaries[crateName] = filepath.Join(artifactsPath, wasmBin) + } + w.wasmBinariesChan <- wasmBinaries + }() + + return w +} + +// WaitForCompile will wait until coyympilation is complete, this can be called after chain setup +// Successful compilation will return a map of crate names to binary locations in a channel +func (w *Workspace) WaitForCompile() (map[string]string, error) { + contractBinaries := make(map[string]string) + select { + case err := <-w.errChan: + return contractBinaries, err + case contractBinaries = <-w.wasmBinariesChan: + } + return contractBinaries, nil +} \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/README b/examples/cosmwasm/rust-optimizer/README new file mode 100644 index 000000000..348ea58ef --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/README @@ -0,0 +1,3 @@ +The rust-optimizer example contains a simple contract that performs minimal functionality. +The single contract uses cosmwasm/rust-optimizer to compile during test execution. +The test case shows how the contract source can integrate with interchaintest: building the contract, spinning up a chain, storing it on-chain, and instantiating/querying/executing against it. \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/contract/.cargo/config b/examples/cosmwasm/rust-optimizer/contract/.cargo/config new file mode 100644 index 000000000..cca579879 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/.cargo/config @@ -0,0 +1,2 @@ +[alias] +wasm = "build --target wasm32-unknown-unknown --release --lib" \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/contract/.gitignore b/examples/cosmwasm/rust-optimizer/contract/.gitignore new file mode 100644 index 000000000..7d2b57829 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/.gitignore @@ -0,0 +1,2 @@ +target/ +artifacts/ \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/contract/Cargo.lock b/examples/cosmwasm/rust-optimizer/contract/Cargo.lock new file mode 100644 index 000000000..cf3db7f0c --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/Cargo.lock @@ -0,0 +1,696 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" + +[[package]] +name = "cosmwasm-crypto" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75836a10cb9654c54e77ee56da94d592923092a10b369cdb0dbd56acefc16340" +dependencies = [ + "digest 0.10.7", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9f7f0e51bfc7295f7b2664fe8513c966428642aa765dad8a74acdab5e0c773" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f00b363610218eea83f24bbab09e1a7c3920b79f068334fdfcc62f6129ef9fc" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae38f909b2822d32b275c9e2db9728497aa33ffe67dd463bc67c6a3b7092785c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a49b85345e811c8e80ec55d0d091e4fcb4f00f97ab058f9be5f614c444a730cb" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.6", + "thiserror", + "uint", +] + +[[package]] +name = "cpufeatures" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "intro-contract" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "thiserror", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "k256" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2 0.10.6", +] + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "once_cell" +version = "1.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/examples/cosmwasm/rust-optimizer/contract/Cargo.toml b/examples/cosmwasm/rust-optimizer/contract/Cargo.toml new file mode 100644 index 000000000..0a319509a --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "intro-contract" +version = "0.1.0" +edition = "2021" +authors = ["Strangelove developers"] + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +cosmwasm-schema = "1.1.2" +cosmwasm-std = "1.1.2" +cw-storage-plus = "0.13.2" +thiserror = {version = "1.0.31"} \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/contract/src/contract.rs b/examples/cosmwasm/rust-optimizer/contract/src/contract.rs new file mode 100644 index 000000000..96105908e --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/src/contract.rs @@ -0,0 +1,87 @@ +use crate::{ + error::ContractError, + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, OwnerResponse}, + state::OWNER, +}; +use cosmwasm_std::{ + entry_point, + to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, +}; + +#[entry_point] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + OWNER.save(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_attribute("action", "instantiate") + .add_attribute("owner", info.sender)) +} + +/// Allow contract to be able to migrate if admin is set. +/// This provides option for migration, if admin is not set, this functionality will be disabled +#[entry_point] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + Ok(Response::new().add_attribute("action", "migrate")) +} + +#[entry_point] +pub fn execute( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + // Admin functions + ExecuteMsg::ChangeContractOwner { new_owner } => + change_contract_owner(deps, info, new_owner), + } +} + +fn change_contract_owner( + deps: DepsMut, + info: MessageInfo, + new_owner: String, +) -> Result { + // Only allow current contract owner to change owner + check_is_contract_owner(deps.as_ref(), info.sender)?; + + // validate that new owner is a valid address + let new_owner_addr = deps.api.addr_validate(&new_owner)?; + + // update the contract owner in the contract config + OWNER.save(deps.storage, &new_owner_addr)?; + + // return OK + Ok(Response::new() + .add_attribute("action", "change_contract_owner") + .add_attribute("new_owner", new_owner)) +} + +fn check_is_contract_owner(deps: Deps, sender: Addr) -> Result<(), ContractError> { + let owner = OWNER.load(deps.storage)?; + if owner != sender { + Err(ContractError::Unauthorized {}) + } else { + Ok(()) + } +} + +#[entry_point] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Owner {} => to_binary(&query_owner(deps)?), + } +} + +fn query_owner(deps: Deps) -> StdResult { + let owner = OWNER.load(deps.storage)?; + Ok(OwnerResponse { + address: owner.to_string(), + }) +} diff --git a/examples/cosmwasm/rust-optimizer/contract/src/error.rs b/examples/cosmwasm/rust-optimizer/contract/src/error.rs new file mode 100644 index 000000000..dc19f1033 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/src/error.rs @@ -0,0 +1,11 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, +} diff --git a/examples/cosmwasm/rust-optimizer/contract/src/lib.rs b/examples/cosmwasm/rust-optimizer/contract/src/lib.rs new file mode 100644 index 000000000..2b779f467 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/src/lib.rs @@ -0,0 +1,4 @@ +pub mod contract; +pub mod error; +pub mod msg; +pub mod state; \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/contract/src/msg.rs b/examples/cosmwasm/rust-optimizer/contract/src/msg.rs new file mode 100644 index 000000000..6b99f2bc7 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/src/msg.rs @@ -0,0 +1,27 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; + +#[cw_serde] +pub struct InstantiateMsg {} + +#[cw_serde] +pub struct MigrateMsg {} + +#[cw_serde] +pub enum ExecuteMsg { + ChangeContractOwner { + new_owner: String, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + /// Owner returns the owner of the contract. Response: OwnerResponse + #[returns(OwnerResponse)] + Owner {}, +} + +#[cw_serde] +pub struct OwnerResponse { + pub address: String, +} diff --git a/examples/cosmwasm/rust-optimizer/contract/src/state.rs b/examples/cosmwasm/rust-optimizer/contract/src/state.rs new file mode 100644 index 000000000..d7ecf6b05 --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/contract/src/state.rs @@ -0,0 +1,4 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; + +pub const OWNER: Item = Item::new("owner"); \ No newline at end of file diff --git a/examples/cosmwasm/rust-optimizer/rust_optimizer_test.go b/examples/cosmwasm/rust-optimizer/rust_optimizer_test.go new file mode 100644 index 000000000..df5bb366f --- /dev/null +++ b/examples/cosmwasm/rust-optimizer/rust_optimizer_test.go @@ -0,0 +1,144 @@ +package rust_optimizer + +import ( + "context" + "encoding/json" + "testing" + + "cosmossdk.io/math" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/wasm" + "github.com/strangelove-ventures/interchaintest/v8/contract/cosmwasm" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/testreporter" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +// TestRustOptimizerContract compiles a cosmwasm contract using cosmwasm/rust-optimizer +// It then spins up a juno chain and executes tests +func TestRustOptimizerContract(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } + + t.Parallel() + + // Compile the contract, input is the relative path to the project + // Using cosmwasm/rust-optimizer v0.13.0 instead of the default v0.14.0 + // Output is the contract object + // Compilation runs in parallel with chain setup, waiting if necessary before StoreContract + contract := cosmwasm.NewContract("contract").WithVersion("0.13.0").Compile() + + ctx := context.Background() + + // Chain Factory + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "juno", + Version: "latest", + ChainConfig: ibc.ChainConfig{ + GasPrices: "0.00ujuno", + EncodingConfig: wasm.WasmEncoding(), + }, + }, + }) + + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + juno := chains[0].(*cosmos.CosmosChain) + + client, network := interchaintest.DockerSetup(t) + + // Prep Interchain + ic := interchaintest.NewInterchain().AddChain(juno) + + rep := testreporter.NewNopReporter() + eRep := rep.RelayerExecReporter(t) + + // Build interchain + require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), + SkipPathCreation: true, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + // Create and Fund User Wallets + initBal := math.NewInt(100_000_000) + users := interchaintest.GetAndFundTestUsers(t, ctx, "default", initBal.Int64(), juno) + junoUser := users[0] + + err = testutil.WaitForBlocks(ctx, 2, juno) + require.NoError(t, err) + + // Verify balance + junoUserBalInitial, err := juno.GetBalance(ctx, junoUser.FormattedAddress(), juno.Config().Denom) + require.NoError(t, err) + require.True(t, junoUserBalInitial.Equal(initBal)) + + // Wait for contract to finish compiling + contractBinary, err := contract.WaitForCompile() + require.NoError(t, err) + + // Store contract + contractCodeId, err := juno.StoreContract(ctx, junoUser.KeyName(), contractBinary) + require.NoError(t, err) + + // Instantiate contract + contractAddr, err := juno.InstantiateContract(ctx, junoUser.KeyName(), contractCodeId, "{}", true) + require.NoError(t, err) + + // Query current contract owner + var queryOwnerResp QueryOwnerResponseData + queryOwnerMsg := QueryMsg{Owner: &Owner{}} + err = juno.QueryContract(ctx, contractAddr, queryOwnerMsg, &queryOwnerResp) + require.NoError(t, err) + require.Equal(t, junoUser.FormattedAddress(), queryOwnerResp.Data.Address) + + // Set a new contract owner + newContractOwnerAddr := "juno1kmmr2nu0f2nha6qwhu8s6y5l6yfr3cx505jf25" + changeContractOwnerMsg := ExecuteMsg{ + ChangeContractOwner: &ChangeContractOwner{ + NewOwner: newContractOwnerAddr, + }, + } + + msgBz, err := json.Marshal(changeContractOwnerMsg) + require.NoError(t, err) + _, err = juno.ExecuteContract(ctx, junoUser.KeyName(), contractAddr, string(msgBz)) + require.NoError(t, err) + + // Query the new contract owner + err = juno.QueryContract(ctx, contractAddr, queryOwnerMsg, &queryOwnerResp) + require.NoError(t, err) + require.Equal(t, newContractOwnerAddr, queryOwnerResp.Data.Address) +} + +type ExecuteMsg struct { + ChangeContractOwner *ChangeContractOwner `json:"change_contract_owner,omitempty"` +} + +type ChangeContractOwner struct { + NewOwner string `json:"new_owner"` +} + +type QueryMsg struct { + Owner *Owner `json:"owner,omitempty"` +} + +type Owner struct{} + +type QueryOwnerResponseData struct { + Data QueryOwnerResponse `json:"data,omitempty"` +} + +type QueryOwnerResponse struct { + Address string `json:"address,omitempty"` +} diff --git a/examples/cosmwasm/workspace-optimizer/README b/examples/cosmwasm/workspace-optimizer/README new file mode 100644 index 000000000..ffee2d736 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/README @@ -0,0 +1,3 @@ +The workspace-optimizer example contains a workspace organized with two simple contracts that performs minimal functionality. +The workspace uses cosmwasm/workspace-optimizer to compile during test execution. +The test case shows how the contracts source can integrate with interchaintest: building the contracts, spinning up a chain, storing it on-chain, and instantiating/querying/executing against it. \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/.gitignore b/examples/cosmwasm/workspace-optimizer/workspace/.gitignore new file mode 100644 index 000000000..7d2b57829 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/.gitignore @@ -0,0 +1,2 @@ +target/ +artifacts/ \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/Cargo.lock b/examples/cosmwasm/workspace-optimizer/workspace/Cargo.lock new file mode 100644 index 000000000..9a3cdf9ef --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/Cargo.lock @@ -0,0 +1,692 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bnum" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128a44527fc0d6abf05f9eda748b9027536e12dff93f5acc8449f51583309350" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" + +[[package]] +name = "contract1" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "thiserror", +] + +[[package]] +name = "contract2" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "thiserror", +] + +[[package]] +name = "cosmwasm-crypto" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca101fbf2f76723711a30ea3771ef312ec3ec254ad021b237871ed802f9f175" +dependencies = [ + "digest 0.10.7", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c73d2dd292f60e42849d2b07c03d809cf31e128a4299a805abd6d24553bcaaf5" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce34a08020433989af5cc470104f6bd22134320fe0221bd8aeb919fd5ec92d5" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96694ec781a7dd6dea1f968a2529ade009c21ad999c88b5f53d6cc495b3b96f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a44d3f9c25b2f864737c6605a98f2e4675d53fd8bbc7cf4d7c02475661a793d" +dependencies = [ + "base64", + "bnum", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.7", + "thiserror", +] + +[[package]] +name = "cpufeatures" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-bigint" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" + +[[package]] +name = "ecdsa" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.7", + "signature", +] + +[[package]] +name = "libc" +version = "0.2.148" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "schemars" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763f8cd0d4c71ed8389c90cb8100cba87e763bd01a8e614d4f0af97bcd50a161" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0f696e21e10fa546b7ffb1c9672c6de8fbc7a81acf59524386d8639bf12737" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/examples/cosmwasm/workspace-optimizer/workspace/Cargo.toml b/examples/cosmwasm/workspace-optimizer/workspace/Cargo.toml new file mode 100644 index 000000000..bd5905237 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +members = [ + "contracts/contract1", + "contracts/contract2" +] + +[workspace.dependencies] +cosmwasm-schema = "1.1.2" +cosmwasm-std = "1.1.2" +cw-storage-plus = "0.13.2" +thiserror = {version = "1.0.31"} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.cargo/config b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.cargo/config new file mode 100644 index 000000000..cca579879 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.cargo/config @@ -0,0 +1,2 @@ +[alias] +wasm = "build --target wasm32-unknown-unknown --release --lib" \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.gitignore b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.gitignore new file mode 100644 index 000000000..7d2b57829 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/.gitignore @@ -0,0 +1,2 @@ +target/ +artifacts/ \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.lock b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.lock new file mode 100644 index 000000000..cf3db7f0c --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.lock @@ -0,0 +1,696 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" + +[[package]] +name = "cosmwasm-crypto" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75836a10cb9654c54e77ee56da94d592923092a10b369cdb0dbd56acefc16340" +dependencies = [ + "digest 0.10.7", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9f7f0e51bfc7295f7b2664fe8513c966428642aa765dad8a74acdab5e0c773" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f00b363610218eea83f24bbab09e1a7c3920b79f068334fdfcc62f6129ef9fc" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae38f909b2822d32b275c9e2db9728497aa33ffe67dd463bc67c6a3b7092785c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a49b85345e811c8e80ec55d0d091e4fcb4f00f97ab058f9be5f614c444a730cb" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.6", + "thiserror", + "uint", +] + +[[package]] +name = "cpufeatures" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "intro-contract" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "thiserror", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "k256" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2 0.10.6", +] + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "once_cell" +version = "1.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.toml b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.toml new file mode 100644 index 000000000..09cf4af11 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "contract1" +version = "0.1.0" +edition = "2021" +authors = ["Strangelove developers"] + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +thiserror = { workspace = true } \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/contract.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/contract.rs new file mode 100644 index 000000000..96105908e --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/contract.rs @@ -0,0 +1,87 @@ +use crate::{ + error::ContractError, + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, OwnerResponse}, + state::OWNER, +}; +use cosmwasm_std::{ + entry_point, + to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, +}; + +#[entry_point] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + OWNER.save(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_attribute("action", "instantiate") + .add_attribute("owner", info.sender)) +} + +/// Allow contract to be able to migrate if admin is set. +/// This provides option for migration, if admin is not set, this functionality will be disabled +#[entry_point] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + Ok(Response::new().add_attribute("action", "migrate")) +} + +#[entry_point] +pub fn execute( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + // Admin functions + ExecuteMsg::ChangeContractOwner { new_owner } => + change_contract_owner(deps, info, new_owner), + } +} + +fn change_contract_owner( + deps: DepsMut, + info: MessageInfo, + new_owner: String, +) -> Result { + // Only allow current contract owner to change owner + check_is_contract_owner(deps.as_ref(), info.sender)?; + + // validate that new owner is a valid address + let new_owner_addr = deps.api.addr_validate(&new_owner)?; + + // update the contract owner in the contract config + OWNER.save(deps.storage, &new_owner_addr)?; + + // return OK + Ok(Response::new() + .add_attribute("action", "change_contract_owner") + .add_attribute("new_owner", new_owner)) +} + +fn check_is_contract_owner(deps: Deps, sender: Addr) -> Result<(), ContractError> { + let owner = OWNER.load(deps.storage)?; + if owner != sender { + Err(ContractError::Unauthorized {}) + } else { + Ok(()) + } +} + +#[entry_point] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Owner {} => to_binary(&query_owner(deps)?), + } +} + +fn query_owner(deps: Deps) -> StdResult { + let owner = OWNER.load(deps.storage)?; + Ok(OwnerResponse { + address: owner.to_string(), + }) +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/error.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/error.rs new file mode 100644 index 000000000..dc19f1033 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/error.rs @@ -0,0 +1,11 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized")] + Unauthorized {}, +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/lib.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/lib.rs new file mode 100644 index 000000000..2b779f467 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/lib.rs @@ -0,0 +1,4 @@ +pub mod contract; +pub mod error; +pub mod msg; +pub mod state; \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/msg.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/msg.rs new file mode 100644 index 000000000..6b99f2bc7 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/msg.rs @@ -0,0 +1,27 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; + +#[cw_serde] +pub struct InstantiateMsg {} + +#[cw_serde] +pub struct MigrateMsg {} + +#[cw_serde] +pub enum ExecuteMsg { + ChangeContractOwner { + new_owner: String, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + /// Owner returns the owner of the contract. Response: OwnerResponse + #[returns(OwnerResponse)] + Owner {}, +} + +#[cw_serde] +pub struct OwnerResponse { + pub address: String, +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/state.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/state.rs new file mode 100644 index 000000000..d7ecf6b05 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract1/src/state.rs @@ -0,0 +1,4 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; + +pub const OWNER: Item = Item::new("owner"); \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.cargo/config b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.cargo/config new file mode 100644 index 000000000..cca579879 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.cargo/config @@ -0,0 +1,2 @@ +[alias] +wasm = "build --target wasm32-unknown-unknown --release --lib" \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.gitignore b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.gitignore new file mode 100644 index 000000000..7d2b57829 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/.gitignore @@ -0,0 +1,2 @@ +target/ +artifacts/ \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.lock b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.lock new file mode 100644 index 000000000..cf3db7f0c --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.lock @@ -0,0 +1,696 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" + +[[package]] +name = "cosmwasm-crypto" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75836a10cb9654c54e77ee56da94d592923092a10b369cdb0dbd56acefc16340" +dependencies = [ + "digest 0.10.7", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9f7f0e51bfc7295f7b2664fe8513c966428642aa765dad8a74acdab5e0c773" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f00b363610218eea83f24bbab09e1a7c3920b79f068334fdfcc62f6129ef9fc" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae38f909b2822d32b275c9e2db9728497aa33ffe67dd463bc67c6a3b7092785c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a49b85345e811c8e80ec55d0d091e4fcb4f00f97ab058f9be5f614c444a730cb" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm", + "sha2 0.10.6", + "thiserror", + "uint", +] + +[[package]] +name = "cpufeatures" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-storage-plus" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648b1507290bbc03a8d88463d7cd9b04b1fa0155e5eef366c4fa052b9caaac7a" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "der" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "intro-contract" +version = "0.1.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "thiserror", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "k256" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2 0.10.6", +] + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "once_cell" +version = "1.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 1.0.109", +] + +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.toml b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.toml new file mode 100644 index 000000000..243ba601d --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "contract2" +version = "0.1.0" +edition = "2021" +authors = ["Strangelove developers"] + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +thiserror = { workspace = true } \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/contract.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/contract.rs new file mode 100644 index 000000000..3a93b6852 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/contract.rs @@ -0,0 +1,87 @@ +use crate::{ + error::ContractError, + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, OwnerResponse}, + state::OWNER, +}; +use cosmwasm_std::{ + entry_point, + to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, +}; + +#[entry_point] +pub fn instantiate( + deps: DepsMut, + _env: Env, + info: MessageInfo, + _msg: InstantiateMsg, +) -> Result { + OWNER.save(deps.storage, &info.sender)?; + + Ok(Response::new() + .add_attribute("action", "instantiate-contract2") + .add_attribute("owner", info.sender)) +} + +/// Allow contract to be able to migrate if admin is set. +/// This provides option for migration, if admin is not set, this functionality will be disabled +#[entry_point] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + Ok(Response::new().add_attribute("action", "migrate")) +} + +#[entry_point] +pub fn execute( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + match msg { + // Admin functions + ExecuteMsg::ChangeContractOwner { new_owner } => + change_contract_owner(deps, info, new_owner), + } +} + +fn change_contract_owner( + deps: DepsMut, + info: MessageInfo, + new_owner: String, +) -> Result { + // Only allow current contract owner to change owner + check_is_contract_owner(deps.as_ref(), info.sender)?; + + // validate that new owner is a valid address + let new_owner_addr = deps.api.addr_validate(&new_owner)?; + + // update the contract owner in the contract config + OWNER.save(deps.storage, &new_owner_addr)?; + + // return OK + Ok(Response::new() + .add_attribute("action", "change_contract2_owner") + .add_attribute("new_owner", new_owner)) +} + +fn check_is_contract_owner(deps: Deps, sender: Addr) -> Result<(), ContractError> { + let owner = OWNER.load(deps.storage)?; + if owner != sender { + Err(ContractError::Unauthorized {}) + } else { + Ok(()) + } +} + +#[entry_point] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Owner {} => to_binary(&query_owner(deps)?), + } +} + +fn query_owner(deps: Deps) -> StdResult { + let owner = OWNER.load(deps.storage)?; + Ok(OwnerResponse { + address: owner.to_string(), + }) +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/error.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/error.rs new file mode 100644 index 000000000..11b0ff407 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/error.rs @@ -0,0 +1,11 @@ +use cosmwasm_std::StdError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ContractError { + #[error("{0}")] + Std(#[from] StdError), + + #[error("Unauthorized2")] + Unauthorized {}, +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/lib.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/lib.rs new file mode 100644 index 000000000..2b779f467 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/lib.rs @@ -0,0 +1,4 @@ +pub mod contract; +pub mod error; +pub mod msg; +pub mod state; \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/msg.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/msg.rs new file mode 100644 index 000000000..6b99f2bc7 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/msg.rs @@ -0,0 +1,27 @@ +use cosmwasm_schema::{cw_serde, QueryResponses}; + +#[cw_serde] +pub struct InstantiateMsg {} + +#[cw_serde] +pub struct MigrateMsg {} + +#[cw_serde] +pub enum ExecuteMsg { + ChangeContractOwner { + new_owner: String, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + /// Owner returns the owner of the contract. Response: OwnerResponse + #[returns(OwnerResponse)] + Owner {}, +} + +#[cw_serde] +pub struct OwnerResponse { + pub address: String, +} diff --git a/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/state.rs b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/state.rs new file mode 100644 index 000000000..42503bc0e --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace/contracts/contract2/src/state.rs @@ -0,0 +1,4 @@ +use cosmwasm_std::Addr; +use cw_storage_plus::Item; + +pub const OWNER: Item = Item::new("owner2"); \ No newline at end of file diff --git a/examples/cosmwasm/workspace-optimizer/workspace_optimizer_test.go b/examples/cosmwasm/workspace-optimizer/workspace_optimizer_test.go new file mode 100644 index 000000000..f127f8c06 --- /dev/null +++ b/examples/cosmwasm/workspace-optimizer/workspace_optimizer_test.go @@ -0,0 +1,144 @@ +package workspace_optimizer + +import ( + "context" + "encoding/json" + "testing" + + "cosmossdk.io/math" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos/wasm" + "github.com/strangelove-ventures/interchaintest/v8/contract/cosmwasm" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/testreporter" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" +) + +// TestWorkspaceOptimizerContracts compiles a workspace's contracts using cosmwasm/workspace-optimizer +// It then spins up a juno chain and executes tests +func TestWorkspaceOptimizerContracts(t *testing.T) { + if testing.Short() { + t.Skip("skipping in short mode") + } + + t.Parallel() + + // Compile the workspace contracts, input is the relative path to the project + // Using cosmwasm/workspace-optimizer v0.14.0 (default) + // Output is the workspace object + // Compilation runs in parallel with the chain setup, waiting if necessary before StoreContract + workspace := cosmwasm.NewWorkspace("workspace").Compile() + + ctx := context.Background() + + // Chain Factory + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "juno", + Version: "latest", + ChainConfig: ibc.ChainConfig{ + GasPrices: "0.00ujuno", + EncodingConfig: wasm.WasmEncoding(), + }, + }, + }) + + chains, err := cf.Chains(t.Name()) + require.NoError(t, err) + juno := chains[0].(*cosmos.CosmosChain) + + client, network := interchaintest.DockerSetup(t) + + // Prep Interchain + ic := interchaintest.NewInterchain().AddChain(juno) + + rep := testreporter.NewNopReporter() + eRep := rep.RelayerExecReporter(t) + + // Build interchain + require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ + TestName: t.Name(), + Client: client, + NetworkID: network, + BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), + SkipPathCreation: true, + })) + t.Cleanup(func() { + _ = ic.Close() + }) + + // Create and Fund User Wallets + initBal := math.NewInt(100_000_000) + users := interchaintest.GetAndFundTestUsers(t, ctx, "default", initBal.Int64(), juno) + junoUser := users[0] + + err = testutil.WaitForBlocks(ctx, 2, juno) + require.NoError(t, err) + + // Verify balance + junoUserBalInitial, err := juno.GetBalance(ctx, junoUser.FormattedAddress(), juno.Config().Denom) + require.NoError(t, err) + require.True(t, junoUserBalInitial.Equal(initBal)) + + // Wait for contracts to finish compiling + contractBinaries, err := workspace.WaitForCompile() + require.NoError(t, err) + + // Store contract + contractCodeId, err := juno.StoreContract(ctx, junoUser.KeyName(), contractBinaries["contract1"]) + require.NoError(t, err) + + // Instantiate contract + contractAddr, err := juno.InstantiateContract(ctx, junoUser.KeyName(), contractCodeId, "{}", true) + require.NoError(t, err) + + // Query current contract owner + var queryOwnerResp QueryOwnerResponseData + queryOwnerMsg := QueryMsg{Owner: &Owner{}} + err = juno.QueryContract(ctx, contractAddr, queryOwnerMsg, &queryOwnerResp) + require.NoError(t, err) + require.Equal(t, junoUser.FormattedAddress(), queryOwnerResp.Data.Address) + + // Set a new contract owner + newContractOwnerAddr := "juno1kmmr2nu0f2nha6qwhu8s6y5l6yfr3cx505jf25" + changeContractOwnerMsg := ExecuteMsg{ + ChangeContractOwner: &ChangeContractOwner{ + NewOwner: newContractOwnerAddr, + }, + } + + msgBz, err := json.Marshal(changeContractOwnerMsg) + require.NoError(t, err) + _, err = juno.ExecuteContract(ctx, junoUser.KeyName(), contractAddr, string(msgBz)) + require.NoError(t, err) + + // Query the new contract owner + err = juno.QueryContract(ctx, contractAddr, queryOwnerMsg, &queryOwnerResp) + require.NoError(t, err) + require.Equal(t, newContractOwnerAddr, queryOwnerResp.Data.Address) +} + +type ExecuteMsg struct { + ChangeContractOwner *ChangeContractOwner `json:"change_contract_owner,omitempty"` +} + +type ChangeContractOwner struct { + NewOwner string `json:"new_owner"` +} + +type QueryMsg struct { + Owner *Owner `json:"owner,omitempty"` +} + +type Owner struct{} + +type QueryOwnerResponseData struct { + Data QueryOwnerResponse `json:"data,omitempty"` +} + +type QueryOwnerResponse struct { + Address string `json:"address,omitempty"` +}