paritytech / canvas-ui

Basic Polkadot/Substrate UI for interacting with a node. This is the main user-facing application, allowing access to all features available on Substrate chains.
https://dotapps.io
Apache License 2.0
31 stars 15 forks source link

ink_prelude::string::String problem #96

Open xhuanlee opened 3 years ago

xhuanlee commented 3 years ago

a2c8860eb830fae5b8a8609f62a9439

set value to hello, it returns u0014hello;

b3c0885fb73e8857682e6644d74b4d9

set value to hello, world!, it returns 4hello, world!

contract source

// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]

use ink_lang as ink;

#[ink::contract]
pub mod flipper {

    use ink_prelude::string::String;

    #[ink(storage)]
    pub struct Flipper {
        value: String,
    }

    impl Flipper {
        /// Creates a new flipper smart contract initialized with the given value.
        #[ink(constructor)]
        pub fn new(init_value: String) -> Self {
            Self { value: init_value }
        }

        /// Creates a new flipper smart contract initialized to `false`.
        #[ink(constructor)]
        pub fn default() -> Self {
            Self::new(String::from("hello, world!"))
        }

        /// Flips the current value of the Flipper's bool.
        #[ink(message)]
        pub fn set(&mut self, v:String) {
            self.value = v;
        }

        /// Returns the current value of the Flipper's bool.
        #[ink(message)]
        pub fn get(&self) -> String {
            self.value.clone()
        }
    }

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn default_works() {
            let flipper = Flipper::default();
            assert_eq!(flipper.get(), String::from("hello, world!"));
        }

        #[test]
        fn it_works() {
            let mut flipper = Flipper::new(String::from("Good day"));
            assert_eq!(flipper.get(), String::from("Good day"));
            flipper.set(String::from("Good morning"));
            assert_eq!(flipper.get(), String::from("Good morning"));
        }
    }
}
atenjin commented 3 years ago

I have submmit this issue in https://github.com/polkadot-js/apps, I think this is a bug in apps. more detils refer to this issue https://github.com/polkadot-js/apps/issues/4621

xhuanlee commented 3 years ago

I have submmit this issue in https://github.com/polkadot-js/apps, I think this is a bug in apps. more detils refer to this issue polkadot-js/apps#4621

I'll take a look at it, Thank you~

cmichi commented 3 years ago

The issue can be reproduced with the Canvas UI. This is how it looks:

screenshot-paritytech github io-2021 04 15-20_13_47

huhu
lala

I've uploaded the .contract file for the contract posted by @xhuanlee here: flipper.contract.zip.

atenjin commented 3 years ago

obviously this is a bug in apps, I have proved this by using europa, and I already summited the issue in apps https://github.com/polkadot-js/apps/issues/4621, waiting for jacob to fix it for a long time.