canvas-ui icon indicating copy to clipboard operation
canvas-ui copied to clipboard

ink_prelude::string::String problem

Open xhuanlee opened this issue 4 years ago • 4 comments

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"));
        }
    }
}

xhuanlee avatar Feb 20 '21 06:02 xhuanlee

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

atenjin avatar Feb 20 '21 08:02 atenjin

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~

xhuanlee avatar Feb 20 '21 08:02 xhuanlee

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.

cmichi avatar Apr 15 '21 18:04 cmichi

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.

atenjin avatar Apr 16 '21 02:04 atenjin