diff --git a/.github/workflows/plotter-test.yml b/.github/workflows/plotter-test.yml new file mode 100644 index 0000000000..d509759003 --- /dev/null +++ b/.github/workflows/plotter-test.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +permissions: + checks: write + pull-requests: write + +jobs: + template_test_current: + name: Plotter tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + + - name: Run plotter tests + run: | + cd tools/plotter + cargo test diff --git a/contracts/feature-tests/basic-features/sc-config.toml b/contracts/feature-tests/basic-features/sc-config.toml index 42c4880f67..cdba7ce722 100644 --- a/contracts/feature-tests/basic-features/sc-config.toml +++ b/contracts/feature-tests/basic-features/sc-config.toml @@ -21,4 +21,10 @@ kill_legacy_callback = true [[proxy]] path = "src/basic_features_proxy.rs" add-unlabelled = false -add-endpoints = ["init", "store_bytes", "load_bytes", "returns_egld_decimal"] +add-endpoints = [ + "init", + "store_bytes", + "load_bytes", + "returns_egld_decimal", + "echo_managed_option", +] diff --git a/contracts/feature-tests/basic-features/src/basic_features_proxy.rs b/contracts/feature-tests/basic-features/src/basic_features_proxy.rs index 469b2d3323..78e267f6bc 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_proxy.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_proxy.rs @@ -62,6 +62,20 @@ where To: TxTo, Gas: TxGas, { + /// This tests how is generated type name in proxy + pub fn echo_managed_option< + Arg0: ProxyArg>>, + >( + self, + mo: Arg0, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("echo_managed_option") + .argument(&mo) + .original_result() + } + pub fn load_bytes( self, ) -> TxTypedCall> { diff --git a/contracts/feature-tests/basic-features/src/echo_managed.rs b/contracts/feature-tests/basic-features/src/echo_managed.rs index 62ee33a7a7..17084a26c8 100644 --- a/contracts/feature-tests/basic-features/src/echo_managed.rs +++ b/contracts/feature-tests/basic-features/src/echo_managed.rs @@ -1,4 +1,4 @@ -multiversx_sc::imports!(); +use multiversx_sc::imports::*; /// Test endpoint argument and result serialization. #[multiversx_sc::module] @@ -23,6 +23,12 @@ pub trait EchoManagedTypes { ma } + /// This tests how is generated type name in proxy + #[endpoint] + fn echo_managed_option(&self, mo: ManagedOption) -> ManagedOption { + mo + } + /// This tests that nested serialization of big ints within unmanaged types works. #[endpoint] fn echo_big_int_managed_vec(&self, x: ManagedVec) -> ManagedVec { diff --git a/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs new file mode 100644 index 0000000000..38d5730c03 --- /dev/null +++ b/contracts/feature-tests/basic-features/tests/basic_features_managed_option_test.rs @@ -0,0 +1,41 @@ +use imports::{MxscPath, ReturnsResult, TestAddress, TestSCAddress}; +use multiversx_sc::types::{BigUint, ManagedOption}; +use multiversx_sc_scenario::{api::StaticApi, imports, ScenarioTxRun, ScenarioWorld}; + +const OWNER_ADDRESS: TestAddress = TestAddress::new("owner"); +const BASIC_FEATURES_ADDRESS: TestSCAddress = TestSCAddress::new("basic-features"); +const BASIC_FEATURES_PATH: MxscPath = MxscPath::new("output/basic-features.mxsc.json"); + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract(BASIC_FEATURES_PATH, basic_features::ContractBuilder); + + blockchain.account(OWNER_ADDRESS).nonce(1); + blockchain + .account(BASIC_FEATURES_ADDRESS) + .nonce(1) + .code(BASIC_FEATURES_PATH); + + blockchain +} + +#[test] +fn managed_option_test() { + let mut world = world(); + + let type_number: BigUint = BigUint::zero(); + let expected_type_managed_option: ManagedOption> = + ManagedOption::some(type_number); + + let output = world + .tx() + .from(OWNER_ADDRESS) + .to(BASIC_FEATURES_ADDRESS) + .typed(basic_features::basic_features_proxy::BasicFeaturesProxy) + .echo_managed_option(expected_type_managed_option.clone()) + .returns(ReturnsResult) + .run(); + + assert_eq!(output, expected_type_managed_option); +} diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 887b75bcd5..18cd29cd68 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 403 +// Endpoints: 404 // Async Callback: 1 -// Total number of exported functions: 405 +// Total number of exported functions: 406 #![no_std] @@ -169,6 +169,7 @@ multiversx_sc_wasm_adapter::endpoints! { echo_big_int => echo_big_int echo_managed_buffer => echo_managed_buffer echo_managed_address => echo_managed_address + echo_managed_option => echo_managed_option echo_big_int_managed_vec => echo_big_int_managed_vec echo_big_int_tuple => echo_big_int_tuple echo_big_int_option => echo_big_int_option diff --git a/tools/plotter/start-server.sh b/tools/plotter/start-server.sh index 09641b1a03..3a5698f05e 100755 --- a/tools/plotter/start-server.sh +++ b/tools/plotter/start-server.sh @@ -1,8 +1,6 @@ #!/bin/bash set -e -mkdir -p www/pkg - ./build-wasm.sh cd www diff --git a/tools/plotter/www/bootstrap.js b/tools/plotter/www/bootstrap.js index bea8b6b67a..2520df8952 100644 --- a/tools/plotter/www/bootstrap.js +++ b/tools/plotter/www/bootstrap.js @@ -4,14 +4,14 @@ async function init() { if (typeof process == "object") { // We run in the npm/webpack environment. const [{Chart}, {main, setup}] = await Promise.all([ - import("wasm-demo"), + import("sc-plotter-wasm"), import("./index.js"), ]); setup(Chart); main(); } else { const [{Chart, default: init}, {main, setup}] = await Promise.all([ - import("../pkg/wasm_demo.js"), + import("../pkg/sc_plotter_wasm.js"), import("./index.js"), ]); await init(); diff --git a/tools/plotter/www/package.json b/tools/plotter/www/package.json index 32a99f8aff..87f6fd3412 100644 --- a/tools/plotter/www/package.json +++ b/tools/plotter/www/package.json @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/38/plotters", "dependencies": { - "wasm-demo": "file:../pkg" + "sc-plotter-wasm": "file:../pkg" }, "devDependencies": { "webpack": "^4.43.0",